Skip to content

Commit a5f6d75

Browse files
committed
update: improve clean command to remove all build artifacts
Updated the clean command to remove additional build artifacts: - Added .eggs directory - Added *.egg files - Added __pycache__ directories - Added .pyc files - Added local development virtualenv Also modified CleanCommand to: - Added --dist flag to CleanCommand for dist cleaning - Kept DistCleanCommand as separate command for backward compatibility
1 parent 5e2662b commit a5f6d75

1 file changed

Lines changed: 51 additions & 21 deletions

File tree

‎setup.py‎

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -182,33 +182,63 @@ def stale(dst, src):
182182
## Build Commands ##
183183

184184
class CleanCommand(Command):
185-
description = "wipe out the ./build & ./dist dirs and other setup-generated files"
186-
user_options = []
185+
description = "wipe out generated files and build artifacts"
186+
user_options = [
187+
('dist', None, 'also remove Python.framework and local dependencies'),
188+
]
189+
187190
def initialize_options(self):
188-
pass
191+
self.dist = None
192+
189193
def finalize_options(self):
190194
pass
195+
191196
def run(self):
192-
os.system('rm -rf ./build ./dist')
193-
os.system('rm -rf plotdevice.egg-info MANIFEST.in PKG')
194-
os.system('rm -rf ./tests/_out ./tests/_diff ./details.html')
195-
os.system('rm -f ./_plotdevice.*.so')
196-
os.system('cd deps/extensions/svg && make clean')
197-
os.system('find plotdevice -name .DS_Store -exec rm {} \;')
198-
os.system('find plotdevice -name \*.pyc -exec rm {} \;')
199-
os.system('find plotdevice -name __pycache__ -type d -prune -exec rmdir {} \;')
200-
201-
class DistCleanCommand(Command):
197+
paths = [
198+
'build',
199+
'dist',
200+
'*.egg',
201+
'*.egg-info',
202+
'.eggs',
203+
'MANIFEST.in',
204+
'PKG',
205+
'tests/_out',
206+
'tests/_diff',
207+
'details.html',
208+
'_plotdevice.*.so',
209+
'**/*.pyc',
210+
'**/__pycache__',
211+
'**/.DS_Store',
212+
]
213+
214+
# Add framework paths if --dist flag is used
215+
if self.dist:
216+
paths.extend([
217+
'deps/local',
218+
'deps/frameworks/Python.framework',
219+
'deps/frameworks/relocatable-python',
220+
])
221+
222+
for path_pattern in paths:
223+
for path in glob(path_pattern, recursive=True):
224+
if exists(path):
225+
print('removing %s'%path)
226+
if os.path.isdir(path):
227+
rmtree(path)
228+
else:
229+
os.unlink(path)
230+
231+
# Run make clean in svg extensions dir
232+
if exists('deps/extensions/svg'):
233+
os.system('cd deps/extensions/svg && make clean')
234+
235+
class DistCleanCommand(CleanCommand):
236+
"""Alias for `clean --dist` for backward compatibility"""
202237
description = "delete Python.framework, local pypi dependencies, and all generated files"
203-
user_options = []
238+
204239
def initialize_options(self):
205-
pass
206-
def finalize_options(self):
207-
pass
208-
def run(self):
209-
self.run_command('clean')
210-
os.system('rm -rf ./deps/local')
211-
os.system('rm -rf ./deps/frameworks/*.framework')
240+
super().initialize_options()
241+
self.dist = True # always do a deep clean
212242

213243
class LocalDevCommand(Command):
214244
description = "set up environment to allow for running `python -m plotdevice` within the repo"

0 commit comments

Comments
 (0)