Skip to content

Commit

Permalink
Revert "Add support for multiple README files (#118)"
Browse files Browse the repository at this point in the history
This reverts commit f101162.
  • Loading branch information
abn committed Nov 15, 2021
1 parent f101162 commit 9d25293
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 107 deletions.
25 changes: 1 addition & 24 deletions poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,7 @@ def configure_package(
package.classifiers = config.get("classifiers", [])

if "readme" in config:
if isinstance(config["readme"], str):
package.readmes = (root / config["readme"],)
else:
package.readmes = tuple(root / readme for readme in config["readme"])

package.description_type = cls._readme_content_type(package.readmes[0])
package.readme = root / config["readme"]

if "platform" in config:
package.platform = config["platform"]
Expand Down Expand Up @@ -424,14 +419,6 @@ def validate(cls, config: dict, strict: bool = False) -> Dict[str, List[str]]:
)
)

# Checking types of all readme files (must match)
if "readme" in config and not isinstance(config["readme"], str):
readme_types = [cls._readme_content_type(r) for r in config["readme"]]
if len(set(readme_types)) > 1:
result["errors"].append(
f"Declared README files must be of same type: found {', '.join(readme_types)}"
)

return result

@classmethod
Expand All @@ -451,13 +438,3 @@ def locate(cls, cwd: Path) -> Path:
cwd
)
)

@staticmethod
def _readme_content_type(path: Union[str, Path]) -> str:
suffix = Path(path).suffix
if suffix == ".rst":
return "text/x-rst"
elif suffix in [".md", ".markdown"]:
return "text/markdown"
else:
return "text/plain"
15 changes: 2 additions & 13 deletions poetry/core/json/schemas/poetry-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,8 @@
"$ref": "#/definitions/maintainers"
},
"readme": {
"anyOf": [
{
"type": "string",
"description": "The path to the README file."
},
{
"type": "array",
"description": "A list of paths to the readme files.",
"items": {
"type": "string"
}
}
]
"type": "string",
"description": "The path to the README file"
},
"classifiers": {
"type": "array",
Expand Down
18 changes: 10 additions & 8 deletions poetry/core/masonry/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ def from_package(cls, package: "Package") -> "Metadata":
meta.name = canonicalize_name(package.name)
meta.version = normalize_version(package.version.text)
meta.summary = package.description
if package.readmes:
descriptions = []
for readme in package.readmes:
with readme.open(encoding="utf-8") as f:
descriptions.append(f.read())
meta.description = "\n".join(descriptions)
if package.readme:
with package.readme.open(encoding="utf-8") as f:
meta.description = f.read()

meta.keywords = ",".join(package.keywords)
meta.home_page = package.homepage or package.repository_url
Expand All @@ -79,8 +76,13 @@ def from_package(cls, package: "Package") -> "Metadata":
meta.requires_dist = [d.to_pep_508() for d in package.requires]

# Version 2.1
if package.description_type:
meta.description_content_type = package.description_type
if package.readme:
if package.readme.suffix == ".rst":
meta.description_content_type = "text/x-rst"
elif package.readme.suffix in [".md", ".markdown"]:
meta.description_content_type = "text/markdown"
else:
meta.description_content_type = "text/plain"

meta.provides_extra = [e for e in package.extras]

Expand Down
3 changes: 1 addition & 2 deletions poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def __init__(
self.documentation_url = None
self.keywords = []
self._license = None
self.readmes = ()
self.description_type = None
self.readme = None

self.extras = {}
self.requires_extras = []
Expand Down
2 changes: 0 additions & 2 deletions tests/fixtures/with_readme_files/README-1.rst

This file was deleted.

2 changes: 0 additions & 2 deletions tests/fixtures/with_readme_files/README-2.rst

This file was deleted.

19 changes: 0 additions & 19 deletions tests/fixtures/with_readme_files/pyproject.toml

This file was deleted.

3 changes: 0 additions & 3 deletions tests/fixtures/with_readme_files/single_python.py

This file was deleted.

13 changes: 0 additions & 13 deletions tests/masonry/builders/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,3 @@ def test_builder_convert_script_files(fixture, result):
project_root = Path(__file__).parent / "fixtures" / fixture
script_files = Builder(Factory().create_poetry(project_root)).convert_script_files()
assert [p.relative_to(project_root) for p in script_files] == result


def test_metadata_with_readme_files():
test_path = Path(__file__).parent.parent.parent / "fixtures" / "with_readme_files"
builder = Builder(Factory().create_poetry(test_path))

metadata = Parser().parsestr(builder.get_metadata_content())

readme1 = test_path / "README-1.rst"
readme2 = test_path / "README-2.rst"
description = "\n".join([readme1.read_text(), readme2.read_text(), ""])

assert metadata.get_payload() == description
22 changes: 1 addition & 21 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_create_poetry():
assert package.authors == ["Sébastien Eustace <[email protected]>"]
assert package.license.id == "MIT"
assert (
package.readmes[0].relative_to(fixtures_dir).as_posix()
package.readme.relative_to(fixtures_dir).as_posix()
== "sample_project/README.rst"
)
assert package.homepage == "https://python-poetry.org"
Expand Down Expand Up @@ -185,26 +185,6 @@ def test_validate_fails():
assert Factory.validate(content) == {"errors": [expected], "warnings": []}


def test_validate_multiple_readme_files():
with_readme_files = TOMLFile(fixtures_dir / "with_readme_files" / "pyproject.toml")
content = with_readme_files.read()["tool"]["poetry"]

assert Factory.validate(content, strict=True) == {"errors": [], "warnings": []}


def test_validate_fails_on_readme_files_with_unmatching_types():
with_readme_files = TOMLFile(fixtures_dir / "with_readme_files" / "pyproject.toml")
content = with_readme_files.read()["tool"]["poetry"]
content["readme"][0] = "README.md"

assert Factory.validate(content, strict=True) == {
"errors": [
"Declared README files must be of same type: found text/markdown, text/x-rst"
],
"warnings": [],
}


def test_create_poetry_fails_on_invalid_configuration():
with pytest.raises(RuntimeError) as e:
Factory().create_poetry(
Expand Down

0 comments on commit 9d25293

Please sign in to comment.