Skip to content

Commit 8019ad7

Browse files
committed
Merge: Catching excption from utime and providing human-readable error description (#3716)
2 parents ee4d6f1 + 88018bf commit 8019ad7

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

changelog.d/3667.change.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added a human-readable error description when ``.egg-info`` directory is not writeable -- by :user:`droodev`

setuptools/command/egg_info.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ def delete_file(self, filename):
295295

296296
def run(self):
297297
self.mkpath(self.egg_info)
298-
os.utime(self.egg_info, None)
298+
try:
299+
os.utime(self.egg_info, None)
300+
except OSError as e:
301+
msg = f"Cannot update time stamp of directory '{self.egg_info}'"
302+
raise distutils.errors.DistutilsFileError(msg) from e
299303
for ep in metadata.entry_points(group='egg_info.writers'):
300304
writer = ep.load()
301305
writer(self, ep.name, os.path.join(self.egg_info, ep.name))

setuptools/tests/test_egg_info.py

+16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time
88
from typing import List, Tuple
99
from pathlib import Path
10+
from unittest import mock
1011

1112
import pytest
1213
from jaraco import path
@@ -158,6 +159,21 @@ def test_expected_files_produced(self, tmpdir_cwd, env):
158159
]
159160
assert sorted(actual) == expected
160161

162+
def test_handling_utime_error(self, tmpdir_cwd, env):
163+
dist = Distribution()
164+
ei = egg_info(dist)
165+
utime_patch = mock.patch('os.utime', side_effect=OSError("TEST"))
166+
mkpath_patch = mock.patch(
167+
'setuptools.command.egg_info.egg_info.mkpath', return_val=None
168+
)
169+
170+
with utime_patch, mkpath_patch:
171+
import distutils.errors
172+
173+
msg = r"Cannot update time stamp of directory 'None'"
174+
with pytest.raises(distutils.errors.DistutilsFileError, match=msg):
175+
ei.run()
176+
161177
def test_license_is_a_string(self, tmpdir_cwd, env):
162178
setup_config = DALS("""
163179
[metadata]

0 commit comments

Comments
 (0)