Skip to content

[BUG] easy_install doesn't handle sysconfig vars containing multiple space separated paths #4059

@karlicoss

Description

@karlicoss

setuptools version

setuptools==68.2.2

Python version

Python3.11 (via pyenv)

OS

macos

Additional environment information

$ python3 --version
Python 3.11.2
$ python3 -m pip --version
pip 23.2.1 from /Users/karlicos/.pyenv/versions/3.11.2/lib/python3.11/site-packages/pip (python 3.11)

Description

I'm using python3.11 via pyenv (this is the only version of python I have apart from system python3.9).
While I've never encountered this issue before, and it involves pyenv, I debugged a bit and I believe it's a setuptools rather than pyenv issue.

When trying to install any editable package, e.g. python3 -m pip install --user -e /path/to/pkg, somehow it creates an extra directory ending with a space in ~/.pyenv/versions:

$ ls -1 ~/.pyenv/versions/
3.11.2
3.11.2

(hard to see obviously because it ends with space 🙃 )

I think this causes some issues further down the line for pyenv, but it's kinda irrelevant for this bug.
I tried making ~/.pyenv/versions directory read only and running setuptools with debug information:

$ DISTUTILS_DEBUG=true python3 -m pip install --user -e /path/to/pkg
...
        Distribution.get_command_obj(): creating 'egg_info' command object
        os.makedirs('/Users/karlicos/.pyenv/versions/3.11.2 /Users/karlicos/.pyenv/versions/3.11.2/lib /Users/karlicos/.pyenv/versions/3.11.2/lib/python3.11 /Users/karlicos/.pyenv/versions/3.11.2/lib/python3.11/lib-dynload', 0o700)
        error: [Errno 13] Permission denied: '/Users/karlicos/.pyenv/versions/3.11.2 '
...

It seems that this happens here

def create_home_path(self):
"""Create directories under ~."""
if not self.user:
return
home = convert_path(os.path.expanduser("~"))
for path in only_strs(self.config_vars.values()):
if path.startswith(home) and not os.path.isdir(path):
self.debug_print("os.makedirs('%s', 0o700)" % path)
os.makedirs(path, 0o700)

The offending variable turned out to be DESTDIRS, which contained a bunch of paths separated by a space. There is also INCLDIRSTROMAKE in my sysconfig that contains multiple paths

python3 -c 'import sysconfig; print({k: v for k, v in sysconfig.get_config_vars().items() if isinstance(v, str) and v.startswith("/Users/karlicos/") and " " in v})'
{'DESTDIRS': '/Users/karlicos/.pyenv/versions/3.11.2 /Users/karlicos/.pyenv/versions/3.11.2/lib /Users/karlicos/.pyenv/versions/3.11.2/lib/python3.11 /Users/karlicos/.pyenv/versions/3.11.2/lib/python3.11/lib-dynload', 'INCLDIRSTOMAKE': '/Users/karlicos/.pyenv/versions/3.11.2/include /Users/karlicos/.pyenv/versions/3.11.2/include /Users/karlicos/.pyenv/versions/3.11.2/include/python3.11 /Users/karlicos/.pyenv/versions/3.11.2/include/python3.11'}

I'm not sure what exactly the aim of this function, but perhaps it needs to do some extra checks before trying to create dirs. I suppose it's possible that it's a misconfiguration on my side somehow, but I think the variable names suggest they may contain multiple paths.

possibly relevant issue: #3063

Expected behavior

Package is installed as editable, no extra dirs are created

How to Reproduce

Not sure how to provide consistent steps to reproduce since it requires pyenv set up in the first place, and there is no Docker on macos to try it

Output

provided above

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs ReproIssues that need a reproducible example.Needs TriageIssues that need to be evaluated for severity and status.bug

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions