feat(check): validate [project.readme] field as per PEP 621#10604
Merged
radoering merged 5 commits intopython-poetry:mainfrom Nov 1, 2025
Merged
feat(check): validate [project.readme] field as per PEP 621#10604radoering merged 5 commits intopython-poetry:mainfrom
radoering merged 5 commits intopython-poetry:mainfrom
Conversation
Reviewer's GuideRefactors the 'check' command to extend readme validation beyond tool.poetry to PEP 621's [project.readme], consolidating error collection and handling multiple formats with existence checks and format error reporting. Class diagram for updated readme validation in check commandclassDiagram
class CheckCommand {
+handle()
+_validate_readme(readme, poetry_file)
+_validate_dependencies_source(config)
}
CheckCommand : +handle() updated to validate [project.readme] per PEP 621
CheckCommand : +handle() now supports dict and str formats for [project.readme]
CheckCommand : +handle() reports format errors for invalid [project.readme]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/poetry/console/commands/check.py:157-168` </location>
<code_context>
+ if "readme" in poetry_config:
+ readme_errors += self._validate_readme(poetry_config["readme"], poetry_file)
+
+ project_readme = project.get("readme")
+ if project_readme:
+ if isinstance(project_readme, dict):
+ readme_path = project_readme.get("file")
+ if readme_path:
+ readme_errors += self._validate_readme(readme_path, poetry_file)
+ elif isinstance(project_readme, str):
+ readme_errors += self._validate_readme(project_readme, poetry_file)
+ else:
+ readme_errors.append(
+ f"Invalid format for [project.readme]: {project_readme!r}"
+ )
</code_context>
<issue_to_address>
**suggestion:** Consider handling multiple readme files in [project.readme] if specified as a list.
PEP 621 permits [project.readme] to be a list of strings. Please update the logic to handle lists and validate each file's existence.
```suggestion
project_readme = project.get("readme")
if project_readme:
if isinstance(project_readme, dict):
readme_path = project_readme.get("file")
if readme_path:
readme_errors += self._validate_readme(readme_path, poetry_file)
elif isinstance(project_readme, str):
readme_errors += self._validate_readme(project_readme, poetry_file)
elif isinstance(project_readme, list):
for readme_item in project_readme:
if isinstance(readme_item, str):
readme_errors += self._validate_readme(readme_item, poetry_file)
else:
readme_errors.append(
f"Invalid entry in [project.readme] list: {readme_item!r}"
)
else:
readme_errors.append(
f"Invalid format for [project.readme]: {project_readme!r}"
)
```
</issue_to_address>
### Comment 2
<location> `src/poetry/console/commands/check.py:166` </location>
<code_context>
+ readme_errors += self._validate_readme(project_readme, poetry_file)
+ else:
+ readme_errors.append(
+ f"Invalid format for [project.readme]: {project_readme!r}"
+ )
+
</code_context>
<issue_to_address>
**suggestion:** Consider providing guidance on valid [project.readme] formats in the error message.
Include the accepted formats (string, dict with 'file', or list of strings) in the error message to help users fix configuration issues.
```suggestion
readme_errors.append(
f"Invalid format for [project.readme]: {project_readme!r}. "
"Accepted formats are: a string (filename), a dict with a 'file' key, or a list of strings (filenames)."
)
```
</issue_to_address>
### Comment 3
<location> `src/poetry/console/commands/check.py:134` </location>
<code_context>
def handle(self) -> int:
from poetry.core.pyproject.toml import PyProjectTOML
from poetry.factory import Factory
# Load poetry config and display errors, if any
poetry_file = self.poetry.file.path
toml_data = PyProjectTOML(poetry_file).data
check_result = Factory.validate(toml_data, strict=True)
project = toml_data.get("project", {})
poetry_config = toml_data["tool"]["poetry"]
# Validate trove classifiers
project_classifiers = set(
project.get("classifiers") or poetry_config.get("classifiers", [])
)
errors, warnings = self._validate_classifiers(project_classifiers)
check_result["errors"].extend(errors)
check_result["warnings"].extend(warnings)
readme_errors = []
# Check [tool.poetry.readme]
if "readme" in poetry_config:
readme_errors += self._validate_readme(poetry_config["readme"], poetry_file)
project_readme = project.get("readme")
if project_readme:
if isinstance(project_readme, dict):
readme_path = project_readme.get("file")
if readme_path:
readme_errors += self._validate_readme(readme_path, poetry_file)
elif isinstance(project_readme, str):
readme_errors += self._validate_readme(project_readme, poetry_file)
else:
readme_errors.append(
f"Invalid format for [project.readme]: {project_readme!r}"
)
check_result["errors"].extend(readme_errors)
# Validate dependencies' sources
check_result["errors"] += self._validate_dependencies_source(poetry_config)
# Verify that lock file is consistent
if self.option("lock") and not self.poetry.locker.is_locked():
check_result["errors"] += ["poetry.lock was not found."]
if self.poetry.locker.is_locked() and not self.poetry.locker.is_fresh():
check_result["errors"] += [
"pyproject.toml changed significantly since poetry.lock was last generated. "
"Run `poetry lock` to fix the lock file."
]
return_code = 0
if check_result["errors"] or (
check_result["warnings"] and self.option("strict")
):
return_code = 1
if not check_result["errors"] and not check_result["warnings"]:
self.info("All set!")
for error in check_result["errors"]:
self.line_error(f"<error>Error: {error}</error>")
for error in check_result["warnings"]:
self.line_error(f"<warning>Warning: {error}</warning>")
return return_code
</code_context>
<issue_to_address>
**issue (code-quality):** Use named expression to simplify assignment and conditional [×2] ([`use-named-expression`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/use-named-expression/))
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Kelleretoro
approved these changes
Oct 30, 2025
radoering
requested changes
Oct 31, 2025
Member
radoering
left a comment
There was a problem hiding this comment.
Can you add tests in test_check.py, please?
Kelleretoro
approved these changes
Nov 1, 2025
Kelleretoro
approved these changes
Nov 1, 2025
Kelleretoro
approved these changes
Nov 1, 2025
Member
|
pre-commit.ci autofix |
Kelleretoro
approved these changes
Nov 1, 2025
Kelleretoro
approved these changes
Nov 1, 2025
Kelleretoro
approved these changes
Nov 1, 2025
Kelleretoro
approved these changes
Nov 1, 2025
This adds validation for [project.readme] defined according to PEP 621. Previously, Poetry only validated [tool.poetry.readme]. The new logic ensures referenced files in [project.readme] exist and are accessible.
radoering
approved these changes
Nov 1, 2025
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This adds validation for [project.readme] defined according to PEP 621. Previously, Poetry only validated [tool.poetry.readme]. The new logic ensures referenced files in [project.readme] exist and are accessible.
Pull Request Check List
Resolves: #issue-number-here
Summary by Sourcery
Extend the check command to validate the existence and format of files referenced in the PEP 621 [project.readme] field in addition to the existing [tool.poetry.readme] validation.
New Features:
Enhancements: