-
Notifications
You must be signed in to change notification settings - Fork 84
fix: detect override vs. config-settings #1262
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
Draft
henryiii
wants to merge
1
commit into
main
Choose a base branch
from
henryiii/fix/override
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,22 +137,28 @@ def _handle_move( | |
|
|
||
| def _validate_overrides( | ||
| settings: ScikitBuildSettings, | ||
| static_settings: ScikitBuildSettings, | ||
| overrides: dict[str, OverrideRecord], | ||
| config_setting_keys: set[str], | ||
| ) -> None: | ||
| """Validate all fields with any override information.""" | ||
|
|
||
| def validate_field( | ||
| field: dataclasses.Field[Any], | ||
| value: Any, | ||
| static_value: Any, | ||
| prefix: str = "", | ||
| record: OverrideRecord | None = None, | ||
| ) -> None: | ||
| """Do the actual validation.""" | ||
| # Check if we had a hard-coded value in the record | ||
| conf_key = field.name.replace("_", "-") | ||
| if field.metadata.get("override_only", False): | ||
| original_value = record.original_value if record else value | ||
| if original_value is not None: | ||
| full_key = f"{prefix}{conf_key}" | ||
| original_value = record.original_value if record else static_value | ||
| if original_value is not None or ( | ||
| value is not None and full_key not in config_setting_keys | ||
| ): | ||
| msg = f"{prefix}{conf_key} is not allowed to be hard-coded in the pyproject.toml file" | ||
| if settings.strict_config: | ||
| sys.stdout.flush() | ||
|
|
@@ -162,6 +168,7 @@ def validate_field( | |
|
|
||
| def validate_field_recursive( | ||
| obj: Any, | ||
| static_obj: Any, | ||
| record: OverrideRecord | None = None, | ||
| prefix: str = "", | ||
| ) -> None: | ||
|
|
@@ -170,20 +177,25 @@ def validate_field_recursive( | |
| conf_key = field.name.replace("_", "-") | ||
| closest_record = overrides.get(f"{prefix}{conf_key}", record) | ||
| value = getattr(obj, field.name) | ||
| static_value = getattr(static_obj, field.name) | ||
| # Do the validation of the current field | ||
| validate_field( | ||
| field=field, | ||
| value=value, | ||
| static_value=static_value, | ||
| prefix=prefix, | ||
| record=closest_record, | ||
| ) | ||
| if dataclasses.is_dataclass(value): | ||
| validate_field_recursive( | ||
| obj=value, record=closest_record, prefix=f"{prefix}{conf_key}." | ||
| obj=value, | ||
| static_obj=static_value, | ||
| record=closest_record, | ||
| prefix=f"{prefix}{conf_key}.", | ||
| ) | ||
|
|
||
| # Navigate all fields starting from the top-level | ||
| validate_field_recursive(obj=settings) | ||
| validate_field_recursive(obj=settings, static_obj=static_settings) | ||
|
|
||
|
|
||
| class SettingsReader: | ||
|
|
@@ -250,6 +262,9 @@ def __init__( | |
| remaining = { | ||
| k: v for k, v in config_settings.items() if not k.startswith("skbuild.") | ||
| } | ||
| self.config_setting_keys = { | ||
| k[8:] if k.startswith("skbuild.") else k for k in config_settings | ||
| } | ||
| self.sources = SourceChain( | ||
| EnvSource("SKBUILD", env=env), | ||
| ConfSource("skbuild", settings=prefixed, verify=verify_conf), | ||
|
|
@@ -259,7 +274,7 @@ def __init__( | |
| ) | ||
| self.settings = self.sources.convert_target(ScikitBuildSettings) | ||
|
|
||
| static_settings = SourceChain( | ||
| self.static_settings = SourceChain( | ||
|
Comment on lines
-262
to
+277
Collaborator
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. Maybe what we need here is to break down the |
||
| *toml_srcs, prefixes=["tool", "scikit-build"] | ||
| ).convert_target(ScikitBuildSettings) | ||
|
|
||
|
|
@@ -350,8 +365,8 @@ def __init__( | |
| self.settings.build.verbose, | ||
| self.settings.minimum_version, | ||
| Version("0.10"), | ||
| static=static_settings.cmake.verbose == self.settings.cmake.verbose | ||
| and static_settings.build.verbose == self.settings.build.verbose, | ||
| static=self.static_settings.cmake.verbose == self.settings.cmake.verbose | ||
| and self.static_settings.build.verbose == self.settings.build.verbose, | ||
| ) | ||
| self.settings.build.targets = _handle_move( | ||
| "cmake.targets", | ||
|
|
@@ -360,8 +375,8 @@ def __init__( | |
| self.settings.build.targets, | ||
| self.settings.minimum_version, | ||
| Version("0.10"), | ||
| static=static_settings.cmake.targets == self.settings.cmake.targets | ||
| and static_settings.build.targets == self.settings.build.targets, | ||
| static=self.static_settings.cmake.targets == self.settings.cmake.targets | ||
| and self.static_settings.build.targets == self.settings.build.targets, | ||
| ) | ||
|
|
||
| if self.settings.sdist.inclusion_mode is not None: | ||
|
|
@@ -421,7 +436,12 @@ def validate_may_exit(self) -> None: | |
| self.print_suggestions() | ||
| raise SystemExit(7) | ||
| logger.warning("Unrecognized options: {}", ", ".join(unrecognized)) | ||
| _validate_overrides(self.settings, self.overridden_items) | ||
| _validate_overrides( | ||
| self.settings, | ||
| self.static_settings, | ||
| self.overridden_items, | ||
| self.config_setting_keys, | ||
| ) | ||
|
|
||
| for key, value in self.settings.metadata.items(): | ||
| if "provider" not in value: | ||
|
|
||
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.
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.
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 think the logic here is right, but can't tell exactly what it should be. I think it fails if the user provided if from env-variable.