-
Notifications
You must be signed in to change notification settings - Fork 251
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
Add support for multiple README files (retrocompatible) #248
Add support for multiple README files (retrocompatible) #248
Conversation
This makes poetry aware about the upcoming changes in poetry-core in order to support declaration of multiple readme files in pyproject.toml Relates python-poetry#873 Enable python-poetry/poetry-core#248
This code reuses the `"readme"` entry in a way to allow the user to declare in the old way or the new way. With the changes, the two following declarations are valid: **Single file** ```toml readme = "README.rst" ``` **Multiple files** ```toml readme = [ "README.rst", "HISTORY.rst" ] ``` If the user declares files in different formats, the strict validation will issue. NOTICE: The class `Package` suffered an important change: `readme` was renamed to the plural `readmes`. Properties for the single form were introduced to ensure retrocompatibility.
cbe43f3
to
eb8883e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not the biggest fan of adding another helper, but we can always move it later during a cleanup of that module.
LGTM after feedback is addressed.
src/poetry/core/factory.py
Outdated
@@ -421,6 +426,14 @@ 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 = [readme_content_type(r) for r in config["readme"]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readme_types = [readme_content_type(r) for r in config["readme"]] | |
readme_types = {readme_content_type(r) for r in config["readme"]} |
No reason not to use a set from the start...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I took this decision prematurely, motivated by the fact the set
gives non-predictable order (which is important for me in the unit test). I am solving this by adding sorted(readme_types)
in the error message value.
src/poetry/core/factory.py
Outdated
# Checking types of all readme files (must match) | ||
if "readme" in config and not isinstance(config["readme"], str): | ||
readme_types = [readme_content_type(r) for r in config["readme"]] | ||
if len(set(readme_types)) > 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...which means we can drop the set()
call.
src/poetry/core/packages/package.py
Outdated
import warnings | ||
|
||
warnings.warn( | ||
"`readme` is deprecated: you are getting only the first readme file. Please use the plural form `readmes`", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a period to the end of this sentence.
src/poetry/core/packages/package.py
Outdated
import warnings | ||
|
||
warnings.warn( | ||
"`readme` is deprecated. Please assign a tuple to the plural form `readmes`", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
@neersighted I have to say that I deeply consider about this decision. But the lack of a new helper would mean to store the content type into Package, which doesn't fit IMHO. So I decided to have the helper. |
Overview
This code was merged before on #118 and reverted on #235, due to the breaking of
Package.readme
is renamed toPackage.readmes
and it is aTuple[Path]
instead of simplyPath
.In this PR you will find mostly the same thing of #118 with a few little improvements.
Description
This code reuses the
"readme"
entry in a way to allow the user to declare in the old way or the new way.With the changes, the two following declarations are valid:
Single file
Multiple files
If the user declares files in different formats, the strict validation will issue.
Notice
The class
Package
suffered an important change:readme
was renamed to the pluralreadmes
. Properties for the single form were introduced to ensure retrocompatibility.Pull Request Check List
Resolves: python-poetry/poetry#873