Skip to content
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

[BUG] AttributeError: '_Printer' object has no attribute 'split' in rfc822_escape #2741

Closed
1 task done
jhmartin opened this issue Jul 23, 2021 · 9 comments
Closed
1 task done
Labels
languishing Needs Repro Issues that need a reproducible example.

Comments

@jhmartin
Copy link

jhmartin commented Jul 23, 2021

setuptools version

57.4.0

Python version

3.8.11

OS

OSX (Docker image python:3.8)

Additional environment information

I suspect https://github.com/pypa/setuptools/pull/2640/files triggered it.
56.2.0 fails.
56.1.0 works.

Description

My setup.py is

setup(
    name=name,
    version=version,
    packages=['REDACTED'],
    author=author,
    author_email=author_email,
    classifiers=[
        'Development Status :: Release',
        'Intended Audience :: Developers',
        'Topic :: Utilities',
        'Natural Language :: English',
        'License :: Private Domain',
        'Operating System :: Linux',
        'Programming Language :: Python :: 3.7'
    ],
    description=description,
    install_requires=install_requirements,
    long_description=readme,
    include_package_data=True,
    setup_requires=['setuptools_scm'],
    license=license,
    keywords=['REDACTED', 'REDACTED', 'REDACTED', 'REDACTED', 'REDACTED'],
    url=url,
    zip_safe=False,
    entry_points={
        'console_scripts': [
            "REDACTED = REDACTED.cli.cli:cli"
        ]
    }
)

The repository does not have a LICENSE.txt in it.

My version.py has:

__title__ = 'REDACTED'
__description__ = 'REDACTED'
__url__ = 'REDACTED'
__author__ = 'REDACTED'
__author_email__ = 'REDACTED'
__license__ = 'Proprietary'
__copyright__ = 'REDACTED'
__name__ = "REDACTED"
__version__ = '1.10.0'
__final_release__ = False

Build fails as seen in the console output below.

Expected behavior

The build should complete.

How to Reproduce

Build an egg that does not specify a license in license.py, but does in __version__.py as a single line.
The build will fail as shown in Output.

Output

writing MYAPP.egg-info/PKG-INFO
Traceback (most recent call last):
  File "setup.py", line 43, in <module>
    setup(
  File "/usr/local/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/local/lib/python3.8/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/local/lib/python3.8/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.8/site-packages/setuptools/command/sdist.py", line 42, in run
    self.run_command('egg_info')
  File "/usr/local/lib/python3.8/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.8/site-packages/setuptools/command/egg_info.py", line 292, in run
    writer(self, ep.name, os.path.join(self.egg_info, ep.name))
  File "/usr/local/lib/python3.8/site-packages/setuptools/command/egg_info.py", line 635, in write_pkg_info
    metadata.write_pkg_info(cmd.egg_info)
  File "/usr/local/lib/python3.8/distutils/dist.py", line 1117, in write_pkg_info
    self.write_pkg_file(pkg_info)
  File "/usr/local/lib/python3.8/site-packages/setuptools/dist.py", line 185, in write_pkg_file
    license = rfc822_escape(self.get_license())
  File "/usr/local/lib/python3.8/distutils/util.py", line 475, in rfc822_escape
    lines = header.split('\n')

Code of Conduct

  • I agree to follow the PSF Code of Conduct
@jhmartin jhmartin added bug Needs Triage Issues that need to be evaluated for severity and status. labels Jul 23, 2021
@cowboy-cod3r
Copy link

I too have run into this. Downgrading to setuptools 56.1.0 as @jhmartin suggested worked.

@jhmartin
Copy link
Author

Setting

    license="Somestring",

in setup.py also works around the issue.

@jaraco
Copy link
Member

jaraco commented Sep 12, 2021

As reported, the setup.py is invalid. It sets version=version, but version is undefined. Can you provide more detail as to ascertain what (preferably minimal) inputs are required to trigger the error?

gruentee added a commit to gruentee/fever-api that referenced this issue Sep 22, 2021
Necessary to be able to install with setuptools>`56.1.0`, see pypa/setuptools#2741
gruentee added a commit to gruentee/fever-api that referenced this issue Sep 22, 2021
Necessary to be able to install with setuptools>`56.1.0`, see pypa/setuptools#2741
@jaraco jaraco closed this as completed Oct 22, 2021
@jaraco jaraco added languishing and removed Needs Triage Issues that need to be evaluated for severity and status. labels Oct 22, 2021
@Arun-Karunakaran
Copy link

Arun-Karunakaran commented Mar 6, 2022

Even I ran in this error ,

Traceback (most recent call last):
  File "setup.py", line 85, in <module>
    setup(
  File "/usr/local/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/local/lib/python3.8/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/local/lib/python3.8/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.8/distutils/command/bdist.py", line 143, in run
    self.run_command(cmd_name)
  File "/usr/local/lib/python3.8/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.8/distutils/command/bdist_dumb.py", line 89, in run
    self.run_command('install')
  File "/usr/local/lib/python3.8/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.8/site-packages/setuptools/command/install.py", line 61, in run
    return orig.install.run(self)
  File "/usr/local/lib/python3.8/distutils/command/install.py", line 557, in run
    self.run_command(cmd_name)
  File "/usr/local/lib/python3.8/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.8/site-packages/setuptools/command/install_egg_info.py", line 34, in run
    self.run_command('egg_info')
  File "/usr/local/lib/python3.8/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.8/site-packages/setuptools/command/egg_info.py", line 292, in run
    writer(self, ep.name, os.path.join(self.egg_info, ep.name))
  File "/usr/local/lib/python3.8/site-packages/setuptools/command/egg_info.py", line 635, in write_pkg_info
    metadata.write_pkg_info(cmd.egg_info)
  File "/usr/local/lib/python3.8/distutils/dist.py", line 1117, in write_pkg_info
    self.write_pkg_file(pkg_info)
  File "/usr/local/lib/python3.8/site-packages/setuptools/dist.py", line 185, in write_pkg_file
    license = rfc822_escape(self.get_license())
  File "/usr/local/lib/python3.8/distutils/util.py", line 475, in rfc822_escape
    lines = header.split('\n')
AttributeError: 'tuple' object has no attribute 'split'

Please suggest an option to resolve this asap.

@jaraco
Copy link
Member

jaraco commented Mar 6, 2022

Hi Arun. Your traceback provides no insight that changes any of the analysis previously done above. I've requested additional information from the original poster without response. If there's going to be any progress on this issue, it's going to require someone to come up with a reproducer that demonstrates what inputs are necessary to trigger the error.

@jaraco jaraco added Needs Repro Issues that need a reproducible example. and removed bug labels Mar 6, 2022
@Mr-ZJH
Copy link

Mr-ZJH commented Jul 10, 2022

useful

@tristanbrown
Copy link

tristanbrown commented Feb 12, 2023

I have also encountered this issue using setuptools 67.1.0. The bug occurs if the "license" kwarg is set by importing it from another module.

## setup.py
from setuptools import setup, find_packages

import __about__

REQUIREMENTS = [
    'python-dotenv',
    'pandas>=1.1.0',
    'psycopg2-binary',
    'sqlalchemy',
    'alembic',
    'arrow',
]

setup(
    name=__about__.__name__,
    version=__about__.__version__,
    author=__about__.__author__,
    author_email=__about__.__email__,
    description=__about__.__desc__,
    license=__about__.__license__,
    packages=find_packages(where='src'),
    package_dir={'': 'src'},
    install_requires=REQUIREMENTS,
    python_requires='>=3.6, !=3.7.2',
    entry_points={
        'console_scripts': [
        ]
    },
)
## __about__.py

__name__ = 'my_package'
__version__ = '0.0.1'
__author__ = "Tristan Brown",
__email__ = "myemail@gmail.com",
__desc__ = "Example.",
__license__ = "MIT",

If I change the license=__about__.__license__, line to license="MIT",, then the bug does not occur. None of the other imported values are a problem.

@jaraco
Copy link
Member

jaraco commented Feb 12, 2023

Hey Tristan. Thanks for the repro. I created the two files you suggested and also created a src directory to satisfy the packages directive, and was able to replicate an error. The error encountered is AttributeError: 'tuple' object has no attribute 'split'. That's because you're setting license to "MIT",, which is equivalent to ("MIT",) (notice the trailing comma), and a tuple is not an allowed type for license.

setup.py invocation is discouraged and you should port your usage to setup.cfg or pyproject.toml. I was able to port your example to something that works:

 draft $ tree
.
├── pyproject.toml
├── setup.cfg
└── src
    └── __about__.py

2 directories, 3 files
 draft $ cat pyproject.toml
[build-system]
requires = ["setuptools>=56"]
build-backend = "setuptools.build_meta"
 draft $ cat setup.cfg
[metadata]
name=my_package
version=attr:__about__.__version__
author= Tristan Brown
author_email= myemail@gmail.com
description=Example.
license=MIT
 draft $ cat src/__about__.py
__version__ = '0.0.1'
 draft $ pip-run .
Python 3.11.1 (main, Dec 23 2022, 09:28:24) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import importlib.metadata as md
>>> dist = md.distribution('my_package')
>>> dist.metadata['name']
'my-package'
>>> dist.metadata['version']
'0.0.1'
>>> dist.metadata['author']
'Tristan Brown'
>>> dist.metadata['author-email']
'myemail@gmail.com'
>>> dist.metadata['summary']
'Example.'
>>> dist.metadata['license']
'MIT'
>>> ^D

@tristanbrown
Copy link

Indeed, it was the misplaced commas that broke it. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
languishing Needs Repro Issues that need a reproducible example.
Projects
None yet
Development

No branches or pull requests

6 participants