Retrofit repo to use template-python packaging standards#22
Retrofit repo to use template-python packaging standards#22jordanpadams wants to merge 6 commits into
Conversation
- Add pds.en_ops_utils Python package under src/ layout - Move pds-sync-api logic into src/pds/en_ops_utils/portal/pds_sync_api.py - Reduce scripts/portal/pds-sync-api.py to a thin backward-compat wrapper - Add setup.cfg, pyproject.toml, tox.ini, setup.py, MANIFEST.in - Add .pre-commit-config.yaml (trailing-whitespace, mypy, flake8, detect-secrets) - Add tests/pds/en_ops_utils/portal/ with 8 unit tests - Update README and CLAUDE.md with correct scripts/ paths and new setup instructions - Add coverage.xml to .gitignore Closes #7 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Update test/context/ sys.path inserts from bin/context to scripts/context - Add .secrets.baseline for detect-secrets pre-commit hook Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Remove docs env from tox (internal tools repo, READMEs are sufficient) - Add flake8 and detect-secrets to lint env deps for language:system hooks - chmod -x scripts/sitemap/sitemap-partial.xml (no shebang) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add dependabot.yml (pip + github-actions, weekly) - Add issue-project-automation.yml (project board + label automation) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Picked a few nits here and there! See the comments below.
Also, while pytest worked as described, tox was not as happy:
============================== 8 passed in 1.59s ===============================
.pkg: _exit> python /Users/kelly/Documents/Clients/JPL/PDS/Development/en-ops-utils/.venv/lib/python3.13/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg-cpython312: _exit> python /Users/kelly/Documents/Clients/JPL/PDS/Development/en-ops-utils/.venv/lib/python3.13/site-packages/pyproject_api/_backend.py True setuptools.build_meta
py313: OK ✔ in 2.35 seconds
lint: commands[0]> python -m pre_commit run --color=always --all
Trim Trailing Whitespace.................................................Failed
- hook id: trailing-whitespace
- exit code: 1
- files were modified by this hook
Fixing scripts/ldds/prep_for_ldd_release.sh
Fixing scripts/ldds/ldd-corral.py
Fixing scripts/repos/repo-corral.py
Fixing LICENSE.md
Fixing scripts/ldds/update_ldds_with_template.sh
Fixing scripts/ldds/update-ldd-actions.py
Fix End of Files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook
Fixing scripts/repos/update_action.sh
Fixing scripts/repos/update_templates.sh
Fixing LICENSE.md
Fixing scripts/ldds/update_ldds_with_template.sh
Fixing scripts/solr/deprecated_solr_registry_pds3_export.py
Check that executables have shebangs.....................................Passed
Check for merge conflicts................................................Passed
Debug Statements (Python)................................................Passed
Check Yaml...............................................................Passed
Reorder python imports...................................................Failed
- hook id: reorder-python-imports
- exit code: 1
- files were modified by this hook
Reordering imports in tests/pds/en_ops_utils/portal/test_pds_sync_api.py
Reordering imports in src/pds/en_ops_utils/portal/pds_sync_api.py
flake8...................................................................Passed
detect-secrets...........................................................Failed
- hook id: detect-secrets
- exit code: 1
Executable `/Users/kelly/Documents/Clients/JPL/PDS/Development/en-ops-utils/scripts/detect_secrets_baseline.sh` not found
lint: exit 1 (1.00 seconds) /Users/kelly/Documents/Clients/JPL/PDS/Development/en-ops-utils> python -m pre_commit run --color=always --all pid=49059
py312: OK (2.37=setup[0.49]+cmd[1.88] seconds)
py313: OK (2.35=setup[0.51]+cmd[1.84] seconds)
lint: FAIL code 1 (1.01=setup[0.00]+cmd[1.00] seconds)
evaluation failed :( (5.80 seconds)
| pip3 install --requirement requirements.txt | ||
| python3 -m venv .venv | ||
| source .venv/bin/activate | ||
| pip install -e ".[dev]" # packaged scripts (pds-sync-api, etc.) |
There was a problem hiding this comment.
I like --long options in documentation since they're "self-documenting":
pip install --editable ".[dev]"
pip install --requirement requirements.txt # legacy scripts not yet packaged
But that's just me! Feel free to ignore this
| # Run tests | ||
| pytest test/ -v | ||
| # Run all tests | ||
| pytest tests/ test/ -v |
There was a problem hiding this comment.
I'd like to see
pytest --verbose tests/ test/
However, more important: it looks like tox.ini is running just one of those, i.e., not both tests/ an test/, sort of silenlty dropping the legacy test suite from Roundup or any other CI.
| deps = setuptools<81 | ||
| extras = dev | ||
| usedevelop = true | ||
| commands = pytest --cov=src --cov-report=xml {posargs} |
There was a problem hiding this comment.
This should probably be --cov=pds to harmonize with setup.cfg.
| hooks: | ||
| - id: flake8 | ||
| name: flake8 | ||
| entry: flake8 src |
There was a problem hiding this comment.
Should we add tests, test, and scripts to this?
| hooks: | ||
| - id: detect-secrets | ||
| name: detect-secrets | ||
| entry: scripts/detect_secrets_baseline.sh |
There was a problem hiding this comment.
I think detect_secrets_baseline.sh might be missing from the PR 🤔
| @@ -1,8 +1,10 @@ | |||
| # Legacy requirements for un-ported scripts in bin/. | |||
There was a problem hiding this comment.
Probably should be scripts/ instead of bin/
| pytest>=7.0.0 | ||
| lxml~=6.0.2 | ||
| pytest>=7.0.0 | ||
| lxml>=6.0.2 |
There was a problem hiding this comment.
Sure about this? Using ~=6.0.2 avoids a supply-chain vulnerability. Is there an upper limit of lxml we can state?
| while True: | ||
| _logger.debug("Making request to %s with params %r", url, params) | ||
| r = requests.get(url, params=params) | ||
| matches = r.json()["data"] |
There was a problem hiding this comment.
Might want to add r.raise_for_status() right after the requests.get before attempting to use the payload on the next line.
| params["search-after"] = matches[-1]["properties"][_search_key] | ||
|
|
||
|
|
||
| def _write_harvest_config(node_name: str, download_path: str, config: str) -> None: |
There was a problem hiding this comment.
It looks like node_name isn't used anymore. Can we remove it from the parameter list? If not, we could add a note to the docstring.
| @@ -0,0 +1,2 @@ | |||
| # -*- coding: utf-8 -*- | |||
| # Namespace package | |||
There was a problem hiding this comment.
I think you can remove this entire __init__.py file since namespace packages are implicit with newer Pythons.
- Add branch-cicd, stable-cicd, unstable-cicd, sonarcloud, secrets-detection workflows - Add scripts/detect_secrets_baseline.sh for pre-commit detect-secrets hook - Fix trailing whitespace in scripts/ (pre-commit hook cleanup) - Update .gitignore and LICENSE.md to template standards - Minor linter fixes in setup.cfg, pds_sync_api.py, test_pds_sync_api.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
🗒️ Summary
Begins retrofitting the repo to the template-python packaging standards, scoped to the
pds-sync-apiscript as the first migration. Remaining scripts can be moved one-by-one as they are tested.Changes:
src/pds/en_ops_utils/package layout (setup.cfg,pyproject.toml,tox.ini,setup.py,MANIFEST.in)pds-sync-apilogic intosrc/pds/en_ops_utils/portal/pds_sync_api.py; reducescripts/portal/pds-sync-api.pyto a thin backward-compatible wrapper.pre-commit-config.yaml(trailing-whitespace, reorder-imports, mypy, flake8, detect-secrets)tests/pds/en_ops_utils/portal/with 8 unit tests for_get_lidvid,_already_downloaded,_write_harvest_configREADME.mdandCLAUDE.md: correct allbin/→scripts/paths, document new setup/dev workflow, describe dual legacy/packaged architecturecoverage.xmlto.gitignoreInstall after merge:
⚙️ Test Data and/or Report
♻️ Related Issues
Closes #7
🤓 Reviewer Checklist