Skip to content

Commit 7b17c15

Browse files
authored
handle failures to find a user home directory
In certain environments (notably, the [bazel sandbox](https://bazel.build/docs/sandboxing) on windows), it is possible for `pathlib.Path('~').expanduser()` to fail to find the user home directory and [raise a `RuntimeError`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.expanduser). This causes `distutils` (and ultimately, `setuptools`) to fail. With this patch, we catch and handle the exception by logging a warning and continuing without a user's config file. motivated by bazel-contrib/rules_python#1067
1 parent 8993718 commit 7b17c15

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

distutils/dist.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,12 @@ def _gen_paths(self):
354354
prefix = '.' * (os.name == 'posix')
355355
filename = prefix + 'pydistutils.cfg'
356356
if self.want_user_cfg:
357-
yield pathlib.Path('~').expanduser() / filename
357+
try:
358+
user_home = pathlib.Path('~').expanduser()
359+
except RuntimeError:
360+
self.announce("Failed to locate user home directory. Skipping user config.", logging.WARNING)
361+
else:
362+
yield user_home / filename
358363

359364
# All platforms support local setup.cfg
360365
yield pathlib.Path('setup.cfg')

0 commit comments

Comments
 (0)