Skip to content

DEVOPS-1371: Add reusable Pixi validation hooks - #26

Merged
sebhmg merged 20 commits into
mainfrom
GA-9681-unify-pixi-hooks
Dec 2, 2026
Merged

sebhmg merged 20 commits into
mainfrom
GA-9681-unify-pixi-hooks

Conversation

@sebhmg

@sebhmg sebhmg commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

DEVOPS-1371 - pre-commit hook to validate pixi lock and conda recipe
part of GA-9681 - update Python distribution for 4.9 beta

Summary

  • Add reusable Pixi lock and recipe validation hooks for package repositories.
  • Infer recipe constraints and feature dependencies from workspace files.
  • Default MiraGeoscience Git source URLs and relevant Pixi file filters, reducing consumer configuration.

Related to GA-9681.

sebhmg and others added 3 commits November 24, 2026 01:19
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI adaptive review requested due to automatic review settings November 24, 2026 12:11
@github-actions github-actions Bot changed the title [GA-9681] Add reusable Pixi validation hooks GA-9681: Add reusable Pixi validation hooks Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.71024% with 61 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.54%. Comparing base (3d0dd36) to head (3df0e5e).
⚠️ Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
mirageoscience/hooks/check_pixi_lock.py 88.21% 16 Missing and 13 partials ⚠️
mirageoscience/hooks/check_recipe.py 84.65% 15 Missing and 14 partials ⚠️
mirageoscience/hooks/_cli_utils.py 87.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #26       +/-   ##
===========================================
+ Coverage   63.19%   80.54%   +17.35%     
===========================================
  Files           3        6        +3     
  Lines         163      622      +459     
  Branches       32      133      +101     
===========================================
+ Hits          103      501      +398     
- Misses         54       87       +33     
- Partials        6       34       +28     
Files with missing lines Coverage Δ
mirageoscience/hooks/_cli_utils.py 87.50% <87.50%> (ø)
mirageoscience/hooks/check_pixi_lock.py 88.21% <88.21%> (ø)
mirageoscience/hooks/check_recipe.py 84.65% <84.65%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new commands fail on clean installations due to missing runtime dependencies, while the validators reject valid Pixi configurations and miss some security-policy violations.

7 open issues
What changed in this PR

Adds reusable Pixi validation hooks to the pre-commit hook package, supporting package repositories as part of the GA-9681 Python distribution update.

Changes:

  • Adds lock validation for feature dependencies and package sources, with optional strict PyPI checks.
  • Adds recipe constraint and transitivity validation, plus an optional PyTorch backend check.
  • Registers both hooks with default file filters and MiraGeoscience Git source prefixes, and adds documentation and tests.
File Description
tests/​pixi_hooks_test.py Adds tests for lock policies and recipe constraint inference.
README.rst Documents the hooks, options, defaults, and configuration examples.
pyproject.toml Registers console commands and adds development dependencies.
poetry.lock Locks PyYAML and refreshes dependency metadata.
mirageoscience/​hooks/​check_recipe.py Implements recipe constraint, transitivity, and optional PyTorch checks.
mirageoscience/​hooks/​check_pixi_lock.py Implements feature-based lock and package-source validation.
.pre-commit-hooks.yaml Registers hooks with dependencies and default file filters.

Review effort: Balanced (adaptive)

Comment thread pyproject.toml Resolved
Comment thread mirageoscience/hooks/check_pixi_lock.py Resolved
Comment thread mirageoscience/hooks/check_pixi_lock.py Resolved
Comment thread mirageoscience/hooks/check_pixi_lock.py Resolved
Comment thread mirageoscience/hooks/check_recipe.py Resolved
Comment thread mirageoscience/hooks/check_recipe.py Resolved
Comment thread mirageoscience/hooks/check_recipe.py Resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Recipe checks can crash on valid Conda constraints and conditional requirements or miss direct dependencies, while PyPI source validation mishandles URL normalization and inherited index settings.

1 open issue
5 previously missed issues

In code that hasn't changed since last review

Medium severity Normalize locked index URLs before comparison

mirageoscience/​hooks/​check_pixi_lock.py:173

