Skip to content
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

Validate license-files glob patterns #4841

Closed

Conversation

cdce8p
Copy link
Contributor

@cdce8p cdce8p commented Feb 18, 2025

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-files in setup.cfg and tools.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

@cdce8p cdce8p force-pushed the validate-license-file-patterns branch 5 times, most recently from 4257919 to b50f10b Compare February 18, 2025 22:39
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"
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is similar to the validation pattern I added in flit a few weeks ago. pypa/flit#705

@cdce8p cdce8p force-pushed the validate-license-file-patterns branch from b50f10b to 6c0156f Compare February 18, 2025 22:53
@abravalheri
Copy link
Contributor

abravalheri commented Feb 19, 2025

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
(to give the few people that test in the CI with PYTHONWARNINGS set to error the chance to adapt).

It is a bit annoying that PEP 638 is so heavy in terms of mandatory validations...
And also a pity that we cannot keep the nice existing lazy/iterator style that we currently have when implement the "no file match for individual pattern" error.

@cdce8p cdce8p closed this Feb 20, 2025
@cdce8p cdce8p deleted the validate-license-file-patterns branch February 20, 2025 15:45
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