Add support for multiple README files (retrocompatible)#248
Add support for multiple README files (retrocompatible)#248neersighted merged 3 commits intopython-poetry:masterfrom wagnerluis1982:rework-support-multiple-readme-files
Conversation
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.
neersighted
left a comment
There was a problem hiding this comment.
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
|
|
||
| # 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.
| 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.
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.
...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.
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`", |
@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.readmeis renamed toPackage.readmesand 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
Packagesuffered an important change:readmewas renamed to the pluralreadmes. Properties for the single form were introduced to ensure retrocompatibility.Pull Request Check List
Resolves: python-poetry/poetry#873