Skip to content

feat(foundry): add python_version_minor computed field#56

Merged
olivermeyer merged 2 commits intomainfrom
feat/add-python-version-minor
Apr 27, 2026
Merged

feat(foundry): add python_version_minor computed field#56
olivermeyer merged 2 commits intomainfrom
feat/add-python-version-minor

Conversation

@olivermeyer
Copy link
Copy Markdown
Collaborator

Why?
Callers that need only the major.minor portion of the Python runtime version (e.g. "3.11") currently have to repeat the same .split(".")[:2] derivation themselves. A dedicated field on FoundryContext makes this consistently available without boilerplate.

How?
Added python_version_minor as a Pydantic v2 @computed_field property on FoundryContext, derived from the existing python_version field at access time. Returns "" when python_version is unset. Also added python_version as an explicit parameter to make_context() so tests can exercise the new field without reaching for from_package().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@olivermeyer olivermeyer requested a review from a team as a code owner April 27, 2026 13:00
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Files with missing lines Coverage Δ
src/aignostics_foundry_core/foundry.py 97.54% <100.00%> (+0.11%) ⬆️

Comment thread src/aignostics_foundry_core/foundry.py Outdated
Comment on lines +142 to +144
parts = self.python_version.split(".")
major_minor_part_count = 2
return ".".join(parts[:major_minor_part_count]) if len(parts) >= major_minor_part_count else self.python_version
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Am I missing something or would the following one-liner have the same behavior?
`

Suggested change
parts = self.python_version.split(".")
major_minor_part_count = 2
return ".".join(parts[:major_minor_part_count]) if len(parts) >= major_minor_part_count else self.python_version
return ".".join(self.python_version.split(".")[:2])

Copy link
Copy Markdown
Collaborator Author

@olivermeyer olivermeyer Apr 27, 2026

Choose a reason for hiding this comment

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

I had this initially and ruff raised PLR2004 on the number comparison:

parts = self.python_version.split(".")
return ".".join(parts[:2]) if len(parts) >= 2 else self.python_version

But good point that the if len(parts) ... is a bit convoluted. I'll do this as a middle ground:

major_minor_part_count = 2
return ".".join(self.python_version.split(".")[:major_minor_part_count])

Copy link
Copy Markdown

@neelay-aign neelay-aign Apr 27, 2026

Choose a reason for hiding this comment

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

Could be an appropriate place to use a # noqa IMO, especially to save tokens 😉. But also happy with this. Approved.

@olivermeyer olivermeyer force-pushed the feat/add-python-version-minor branch from 1256df2 to 461b8d6 Compare April 27, 2026 13:18
@olivermeyer olivermeyer requested a review from neelay-aign April 27, 2026 13:18
@sonarqubecloud
Copy link
Copy Markdown

@olivermeyer olivermeyer merged commit 8532af8 into main Apr 27, 2026
12 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.

2 participants