-
Notifications
You must be signed in to change notification settings - Fork 70
Add export tasks #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add export tasks #158
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2df2992
Add export tasks script
xianbaoqian 34be345
Add a github action for testing
xianbaoqian 4c7783b
Address comments.
xianbaoqian 701a24a
fix wording
xianbaoqian 4298ff7
Update .github/workflows/python-api-export-tasks.yaml
xianbaoqian 86fc28c
Update scripts/export_tasks.py
xianbaoqian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| name: Export tasks | ||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "**" | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.8"] | ||
|
|
||
| steps: | ||
| - run: | | ||
| sudo apt-get update | ||
|
|
||
| - uses: actions/checkout@v2 | ||
|
|
||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v2 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - run: python scripts/export_tasks.py | ||
| env: # Or as an environment variable | ||
| API_TOKEN: ${{ secrets.USER_API_TOKEN }} | ||
|
xianbaoqian marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import ast | ||
|
xianbaoqian marked this conversation as resolved.
|
||
| import os | ||
| import pathlib | ||
| import json | ||
|
|
||
| lib_to_task_map = {} | ||
|
|
||
|
|
||
| def extract_tasks(library_name, variable_name, value): | ||
|
xianbaoqian marked this conversation as resolved.
Outdated
xianbaoqian marked this conversation as resolved.
Outdated
|
||
| if variable_name == "ALLOWED_TASKS": | ||
| if isinstance(value, ast.Dict): | ||
| for key in value.keys: | ||
| lib_to_task_map.setdefault(library_name, []).append(key.value) | ||
|
xianbaoqian marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def traverse_global_assignments(library_name, file_content, handler): | ||
|
xianbaoqian marked this conversation as resolved.
|
||
| for element in ast.parse(file_content).body: | ||
| # Typical case | ||
| if isinstance(element, ast.AnnAssign): | ||
| handler(library_name, element.target.id, element.value) | ||
|
xianbaoqian marked this conversation as resolved.
|
||
| # Just in case user omitted the type annotation | ||
| # Unpacking and multi-variable assignment is rare so not handled | ||
| elif isinstance(element, ast.Assign): | ||
| target = element.targets[0] | ||
| if isinstance(target, ast.Name): | ||
| handler(library_name, target.id, element.value) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| root = pathlib.Path(__file__).parent.parent.resolve() | ||
| libs = os.listdir(root / "docker_images") | ||
| libs.remove("common") | ||
|
|
||
| for lib in libs: | ||
| with open(root / "docker_images" / lib / "app/main.py") as f: | ||
| content = f.read() | ||
| traverse_global_assignments(lib, content, extract_tasks) | ||
|
|
||
| output = json.dumps(lib_to_task_map, sort_keys=True, indent=4) | ||
| print(output) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.