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

poetry check command validates readme (files must exist) #7444

Merged
merged 18 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/pyproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ The file(s) can be of any format, but if you intend to publish to PyPI keep the
https://packaging.python.org/en/latest/guides/making-a-pypi-friendly-readme/) in
mind. README paths are implicitly relative to `pyproject.toml`.

{{% note %}}
Whether paths are case-sensitive follows platform defaults, but it is recommended to keep cases.

To be specific, you can set `readme = "rEaDmE.mD"` for `README.md` on macOS and Windows, but Linux users can't `poetry install` after cloning your repo. This is because macOS and Windows are case-insensitive and case-preserving.
{{% /note %}}

The contents of the README file(s) are used to populate the [Description
field](https://packaging.python.org/en/latest/specifications/core-metadata/#description-optional)
of your distribution's metadata (similar to `long_description` in setuptools).
Expand Down
28 changes: 28 additions & 0 deletions src/poetry/console/commands/check.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from poetry.console.commands.command import Command


if TYPE_CHECKING:
from pathlib import Path


class CheckCommand(Command):
name = "check"
description = "Checks the validity of the <comment>pyproject.toml</comment> file."
Expand Down Expand Up @@ -57,6 +63,22 @@ def validate_classifiers(

return errors, warnings

def validate_readme(
self, readme: str | list[str], poetry_file: Path
) -> tuple[list[str], list[str]]:
"""Check existence of referenced readme files"""

errors = []
warnings: list[str] = []
YDX-2147483647 marked this conversation as resolved.
Show resolved Hide resolved

readmes = [readme] if isinstance(readme, str) else readme

for name in readmes:
if not (poetry_file.parent / name).exists():
errors.append(f"Declared README file must exist: found {name}")
YDX-2147483647 marked this conversation as resolved.
Show resolved Hide resolved

return errors, warnings

def handle(self) -> int:
from poetry.factory import Factory
from poetry.pyproject.toml import PyProjectTOML
Expand All @@ -72,6 +94,12 @@ def handle(self) -> int:
check_result["errors"].extend(errors)
check_result["warnings"].extend(warnings)

# Validate readme (files must exist)
if "readme" in config:
errors, warnings = self.validate_readme(config["readme"], poetry_file)
check_result["errors"].extend(errors)
check_result["warnings"].extend(warnings)

if not check_result["errors"] and not check_result["warnings"]:
self.info("All set!")

Expand Down
1 change: 1 addition & 0 deletions tests/console/commands/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_check_invalid(
Error: 'description' is a required property
Error: Project name (invalid) is same as one of its dependencies
Error: Unrecognized classifiers: ['Intended Audience :: Clowns'].
Error: Declared README file must exist: found never/exists.md
Warning: A wildcard Python dependency is ambiguous.\
Consider specifying a more explicit one.
Warning: The "pendulum" dependency specifies the "allows-prereleases" property,\
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/invalid_pyproject/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "1.0.0"
authors = [
"Foo <foo@bar.com>"
]
readme = "never/exists.md"
license = "INVALID"
classifiers = [
"Environment :: Console",
Expand Down