diff options
-rw-r--r-- | changelog.d/3667.change.rst | 1 | ||||
-rw-r--r-- | setuptools/command/egg_info.py | 6 | ||||
-rw-r--r-- | setuptools/tests/test_egg_info.py | 16 |
3 files changed, 22 insertions, 1 deletions
diff --git a/changelog.d/3667.change.rst b/changelog.d/3667.change.rst new file mode 100644 index 00000000..730a577c --- /dev/null +++ b/changelog.d/3667.change.rst @@ -0,0 +1 @@ +Added a human-readable error description when ``.egg-info`` directory is not writeable -- by :user:`droodev` diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 25888ed8..95c81845 100644 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -295,7 +295,11 @@ class egg_info(InfoCommon, Command): def run(self): self.mkpath(self.egg_info) - os.utime(self.egg_info, None) + try: + os.utime(self.egg_info, None) + except OSError as e: + msg = f"Cannot update time stamp of directory '{self.egg_info}'" + raise distutils.errors.DistutilsFileError(msg) from e for ep in metadata.entry_points(group='egg_info.writers'): writer = ep.load() writer(self, ep.name, os.path.join(self.egg_info, ep.name)) diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index 387773c1..6a2a9893 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -7,6 +7,7 @@ import stat import time from typing import List, Tuple from pathlib import Path +from unittest import mock import pytest from jaraco import path @@ -158,6 +159,21 @@ class TestEggInfo: ] assert sorted(actual) == expected + def test_handling_utime_error(self, tmpdir_cwd, env): + dist = Distribution() + ei = egg_info(dist) + utime_patch = mock.patch('os.utime', side_effect=OSError("TEST")) + mkpath_patch = mock.patch( + 'setuptools.command.egg_info.egg_info.mkpath', return_val=None + ) + + with utime_patch, mkpath_patch: + import distutils.errors + + msg = r"Cannot update time stamp of directory 'None'" + with pytest.raises(distutils.errors.DistutilsFileError, match=msg): + ei.run() + def test_license_is_a_string(self, tmpdir_cwd, env): setup_config = DALS(""" [metadata] |