With --validate-pypi-sources, an index configured and locked as https://pypi.org/simple/ is reported as missing even though both files contain the same URL. _index_urls() strips trailing slashes, but this comparison leaves the locked URLs unchanged. Normalize the locked URLs in the same way before comparing them.

Medium severity Translate valid Conda version expressions before validation

mirageoscience/​hooks/​check_recipe.py:47

Valid Conda version expressions such as pillow = "=13" or alternatives separated by | reach SpecifierSet without translation and raise InvalidSpecifier. The hook therefore aborts on valid workspace constraints rather than validating their floors. Parse Conda version semantics, or explicitly translate supported forms before passing them to packaging.

Medium severity Include target-specific feature tables in constraint inference

mirageoscience/​hooks/​check_recipe.py:80

Recipe constraint inference ignores feature target tables. For example, declaring pillow = "13.*" only under [feature.conda-rt.target.win-64.dependencies] with pillow >=13.0.0 in recipe run_constraints produces a constraint-name mismatch because no Pixi source is collected. Include applicable target-specific dependency and constraint tables when deriving sources, respecting their overrides of feature-wide entries.

Medium severity Parse compact Conda MatchSpecs to detect direct dependencies

mirageoscience/​hooks/​check_recipe.py:177

Splitting on whitespace misses compact Conda MatchSpecs: a direct runtime dependency of filelock>=4.2.1 is read as the entire string rather than filelock. With matching Pixi and recipe constraints for filelock >=4.2.1, this lets a direct dependency pass the transitivity check. Use a MatchSpec-aware package-name parser that handles version operators as well as channel and build qualifiers.

Medium severity Handle conditional recipe requirements when extracting package names

mirageoscience/​hooks/​check_recipe.py:178

Valid recipe.yaml requirements can contain conditional mappings, such as a run entry with if: win and then: pywin32. Since the CLI passes the raw yaml.safe_load result here, calling .split() on that entry raises AttributeError, even when the PyTorch check is disabled and no security package is involved. Traverse conditional requirement branches before extracting package names, and use that handling consistently in the constraint and PyTorch checks as well.

7 resolved since last review

Review effort: Balanced (adaptive)

Comment thread mirageoscience/hooks/check_pixi_lock.py Resolved
sebhmg and others added 2 commits November 24, 2026 08:36
Validate Git URL authorities and reject ambiguous paths to prevent allowlist bypass via traversal or host spoofing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Artifact-source validation permits path-traversal URLs outside configured roots, while recipe parsing and PyPI index inheritance mishandle valid configurations.

1 open issue
5 previously missed issues

In code that hasn't changed since last review

High severity Normalize artifact URLs before checking configured path roots

mirageoscience/​hooks/​check_pixi_lock.py:214

The raw prefix check lets artifact URLs escape a configured path root. With --artifact-source-root=https://artifacts.example/packages, https://artifacts.example/packages/../untrusted/mira.whl produces no source error, although URL path normalization resolves it outside /packages/. Apply the same dot-segment and encoded-path safeguards used for Git sources before accepting an artifact URL.

Medium severity Accept compact Conda version constraints

mirageoscience/​hooks/​check_recipe.py:36

Valid Conda constraints such as filelock>=4.2.1 do not require a space between the name and version specifier. This raises ValueError for that input before any validation occurs, even though it is equivalent to the accepted filelock >=4.2.1. Extract the package name independently of whitespace so valid compact constraints are accepted.

Medium severity Include feature target dependencies in constraint-source inference

mirageoscience/​hooks/​check_recipe.py:81

Constraint-source inference skips feature target tables. For example, declaring pillow = "13.*" only under [feature.conda-rt.target.win-64.dependencies] leaves pixi_sources empty, so a matching recipe constraint pillow >=13.0.0 is rejected. Include applicable feature target tables when collecting constraint sources, accounting for target overrides and differing platform floors.

Medium severity Parse compact MatchSpecs before checking transitivity

mirageoscience/​hooks/​check_recipe.py:179

Splitting only on whitespace misses valid compact MatchSpecs in requirements.run. With matching workspace/recipe constraints for filelock >=4.2.1, a direct run dependency filelock>=4.2.1 or conda-forge::filelock=4.2.1 is treated as a different package, allowing validation to pass despite violating the transitivity policy. Extract the MatchSpec's package name before applying aliases and checking the intersection.

