[BUG] 65.4.0 will not run without USERPROFILE set
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 1
Description
setuptools version
65.4.0+
Python version
3.9.9
OS
Windows
Additional environment information
No response
Description
We have a build environment which strips out all but an allowed list of environment variables. In particular, it removes HOME / USERPROFILE. This causes setup.py to fail under all conditions with setuptools 65.4.0 and up. Here's why:
In versions prior to 65.4.0 setuptools used os.path.expanduser. The docs state: "If the expansion fails or if the path does not begin with a tilde, the path is returned unchanged." With no home directory user_file = os.path.join(os.path.expanduser('~'), user_filename) was left with a ~ in it, but then find_config_files would silently ignore it: files = [str(path) for path in self._gen_paths() if path.is_file()] (because path.is_file would return False).
commit (included in 65.4.0) switched from os.path to pathlib, but pathlib raises an exception Cannot determine home directory rather than returning the unexpanded path.
This would be fine because we already pass in --no-user-cfg, and doing so avoids the exception-raising codepath altogether. However, the Distribution class which raises the exception is actually instantiated twice: once at build time and once during initialization. _install_setup_requires instantiates a MinimalDistribution and doesn't pass through any script_args. The upshot is that even if we use --no-user-cfg the setuptool initialization will still raise the exception if no home directory is found. Because the MinimalDistribution class is defined in a function block it's not even easy to monkeypatch.
One possible fix is if --no-user-cfg is specified in the script args then MinimalDistribution:__init__ could add
filtered['script_args'] = ['--no-user-cfg']
prior to the call to super().__init__(filtered)
Note this affects Posix systems, too, though slightly differently. pathlib gethomedir for Posix can still raise an exception, but only if no username is specifically passed in and pwd.getpwnam(username).pw_dir raises an exception.
Expected behavior
Being able to use setuptools with any environment, including one with no USERPROFILE set, especially if passing explicit flags such as --no-user-cfg.
How to Reproduce
- Install setuptools 65.4.0 or greater
- unset USERPROFILE
- run setup.py
Edit: adding a better reproduce step:
echo from setuptools import setup; setup() > setup.py
set USERPROFILE=
set HOMEDRIVE=
set HOMEPATH=
python setup.py --no-user-cfg bdist_wheel
Output
RuntimeError: Can't determine home directory
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with USERPROFILE, HOMEDRIVE, and HOMEPATH unset, using the setup.py command shown. Read setuptools/init.py around MinimalDistribution and setuptools/_distutils/dist.py around Distribution's home-directory handling, including how script_args are passed. Done means setup.py runs with --no-user-cfg in an environment without a home directory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100