-
Notifications
You must be signed in to change notification settings - Fork 326
Fix handling of continuation lines in Description metadata field #1220
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix handling of multiline ``Description`` metadata fields. |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -65,6 +65,28 @@ def _safe_name(name: str) -> str: | |||||||
| return re.sub("[^A-Za-z0-9.]+", "-", name) | ||||||||
|
|
||||||||
|
|
||||||||
| def _dedent(string: str) -> str: | ||||||||
| """Remove line continuation suffix used for the ``Description`` metadata field. | ||||||||
|
|
||||||||
| The metadata standard prescribes that continuation lines should be | ||||||||
| prefixed with 7 spaces followed by a pipe character, however, setuptools | ||||||||
| used to prefix continuation lines with 8 spaces. Handle both here. | ||||||||
|
|
||||||||
| If not all lines following the first start with either of the accepted | ||||||||
| prefixes, the string is returned without modifications. | ||||||||
| """ | ||||||||
| lines = string.splitlines() | ||||||||
| if ( | ||||||||
| False # This is here only to force black into something sensible. | ||||||||
| or all(line.startswith(" |") for line in lines[1:]) | ||||||||
| or all(line.startswith(" ") for line in lines[1:]) | ||||||||
|
Comment on lines
+81
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would implement a different check. The code as written tests whether all the line start with 8 spacer or all the lines start with 7 spaced and a pipe. The proposed code tests whether all the lines start with either 8 spaces or 7 spaces and a pipe. I don't think we should treat intermixed continuation style as valid. There is a test that ensures that someone else is not tempted into the same erroneous simplification. |
||||||||
| ): | ||||||||
| for i in range(1, len(lines)): | ||||||||
| lines[i] = lines[i][8:] | ||||||||
| return "\n".join(lines) | ||||||||
| return string | ||||||||
|
|
||||||||
|
|
||||||||
| # Map ``metadata.RawMetadata`` fields to ``PackageMetadata`` fields. Some | ||||||||
| # fields are renamed to match the names expected in the upload form. | ||||||||
| _RAW_TO_PACKAGE_METADATA = { | ||||||||
|
|
@@ -232,6 +254,11 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile": | |||||||
| # than 2.4. | ||||||||
| if version.Version(meta.get("metadata_version", "0")) < version.Version("2.4"): | ||||||||
| meta.pop("license_files", None) | ||||||||
|
|
||||||||
| description = meta.get("description", None) | ||||||||
| if description is not None: | ||||||||
| meta["description"] = _dedent(description) | ||||||||
|
Comment on lines
+258
to
+260
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this behavior is only necessary for a small and shrinking subset of users, perhaps it should be implemented as one line here (e.g. |
||||||||
|
|
||||||||
| try: | ||||||||
| metadata.Metadata.from_raw(meta) | ||||||||
| except metadata.ExceptionGroup as group: | ||||||||
|
|
||||||||
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 know exactly why this is here (psf/black#2156). I decided to use
# fmt: skipto avoid the need to write the comment.