Medium severity Traverse conditional requirements before parsing dependencies

mirageoscience/​hooks/​check_recipe.py:179

Valid recipe.yaml requirements can contain conditional mappings, for example run: [{if: win, then: pywin32}]. These entries reach .split() as dictionaries and crash check-recipe, even when there are no security-floor packages to check. Traverse conditional then/else requirements before parsing dependency strings, and use that traversal in constraint parsing and the optional PyTorch check too.

Review effort: Balanced (adaptive)

@sebhmg sebhmg changed the title GA-9681: Add reusable Pixi validation hooks GA-9681 / GA-9774: Add reusable Pixi validation hooks Nov 24, 2026
Comment thread mirageoscience/hooks/check_pixi_lock.py Resolved

@RomFloreani RomFloreani 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.

Good job! It's almost ready! A few edge cases and comments and observations. I askped Copilot Opus to run a few tests and reported some things.

Comment thread mirageoscience/hooks/check_pixi_lock.py Resolved
Comment thread mirageoscience/hooks/check_pixi_lock.py Resolved
Comment thread mirageoscience/hooks/check_recipe.py Resolved
Comment thread mirageoscience/hooks/check_recipe.py Resolved
Comment thread README.rst Resolved
Comment thread README.rst Resolved
Comment thread mirageoscience/hooks/check_recipe.py Resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sebhmg
sebhmg requested review from RomFloreani and an adaptive review from Copilot November 24, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Flattened constraints are converted to a dict that discards earlier entries for the same package, allowing a weaker platform-specific minimum version to escape validation.

1 open issue
1 resolved since last review

Review effort: Balanced (adaptive)

Comment thread mirageoscience/hooks/check_recipe.py Resolved
RomFloreani
RomFloreani previously approved these changes Nov 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because unconditional dependency traversal can reject valid recipes with conditional runtime dependencies, even when constraints are absent or explicitly ignored.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@sebhmg

sebhmg commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

🔵 Needs a closer look

Human assessment is needed because unconditional dependency traversal can reject valid recipes with conditional runtime dependencies, even when constraints are absent or explicitly ignored.

this is correct, but the check aims at covering simple cases. To be adjusted in the future if we need to cover conditional runtime dependencies better

@sebhmg sebhmg changed the title GA-9681 / GA-9774: Add reusable Pixi validation hooks DEVOPS-1371: Add reusable Pixi validation hooks Nov 26, 2026
@sebhmg

sebhmg commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because the change contains a critical constraint-inference gap that can let recipes pass despite stronger feature requirements, along with incomplete target-specific dependency handling and a documentation typo.

No open issues 🎉

Review effort: Lite

@sebhmg
sebhmg requested a review from RomFloreani November 30, 2026 21:52

@RomFloreani RomFloreani 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.

Looks good to me! A few nits left to check

Comment thread mirageoscience/hooks/check_recipe.py Resolved
Comment thread mirageoscience/hooks/check_recipe.py Resolved
Comment thread mirageoscience/hooks/check_recipe.py Resolved
Comment thread mirageoscience/hooks/check_recipe.py Resolved
Comment thread mirageoscience/hooks/check_recipe.py Resolved
@sebhmg

sebhmg commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot review open comments on this PR and apply relevant changes

@sebhmg

sebhmg commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot, review open comments by all contributors (not just yours) on this PR and apply relevant changes

Apply the PR review feedback for conditional recipe constraints, invalid-config handling, and regression coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

A moderate active issue remains because empty or scalar recipe.yaml content can trigger an uncaught AttributeError instead of the documented invalid-configuration error.

1 open issue

Review effort: Lite

Comment thread mirageoscience/hooks/check_recipe.py Resolved
@sebhmg
sebhmg requested a review from RomFloreani December 1, 2026 20:46
@sebhmg

sebhmg commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

latest revision of this PR changeset in place and passed here: https://github.com/MiraGeoscience/gempy-drivers/pull/164

@sebhmg
sebhmg merged commit dbf831d into main Dec 2, 2026
21 checks passed
@sebhmg
sebhmg deleted the GA-9681-unify-pixi-hooks branch December 2, 2026 04:07
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