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] Invalid string type when reading declarative `setup.cfg` under Python 2 #1136

Closed
webknjaz opened this issue Aug 27, 2017 · 8 comments
Closed
Assignees
Labels

Comments

@webknjaz
Copy link
Member

@webknjaz webknjaz commented Aug 27, 2017

Hi,

I'm seeing the following error:

error: 'egg_base' must be a directory name (got `src`)

The config contains:

[options]
...
package_dir =
     = src

Contents of package_dir is

{u'': u'src'}

(I've worked around this by manually reading config and patching this applying str() to keys and vars)

Python: 2.7
OS: GNU/Linux

The issue appears to be the same as for:

@jensens
Copy link

@jensens jensens commented Oct 25, 2017

I can confirm this problem.
I tried to empty the setup.py and use the declarative way with information in setup.cfg only.
This problem is the only stopper for me to use this way for Python 2. And since our packages shall support both, it is a stopper for Python 3 as well.

If setup.cfg contains:

package_dir = 
    = src

Under Python 2 the results values of the parsedict (from setuptools.config) are unicode strings:

>>> type(setuptools.config.read_configuration('setup.cfg')['options']['package_dir'][''])
<type 'unicode'>

While under Python 3

>>> type(setuptools.config.read_configuration('setup.cfg')['options']['package_dir'][''])
<class 'str'>

Which overall should be fine, but it is not. Under Python 2 a string <str> and not unicode seems to be expected.
I did not dig this down to distutils, but when modifing line 225 in setuptools.config to turn the type into a str with result[key.strip()] = str(val.strip()) all works fine.

@jaraco
Copy link
Member

@jaraco jaraco commented Oct 25, 2017

Rather than patching only setuptools.config, I'd like to see a patch for setuptools that allows for unicode to be used in setup.py as well. I thought the fix for #597 did that, but apparently not for all cases.

@benoit-pierre
Copy link
Member

@benoit-pierre benoit-pierre commented Oct 25, 2017

I believe #1062 is related. The problem with switching to Unicode for the results of reading the configuration is it will trips things like ensure_string or ensure_string_list in distutils when running under Python 2:
https://travis-ci.org/benoit-pierre/setuptools/jobs/292662535#L763

benoit-pierre added a commit to benoit-pierre/setuptools that referenced this issue Oct 25, 2017
Support the same mechanism as for Python sources for declaring
the encoding to be used when reading `setup.cfg` (see PEP 263),
and return the results of reading it as Unicode.

Fix pypa#1062 and pypa#1136.
benoit-pierre added a commit to benoit-pierre/setuptools that referenced this issue Oct 25, 2017
Support the same mechanism as for Python sources for declaring
the encoding to be used when reading `setup.cfg` (see PEP 263),
and return the results of reading it as Unicode.

Fix pypa#1062 and pypa#1136.
@eromoe
Copy link

@eromoe eromoe commented Dec 29, 2017

I am using win_unicode_console to handle unicode print in cmd, seems relate,
got same error:

 pip install pymultitor

....

    d:\python27\lib\site-packages\win_unicode_console\__init__.py:31: RuntimeWarning: sys.stdin.enco
ding == 'utf-8', whereas sys.stdout.encoding == None, readline hook consumer may assume they are the
 same
      readline_hook.enable(use_pyreadline=use_pyreadline)
    error: 'egg_base' must be a directory name (got `pip-egg-info`)
@uchuugaka
Copy link

@uchuugaka uchuugaka commented Feb 11, 2018

Seems this still blocks 3.x from Python 2.7.x does the issue in setuptools still persist?

@Midnighter
Copy link

@Midnighter Midnighter commented Apr 29, 2018

I'm seeing this issue right now with Python 2.7.12 and

pip        10.0.1
setuptools 39.1.0
wheel      0.31.0

what's the status of fixing this?

smartsammler added a commit to smartsammler/setuptools that referenced this issue Jun 4, 2018
As @jensens pointed out in a comment about issue pypa#1136 this is a first step to prevent the occurrence of that issue
kxepal added a commit to kxepal/setuptools-changelog that referenced this issue Jun 17, 2018
c00kiemon5ter added a commit to c00kiemon5ter/pysaml2 that referenced this issue Jul 3, 2018
A bug is blocking setuptools from working with python2 [bug]. Work is on its
way [pr]. Until that is fixed, package_dir should be defined in setup.py to
preserve compatibility of the native str type.

  [bug]: pypa/setuptools#1136
  [pr]: pypa/setuptools#1180

Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
jmaupetit added a commit to openfun/openedx-xapi that referenced this issue Oct 5, 2018
Add base project packaging configuration.

Note: setuptools seems to have issues when dealing with projects not
located in the project's root [1]. Let's be pragmatic and remove the
src/ directory.

1. pypa/setuptools#1136
jmaupetit added a commit to openfun/openedx-xapi that referenced this issue Oct 26, 2018
Add base project packaging configuration.

Note: setuptools seems to have issues when dealing with projects not
located in the project's root [1]. Let's be pragmatic and remove the
src/ directory.

1. pypa/setuptools#1136
@jaraco jaraco self-assigned this Jan 25, 2019
@jaraco
Copy link
Member

@jaraco jaraco commented Jan 27, 2019

Work in #1180 released as 40.7.0.

@aarchiba
Copy link

@aarchiba aarchiba commented Oct 16, 2019

We have users still reporting this with setuptools 41.4

kevinoid added a commit to kevinoid/python-project-template that referenced this issue Oct 21, 2020
Rather than depending on the version of setuptools shipped with any
particular version of Python, or any packages that may be preinstalled
in the test environment, upgrade test/packaging dependencies before
running tests or building wheels.

Note:  This fixes two specific issues:
- Appveyor images may have an old setuptools version installed for some
  Python versions (e.g. Python 3.5 currently has setuptools 28.8.0).
  This can cause problems due to setup.py requiring 30.3.0.  Upgrade
  required packages during install.
- Travis CI "error: 'egg_base' must be a directory name (got `src`)" on
  some python versions (e.g. 2.7) likely due to
  pypa/setuptools#1136

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
kevinoid added a commit to kevinoid/python-project-template that referenced this issue Oct 22, 2020
The version of setuptools in the Travis virtualenv is current (44.1.1),
but tox .package get-build-requires fails with:

    running egg_info
    error: 'egg_base' must be a directory name (got `src`)

Which appears to be pypa/setuptools#1136
Perhaps Debian package (copied into virtualenv) is affected?  Reinstall
to avoid the issue.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants
You can’t perform that action at this time.