question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Newlines in the `description` field produce a malformed PKG-INFO

See original GitHub issue

We discovered this accidentally by way of https://github.com/zopefoundation/zc.relation/issues/4#issuecomment-397532224: if you pass a string containing newlines to the description argument of setup(), setuptools will generate a malformed PKG-INFO.

To reproduce:

# setup.py
from setuptools import setup
setup(
    name='test-package',
    version='0.1',
    author='Blah Blah',
    author_email='blah@example.com',
    description='description\n\n',
    py_modules=['blah'],
)

(The contents of blah.py do not matter, but the file should exist.)

Run python setup.py sdist and the inspect test_package.egg-info/PKG-INFO. For me, with setuptools 39.1.0, it looks like this:

Metadata-Version: 1.0
Name: test-package
Version: 0.1
Summary: description


Home-page: UNKNOWN
Author: Blah Blah
Author-email: blah@example.com
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN

The extra newlines lead tools to treat the rest of the PKG-INFO as a long_description.

I would expect setuptools to complain about the newlines in the description field, or at least escape them properly (i.e. prepend whitespace, like it does for the long_description field).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:42 (22 by maintainers)

github_iconTop GitHub Comments

5reactions
bittnercommented, Oct 1, 2018

I see the options as:

  1. Escape newlines in the text so they aren’t interpreted as delimiters.
  2. Raise an error whenever double newlines are found outside of long_description.
  3. Silently s/\n+/\n/g for everything except long_description.

I think I prefer 1 as least disruptive, but I’m ambivalent between 2 and 3. 2 is more explicit, but 3 creates less “churn” (since this will just be auto-magically fixed).

We should fail hard for configurations that are invalid. There should be an error message that gives a clear indication on how to fix the problem. This is a developer API, and developers should deal with their broken code. We shouldn’t try to guess-fix broken stuff.

Do the fields/kwargs have an explicit specification of the data they expect? This should be enforced. The fields description and license obviously expect single-line data. Hence, when a newline is submitted in the data for those fields the generation of PKG-INFO should be aborted with a clear error message, e.g.

$ python3 setup.py sdist
ERROR: The "description" field requires a single line of text. Multi-line text was supplied.
Aborting.
3reactions
Mekkcommented, Jan 17, 2021

setuptools 51.3.0 landed and I immediately got some error report about broken (internal) builds.

Reporting error here is not a good idea, really.

Please, don’t go that way. Drop description altogether if you don’t like it and can’t fix it, but don’t break installations. Ecosystem is huge, libraries are plenty, automated builds are numerous…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: Automation rule encountered newline and failed
Solved: Is there a way to copy a field (i.e. the Summary) during a rule to create a new issue WITHOUT encountering this...
Read more >
How to add a line break to the description field o... - ServiceNow
For this catalog item I am working on, for the description they want essentially multiple sentences to be showing on their own with...
Read more >
Newline - Wikipedia
Newline is a control character or sequence of control characters in character encoding specifications such as ASCII, EBCDIC, Unicode, etc.
Read more >
REST api new Task with newlines in Description field
Using PowerShell and the REST api I'm creating new work item Tasks in ADS. I want the Description field to include line breaks, ......
Read more >
How to add line-break in the google groups description field?
The last thing you can try is to URI encode the '\n' using %0A . This seems to have been successfully used in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found