Validate license-files glob patterns#4841
Closed
cdce8p wants to merge 1 commit intopypa:feature/pep639from
Closed
Conversation
2 tasks
4257919 to
b50f10b
Compare
cdce8p
commented
Feb 18, 2025
Comment on lines
472
to
485
| def _validate_and_expand_pattern(self, pattern): | ||
| """Validate license file patterns according to the PyPA specifications. | ||
| https://packaging.python.org/en/latest/specifications/pyproject-toml/#license-files | ||
| """ | ||
| if ".." in pattern: | ||
| raise InvalidConfigError( | ||
| f"License file pattern '{pattern}' cannot contain '..'" | ||
| ) | ||
| if pattern.startswith((os.sep, "/")) or ":\\" in pattern: | ||
| raise InvalidConfigError( | ||
| f"License file pattern '{pattern}' should be relative and " | ||
| "must not start with '/'" | ||
| ) | ||
| if _license_files_allowed_chars.match(pattern) is None: | ||
| raise InvalidConfigError( | ||
| f"License file pattern '{pattern}' contains invalid " | ||
| "characters. " | ||
| "https://packaging.python.org/en/latest/specifications/pyproject-toml/#license-files" | ||
| ) |
Member
Author
There was a problem hiding this comment.
This is similar to the validation pattern I added in flit a few weeks ago. pypa/flit#705
b50f10b to
6c0156f
Compare
Contributor
|
Thank you very much @cdce8p. I think I would like to absorb some of these validations into #4838. We will need to convert the exceptions into deprecation warnings as there is a change builds start to fail It is a bit annoying that PEP 638 is so heavy in terms of mandatory validations... |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Alternative approach to #4838.
Validate each pattern and raise an exception if it is invalid or a pattern doesn't match any license files.
This will also apply to existing configs with
license-filesinsetup.cfgandtools.setuptools.license-files, however I don't think that's an issue as these are almost always real problems and easy to fix.Ref: #4829