Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,31 @@ jobs:
- run: npm ci
- run: npm run lint:tsc

# The standalone scripts carry no .py extension on purpose, so a
# directory scan would silently skip them. The shell expands the
# pdc-* globs below instead, so new scripts following the repo's
# pdc- naming convention are picked up without touching this file.
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.13"
- run: pip install ruff==0.17.4
- run: ruff check standalone/pdc-*
Comment thread
bickelj-agent marked this conversation as resolved.
Resolved
- run: ruff format --check standalone/pdc-*

bandit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.13"
- run: pip install bandit==1.9.4
- run: bandit -q standalone/pdc-*

build:
runs-on: ubuntu-latest
steps:
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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-*
```
6 changes: 3 additions & 3 deletions standalone/pdc-optimize-field-matching
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Comment thread
bickelj marked this conversation as resolved.
Resolved
)

pdc_data_dict = pdc_data_response.json()
Expand Down Expand Up @@ -231,7 +232,6 @@ class RAG(dspy.Module):
)



@app.command()
def retrieve_application_forms():
retrieve_pdc_data(
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? Not a big deal, but why is this in the change?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, ruff format enforces this style, based on https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#comments

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 ruff and bandit rules. Very very few overall, it seems.

)

rag = RAG()
Expand All @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

)

optimized_rag.save(base_path / "optimized_rag.json")
Expand Down
21 changes: 13 additions & 8 deletions standalone/pdc-process-base-fields
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ those columns can simply do so.
}
"""

import json
import argparse
import json
import sys

try:
Expand Down Expand Up @@ -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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yes they are part of ruff's convention.

I am trying to avoid adding a bunch of exclusions to the rules especially since our files are mostly already following the conventions.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

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()
Expand All @@ -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"
Comment thread
bickelj marked this conversation as resolved.
Resolved
)


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading