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

Open
webknjaz opened this Issue Aug 27, 2017 · 6 comments

Comments

Projects
None yet
8 participants
@webknjaz
Contributor

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:

@FlorianWilhelm FlorianWilhelm referenced this issue Oct 14, 2017

Merged

Drop pbr #125

@jensens

This comment has been minimized.

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

This comment has been minimized.

Member

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

This comment has been minimized.

Member

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

improve encoding handling for `setup.cfg`
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

improve encoding handling for `setup.cfg`
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

This comment has been minimized.

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

This comment has been minimized.

uchuugaka commented Feb 11, 2018

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

@Midnighter

This comment has been minimized.

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

Convert dict values to string for Python 2 support
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

Switch from setup.py to setup.cfg
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

📦(core) add project packaging
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

📦(core) add project packaging
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment