Skip to content

Adding CI for PR's -- uv lockfile verification, ruff lint, unit test suite#35

Merged
phuo-nv merged 24 commits into
NVIDIA-AI-Blueprints:mainfrom
jgoldberg-nvidia:main
Apr 22, 2026
Merged

Adding CI for PR's -- uv lockfile verification, ruff lint, unit test suite#35
phuo-nv merged 24 commits into
NVIDIA-AI-Blueprints:mainfrom
jgoldberg-nvidia:main

Conversation

@jgoldberg-nvidia

@jgoldberg-nvidia jgoldberg-nvidia commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a PR-level CI workflow (.github/workflows/pr.yaml) that runs on every pull request against main, motivated by the recent uv sync --extra cuda13 break in e65a857 that only surfaced after merge.

  • lockfile-check job runs uv lock --locked, which re-resolves the full manifest across every Python version in requires-python and
    every extra (dev, cuda12, cuda13). Catches dependency-resolution regressions (e.g., pinning cuml-cu13==26.4.* while requires-python
    still permits Python 3.10) before merge, instead of waiting for the post-merge GPU job.
  • install-and-test matrix runs unit tests on Python 3.11 and 3.12, catching code that works on the current dev target but regresses on the
    declared floor.
  • lint job runs ruff format --check and ruff check on src/.
  • pr-builder gate marks the PR as failing if any of the above fail.

Also switches dev tooling from black/isort/flake8 to ruff (single tool, faster) and applies ruff format to src/. Adds a
tests/test_core.py suite (38 tests) covering returns, CVaR data + parameters, portfolio math, efficient frontier, and the backtester, using the
pydantic ReturnsComputeSettings / ScenarioGenerationSettings models.

One test (test_no_fit) is skipped pending a fix to generate_cvar_data — the no_fit path passes a DataFrame to CvarData.R, which
pydantic validates as ndarray. Latent bug in main; skip preserves the test for when it's fixed.

Test plan

  • lockfile-check passes on this PR (proves uv lock --locked resolves cleanly for all extras and Python versions)
  • install-and-test passes on Python 3.11 and 3.12 matrix legs
  • lint passes (ruff format --check src/ and ruff check src/ both clean)
  • main.yml post-merge notebook run still succeeds against the merged code
  • Verify locally: introduce a bad pin (e.g., cuml-cu13==99.0.*) in a throwaway commit and confirm lockfile-check fails

Introduce a pr.yaml workflow that runs black, isort, and flake8 on
every pull request to main, plus a package install verification step.
Add lint as a prerequisite to the existing main.yml notebook runner.
Wire up .pre-commit-config.yaml for local developer feedback.

Made-with: Cursor
Run black and isort across src/ and notebooks/ to bring existing code
into compliance with the new CI lint checks. Switch to black[jupyter]
so .ipynb files are covered.

Made-with: Cursor
- Takes main's updated src/, notebooks, pyproject.toml deps and cuml/cuopt 26.4 pins
- Takes Python 3.11 minimum from the fix branch
- Preserves ruff dev tooling and ruff config (required by pr.yaml lint steps)
- Updates test_core.py import: compute_abs_returns -> compute_linear_returns
- Regenerates uv.lock against merged pyproject.toml
- pyproject.toml: fix ruff target-version (string, not list) and per-file-ignores glob (**/__init__.py)
- ruff format + --fix applied to 6 src/ files (whitespace, trailing newlines, f-strings)
- tests: compute_abs_returns -> compute_absolute_returns (correct rename; linear != absolute)
- tests: use ReturnsComputeSettings / ScenarioGenerationSettings pydantic models instead of dicts
- tests: invalid fit_type now raises pydantic ValidationError at model construction
- tests: skip test_no_fit due to pre-existing DataFrame-vs-ndarray bug in no_fit path
- uv.lock regenerated
Adding CI/CD pipeline for PRs, Ruff linting, and Unit tests
@phuo-nv

phuo-nv commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

@jgoldberg-nvidia we need to resolve the uv.lock conflict here. Can simply update this one. Thanks!

@jgoldberg-nvidia jgoldberg-nvidia changed the title Draft: CI support Adding CI for PR's -- uv lockfile verification, ruff lint, unit test suite Apr 21, 2026
@jgoldberg-nvidia jgoldberg-nvidia requested review from Copilot, phuo-nv and ryanzhang1230 and removed request for Copilot, phuo-nv and ryanzhang1230 April 21, 2026 16:48

Copilot AI 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

Adds PR-level CI checks to catch lockfile, linting/formatting, and unit-test regressions before merge, and migrates dev tooling to Ruff with an initial unit test suite.

Changes:

  • Introduces a new PR CI workflow to verify uv.lock, run Ruff format/lint, and execute pytest across a Python version matrix.
  • Switches dev tooling from black/isort/flake8 to Ruff and updates code formatting accordingly.
  • Adds a broad unit test suite for core returns/CVaR/portfolio/backtest functionality.

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
.github/workflows/pr.yaml New PR workflow for lockfile verification, linting/formatting, and tests.
.github/workflows/main.yml Adds a lint+tests gate before running notebooks post-merge.
pyproject.toml Replaces black/isort/flake8 with ruff + pytest in dev extra; adds Ruff config.
.pre-commit-config.yaml Adds pre-commit hooks for Ruff lint/format plus whitespace fixers.
uv.lock Updates lock to reflect new dev tooling (ruff/pytest) and removed black/isort/flake8.
tests/test_core.py New unit test module covering returns, CVaR data/params, optimization, frontier, backtesting.
src/utils.py Reformats code (notably long constants/printing and a few wrapped expressions) for Ruff.
src/backtest.py Minor docstring edit (introduces a punctuation typo).
src/base_optimizer.py Minor formatting change.
src/cvar_optimizer.py Minor formatting/import consolidation.
src/cvar_utils.py Minor formatting fixes.
src/mean_variance_optimizer.py Minor formatting fixes.
src/rebalance.py Minor formatting fixes (including assertions).
src/portfolio.py Minor formatting fixes (including an assertion).
src/settings.py Removes trailing whitespace.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/backtest.py Outdated
Comment thread tests/test_core.py
Comment thread src/rebalance.py
Comment thread src/portfolio.py
Comment thread .github/workflows/pr.yaml
@phuo-nv phuo-nv merged commit 7d33745 into NVIDIA-AI-Blueprints:main Apr 22, 2026
5 checks passed
Sign up for free to 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.

3 participants