Skip to content

Commit 2e9c8bb

Browse files
committed
setup.py: Don't forcibly remove the old build dir. Perform a finer-grained check (issue #108)
This reverts patch 984ae98 ("Force removal of the old build-dir in setup.py") and checks for the build dir for consistency instead.
1 parent 6d4e517 commit 2e9c8bb

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

setup.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
from __future__ import absolute_import
3+
from __future__ import absolute_import, print_function
44

55
import os
66
import os.path
@@ -120,14 +120,43 @@
120120
# user's Py3 installation if they run "python2 setup.py
121121
# build" and then "python3 setup.py install".
122122

123-
import distutils.dir_util
124-
print('removing old build dir')
125123
try:
126-
distutils.dir_util.remove_tree('build')
124+
# If the user happens to run:
125+
# python2 setup.py build
126+
# python3 setup.py install
127+
# then folders like "configparser" will be in build/lib.
128+
# If so, we CANNOT let the user install this, because
129+
# this may break his/her Python 3 install, depending on the folder order in
130+
# sys.path. (Running "import configparser" etc. may pick up our Py2
131+
# substitute packages, instead of the intended system stdlib modules.)
132+
SYSTEM_MODULES = set([
133+
'_dummy_thread',
134+
'_markupbase',
135+
'_thread',
136+
'builtins',
137+
'configparser',
138+
'copyreg',
139+
'html',
140+
'http',
141+
'queue',
142+
'reprlib',
143+
'socketserver',
144+
'tkinter',
145+
'winreg',
146+
'xmlrpc'
147+
])
148+
149+
if sys.version_info[0] >= 3:
150+
# Do any of the above folders exist in build/lib?
151+
files = os.listdir(os.path.join('build', 'lib'))
152+
if len(set(files) & set(SYSTEM_MODULES)) > 0:
153+
print('ERROR: Your build folder is in an inconsistent state for '
154+
'a Python 3.x install. Please remove it manually and run '
155+
'setup.py again.', file=sys.stderr)
156+
sys.exit(1)
127157
except OSError:
128158
pass
129159

130-
131160
setup(name=NAME,
132161
version=VERSION,
133162
author=AUTHOR,

0 commit comments

Comments
 (0)