Skip to content

chore: use uv and ruff for analytics reporting (#4934) - #4936

Merged
NoopDog merged 16 commits into
mainfrom
hunter/4934-modernize-analytics-package
Aug 22, 2026
Merged

chore: use uv and ruff for analytics reporting (#4934)#4936
NoopDog merged 16 commits into
mainfrom
hunter/4934-modernize-analytics-package

Conversation

@hunterckx

Copy link
Copy Markdown
Contributor

Closes#4934

  • Switched to uv for package/dependency management
  • Added pyproject.toml files for the package and for the broader analytics folder
  • Added Ruff formatting/linting with npm scripts for running it
    • Most of the changes in this PR are from formatting being applied
  • Added Python checks to run-checks workflow (Ruff, lockfile consistency, importing the package entry point)

@hunterckx
hunterckxforce-pushed the hunter/4934-modernize-analytics-package branch from 4e966c9 to 84d3588CompareAugust 20, 2026 04:28
lambda m: f"{m[:4]}-{m[4:]}" if len(m) == 6 and "-" not in m else m
)
counts_by_month = dict(zip(grouped[month_col], grouped[count_col].astype(int)))
counts_by_month = grouped.set_index(month_col)[count_col].astype(int).to_dict()

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

One change here that's not just reformatting: there was a linting issue with the zip so this is changed to keep the two columns together in Pandas and then convert to a dict

return dict(
zip([dimension["id"] for dimension in dimensions], [dimension["alias"] for dimension in dimensions])
)
return {field["id"]: field["alias"] for field in fields}

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Another zip issue -- here converted to a notably simpler dict comprehension

CopilotAI left a comment

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.

Pull request overview

This PR modernizes the analytics/** Python tooling by migrating dependency management to uv, consolidating packaging metadata into pyproject.toml, introducing Ruff linting/formatting, and wiring Python checks into CI to prevent regressions like the prior star-import leak.

Changes:

  • Replace venv + requirements.txt workflow with uv (uv.lock, .python-version) and update setup docs.
  • Add Ruff lint/format configuration and new npm scripts for running Python lint/format.
  • Add a new analytics job to run-checks.yml to run Ruff and validate imports under a locked environment.

Reviewed changes

Copilot reviewed 24 out of 26 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
package.jsonAdds npm scripts to run Ruff via uv from the repo root.
analytics/requirements.txtRemoves legacy pip requirements file in favor of uv.lock.
analytics/readme.mdUpdates local setup + lint/format instructions for uv + Ruff.
analytics/pyproject.tomlDefines uv workspace, dependency groups (incl. Ruff), and Ruff lint selection.
analytics/uv.lockAdds the locked dependency resolution for the analytics workspace.
analytics/.python-versionPins Python version used by uv.
analytics/lungmap/generate_static_site.pyRuff-driven import and formatting updates.
analytics/lungmap/constants.pyNormalizes string quoting/formatting.
analytics/hca-explorer/generate_static_site.pyRuff-driven import and formatting updates.
analytics/hca-explorer/constants.pyReformats nested dict constant for readability.
analytics/anvil-explorer/generate_static_site.pyRuff-driven import and formatting updates.
analytics/anvil-explorer/constants.pyNormalizes string quoting/formatting.
analytics/anvil-catalog/generate_static_site.pyRuff-driven import formatting updates.
analytics/analytics_package/setup.pyRemoves legacy setup.py packaging entrypoint.
analytics/analytics_package/pyproject.tomlIntroduces setuptools-based packaging metadata via pyproject.toml.
analytics/analytics_package/analytics/static_site/generator.pyImport ordering/formatting changes.
analytics/analytics_package/analytics/static_site/fetch.pyFormatting plus a small dict construction change for monthly counts.
analytics/analytics_package/analytics/static_site/export.pyFormatting changes and minor readability improvements.
analytics/analytics_package/analytics/static_site/charts.pyFormats nested chart config structures for readability.
analytics/analytics_package/analytics/static_site/init.pyReorders exports and formats __all__.
analytics/analytics_package/analytics/report_elements.pyImport ordering/formatting and readability refactors for chained operations.
analytics/analytics_package/analytics/entities.pyMinor formatting normalization for constants/enums.
analytics/analytics_package/analytics/api.pyLarge formatting/indentation normalization; preserves existing behaviors.
analytics/analytics_package/analytics/_report_utils.pyFormatting + small refactor to renaming helper and readability improvements.
.gitignoreSwitches ignored venv dir to analytics/.venv and ignores Ruff cache.
.github/workflows/run-checks.ymlAdds analytics CI job running Ruff and a minimal import check under uv.
Suppressed comments (2)

analytics/analytics_package/analytics/api.py:404

  • Spelling in comments: "nmes" → "names" and "Crete" → "Create".
 # Collect column nmes

analytics/analytics_package/analytics/api.py:287

  • Spelling in comment: "Crete" → "Create".
 # Crete the dataframe

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment threadpackage.json Outdated
Comment threadanalytics/readme.md Outdated
Comment threadanalytics/analytics_package/analytics/api.py

@NoopDogNoopDog left a comment

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.

Reviewed with Claude Code — the Python reformatting itself verified clean (AST-equivalent across all 16 changed files, pins preserved). A handful of tooling-hygiene suggestions, most inline below, plus one that doesn't anchor to the diff:

Pre-commit hook doesn't run the new Python checks.husky/pre-commit gates prettier/eslint/tsc but not lint:python / check-format:python, so an analytics/*.py edit passes the hook and then fails in CI on ruff format --check. Unconditional wiring would break commits for developers without uv, but a guarded invocation (only when uv exists and analytics files are staged) would match how the other checks are integrated.

Comment thread.gitignore
Comment threadpackage.json Outdated
Comment thread.github/workflows/run-checks.yml
Comment thread.github/workflows/run-checks.yml
dev = ["ruff==0.16.3"]

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "I", "W", "B"]

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.

This select re-spells ruff's default set (E4, E7, E9, F) before appending the real policy; extend-select = ["I", "W", "B"] expresses the same intent in one self-documenting line and tracks default-set updates when the pinned ruff is bumped. Explicit pinning is defensible too — nitpick either way.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Ruff's default rules actually include an assortment of rules not included here, and do not include E4 or all of E7 and F. I don't really have a reason to prefer one choice or the other (or the combination), but a couple things to consider are that Ruff recommends an explicit select, and enabling all of the default rules would require a few more code changes. (On the other hand, using the default rules would be consistent with how we handle TypeScript linting)

Replace the bare setuptools setup.py with a pyproject.toml (setuptools
backend, so the downstream git+#subdirectory install path is unchanged),
and replace the hand-pinned requirements.txt with a uv workspace and
uv.lock. Adds ruff config and a .python-version.
Auto-fixes for E714 (not-is-test), I001 (import sorting) and trailing
whitespace, plus explicit strict=True on the two zip() calls flagged by
B905 -- both zip sequences that are equal-length by construction.
Whitespace and wrapping only. Notably converts api.py from tab to space
indentation -- it was the only tab-indented file in the tree.
Adds an analytics job to run-checks.yml that syncs the uv environment
against the lockfile, runs ruff check and ruff format --check, and
smoke-imports the package to prove the pyproject packaging installs.
Replaces the venv + pip + requirements.txt instructions with uv sync,
and documents the ruff commands.
@hunterckx
hunterckxforce-pushed the hunter/4934-modernize-analytics-package branch from 94bd546 to 0efac16CompareAugust 21, 2026 21:23
@NoopDog
NoopDog merged commit e738381 into mainAug 22, 2026
4 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: modernize analytics package tooling (uv, ruff, pyproject)

3 participants

@hunterckx@NoopDog