-
Notifications
You must be signed in to change notification settings - Fork 50
feat(project_override): add add_dynamic_field to project_override
#1105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
|
|
||
| from fromager import build_environment, context | ||
| from fromager.packagesettings import ( | ||
| PEP621_DYNAMIC_FIELDS, | ||
| Annotations, | ||
| BuildDirectory, | ||
| EnvVars, | ||
|
|
@@ -77,6 +78,7 @@ | |
| "remove_build_requires": ["cmake"], | ||
| "update_build_requires": ["setuptools>=68.0.0", "torch"], | ||
| "requires_external": ["openssl-libs"], | ||
| "add_dynamic_field": ["readme"], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think we have any existing asserts testing this. I will suggest something like this to suitable tests |
||
| }, | ||
| "resolver_dist": { | ||
| "include_sdists": True, | ||
|
|
@@ -139,6 +141,7 @@ | |
| "remove_build_requires": [], | ||
| "update_build_requires": [], | ||
| "requires_external": [], | ||
| "add_dynamic_field": [], | ||
| }, | ||
| "resolver_dist": { | ||
| "sdist_server_url": None, | ||
|
|
@@ -180,6 +183,7 @@ | |
| "remove_build_requires": [], | ||
| "update_build_requires": [], | ||
| "requires_external": [], | ||
| "add_dynamic_field": [], | ||
| }, | ||
| "resolver_dist": { | ||
| "sdist_server_url": None, | ||
|
|
@@ -902,3 +906,44 @@ def test_version_none_no_reference( | |
| result = pbi.get_extra_environ(template_env={}, version=None) | ||
| assert result["FOO"] == "bar" | ||
| assert "__version__" not in result | ||
|
|
||
|
|
||
| def test_add_dynamic_field_from_yaml() -> None: | ||
| ps = PackageSettings.from_string( | ||
| "test-pkg", | ||
| """ | ||
| project_override: | ||
| add_dynamic_field: | ||
| - readme | ||
| - version | ||
| """, | ||
| ) | ||
| assert ps.project_override.add_dynamic_field == ["readme", "version"] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("invalid_field", ["name", "typo", "Name"]) | ||
| def test_add_dynamic_field_rejects_invalid(invalid_field: str) -> None: | ||
| with pytest.raises(RuntimeError, match="Allowed values per PEP 621"): | ||
| PackageSettings.from_string( | ||
| "test-pkg", | ||
| f""" | ||
| project_override: | ||
| add_dynamic_field: | ||
| - {invalid_field} | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def test_add_dynamic_field_accepts_all_pep621_fields() -> None: | ||
| fields_yaml = "\n".join(f" - {f}" for f in sorted(PEP621_DYNAMIC_FIELDS)) | ||
| ps = PackageSettings.from_string( | ||
| "test-pkg", | ||
| f""" | ||
| project_override: | ||
| add_dynamic_field: | ||
| {fields_yaml} | ||
| """, | ||
| ) | ||
| assert sorted(ps.project_override.add_dynamic_field) == sorted( | ||
| PEP621_DYNAMIC_FIELDS | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normalize before comparing.
The current
set(...)check hides changes that only remove duplicates or reorder the list, so pre-existing malformed[project].dynamicarrays never get cleaned up unless a new field is added.♻️ Suggested fix
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree.
file when it actually adds a new field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jskladan, you're right — I'll withdraw the suggestion. Theset()comparison correctly answers "did we actually add a new field?", sincemergedis always a superset ofold_dynamic. My proposedmerged != old_dynamicwould have incorrectly triggered rewrites for pre-existing ordering or duplicate differences, which is outside the scope of this function. The current logic is sound.