Repository navigation
Add ruff and bandit Python checks to CI #320
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,3 +48,18 @@ The `.env` file and `config.*.json` files are ignored by git, | |
| as they likely contain credentials and should not be committed. | ||
|
|
||
| Finally, every option can be specified on the command line itself. | ||
|
|
||
| ## Standalone Python scripts | ||
|
|
||
| The Python scripts in `standalone/` carry no filename extension, so | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obviously, this documentation would change if we are able to make the change implicitly suggested by my earlier comment about identifying lintable files based on file contents rather than file name. |
||
| a directory scan would silently skip them. CI lints them with ruff | ||
| and bandit by shell-expanding the `standalone/pdc-*` glob, so for a | ||
| new script to be covered by lint, its name should start with `pdc-`. | ||
|
|
||
| To run the same checks locally: | ||
|
|
||
| ``` | ||
| ruff check standalone/pdc-* | ||
| ruff format --check standalone/pdc-* | ||
| bandit -q standalone/pdc-* | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,6 +138,7 @@ def retrieve_pdc_data(endpoint: str, *, params: dict[str, Any] | None = None): | |
| f"{DS_PDC_API_BASE_URL}{endpoint}", | ||
| headers={"Authorization": f"Bearer {access_token}"}, | ||
| params=params or {}, | ||
| timeout=60, | ||
|
bickelj marked this conversation as resolved.
Resolved
|
||
| ) | ||
|
|
||
| pdc_data_dict = pdc_data_response.json() | ||
|
|
@@ -231,7 +232,6 @@ class RAG(dspy.Module): | |
| ) | ||
|
|
||
|
|
||
|
|
||
| @app.command() | ||
| def retrieve_application_forms(): | ||
| retrieve_pdc_data( | ||
|
|
@@ -396,7 +396,7 @@ def optimize_rag(): | |
| num_threads=2, | ||
| track_stats=True, | ||
| use_merge=False, | ||
| reflection_lm=lm, # TODO: use a separate reflection LLM | ||
| reflection_lm=lm, # TODO: use a separate reflection LLM | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? Not a big deal, but why is this in the change?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly,
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, this commit includes the changes needed to pass CI, in other words, it is making those formatting changes that are needed to pass the |
||
| ) | ||
|
|
||
| rag = RAG() | ||
|
|
@@ -414,7 +414,7 @@ def optimize_rag(): | |
| optimized_rag = optimizer.compile( | ||
| rag, | ||
| trainset=trainset_examples, | ||
| valset=trainset_examples, # TODO: use a separate validation set | ||
| valset=trainset_examples, # TODO: use a separate validation set | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| ) | ||
|
|
||
| optimized_rag.save(base_path / "optimized_rag.json") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,8 +69,8 @@ those columns can simply do so. | |
| } | ||
| """ | ||
|
|
||
| import json | ||
| import argparse | ||
| import json | ||
| import sys | ||
|
|
||
| try: | ||
|
|
@@ -107,14 +107,18 @@ def main(): | |
| # here would be RawDescriptionHelpFormatter -- I don't usually | ||
| # use that because it can do some minor reformatting that I | ||
| # find aesthetically displeasing, but hey, YMMV. | ||
| formatter_class=argparse.RawTextHelpFormatter) | ||
| allowed_formats = ["csv",] # maybe also "markdown", "html", etc some day | ||
| formatter_class=argparse.RawTextHelpFormatter, | ||
| ) | ||
| allowed_formats = [ | ||
| "csv", | ||
| ] # maybe also "markdown", "html", etc some day | ||
| arg_parser.add_argument( | ||
| '--output-format', | ||
| "--output-format", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these quote-char changes part of adhering to a convention? I've no objection to them, but I wonder if they belong in the same commit (or even the same PR) together with substantive changes.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, yeah we should make these a separate commit prior to the CI change. That way every commit could/should pass CI if it were checked out.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And yes they are part of I am trying to avoid adding a bunch of exclusions to the rules especially since our files are mostly already following the conventions.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are now split into a separate commit on the same branch as part of this PR.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thank you! |
||
| choices=allowed_formats, | ||
| type=str.lower, | ||
| default="csv", | ||
| help="Output format to show base fields in. Default: 'csv'") | ||
| help="Output format to show base fields in. Default: 'csv'", | ||
| ) | ||
|
|
||
| # Parse command line. | ||
| args = arg_parser.parse_args() | ||
|
|
@@ -123,11 +127,12 @@ def main(): | |
| json_input = json.load(sys.stdin) | ||
| parsed_input = pandas.json_normalize(json_input) | ||
| # Switch to index=True to include a first column that shows DataFrame index | ||
| parsed_input.to_csv(sys.stdout, index=False, encoding='utf-8') | ||
| parsed_input.to_csv(sys.stdout, index=False, encoding="utf-8") | ||
| else: # can't happen | ||
| raise ValueError( | ||
| f"ERROR: Unknown output format 'f{args.output_format}' requested") | ||
| f"ERROR: Unknown output format 'f{args.output_format}' requested" | ||
|
bickelj marked this conversation as resolved.
Resolved
|
||
| ) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| if __name__ == "__main__": | ||
| main() | ||
Uh oh!
There was an error while loading. Please reload this page.