Skip to content

Commit f23eb22

Browse files
committed
Add support for --all.
1 parent cd2d7fa commit f23eb22

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

HISTORY

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changelog
55

66
- Support removal of virtual environment directories.
77
- Support recursive removal of *__pycache__* directories.
8+
- Add support for *--all*.
89

910
* 0.0.2 (17-Nov-2014)
1011

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ few new command line parameters.
7878
``setup.py clean --pycache``
7979
Recursively removes directories named *__pycache__*.
8080

81+
``setup.py clean --all``
82+
Remove all of by-products. This is the same as using ``--dist --egg
83+
--environment --pycache``.
84+
8185
Where can I get this extension from?
8286
------------------------------------
8387
+---------------+-----------------------------------------------------+

setupext/janitor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ def finalize_options(self):
5656
if self.egg_base is None:
5757
self.egg_base = os.curdir
5858

59+
if self.all:
60+
for flag in self.boolean_options:
61+
setattr(self, flag, True)
62+
5963
if self.environment and self.virtualenv_dir is None:
6064
self.virtualenv_dir = os.environ.get('VIRTUAL_ENV', None)
6165

tests.py

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def setUpClass(cls):
8484
def create_directory(cls, dir_name):
8585
return tempfile.mkdtemp(dir=cls.temp_dir, prefix=dir_name)
8686

87+
@staticmethod
88+
def mkdirs(*dirs):
89+
for d in dirs:
90+
os.makedirs(d)
91+
return dirs[:]
92+
8793
def assert_path_does_not_exist(self, *trailing_segments):
8894
full_path = os.path.join(*trailing_segments)
8995
if os.path.exists(full_path):
@@ -228,11 +234,6 @@ def setUp(self):
228234
self.addCleanup(os.chdir, starting_dir)
229235
os.chdir(self.test_root)
230236

231-
def mkdirs(self, *dirs):
232-
for d in dirs:
233-
os.makedirs(d)
234-
return dirs[:]
235-
236237
def test_that_pycache_directories_are_removed(self):
237238
all_dirs = self.mkdirs(
238239
os.path.join(self.test_root, '__pycache__'),
@@ -255,3 +256,50 @@ def test_that_janitor_does_not_fail_when_cache_parent_is_removed(self):
255256
run_setup('clean', '--dist', '--pycache')
256257
for cache_dir in all_dirs:
257258
self.assert_path_does_not_exist(cache_dir)
259+
260+
261+
class RemoveAllTests(DirectoryCleanupMixin, unittest.TestCase):
262+
263+
@classmethod
264+
def setUpClass(cls):
265+
super(RemoveAllTests, cls).setUpClass()
266+
test_root = cls.create_directory('test-root')
267+
starting_dir = os.curdir
268+
saved_env_dir = os.environ.get('VIRTUAL_ENV', None)
269+
270+
def restore():
271+
os.chdir(starting_dir)
272+
os.environ.pop('VIRTUAL_ENV', None)
273+
if saved_env_dir is not None:
274+
os.environ['VIRTUAL_ENV'] = saved_env_dir
275+
276+
os.chdir(test_root)
277+
try:
278+
all_dirs = cls.mkdirs(
279+
'__pycache__',
280+
'dist',
281+
'foo.egg-info',
282+
'env',
283+
)
284+
cls.pycache_dir = all_dirs[0]
285+
cls.dist_dir = all_dirs[1]
286+
cls.egg_dir = all_dirs[2]
287+
cls.env_dir = all_dirs[3]
288+
os.environ['VIRTUAL_ENV'] = cls.env_dir
289+
run_setup('clean', '--all')
290+
restore()
291+
except:
292+
restore()
293+
raise
294+
295+
def test_that_pycache_is_removed(self):
296+
self.assert_path_does_not_exist(self.pycache_dir)
297+
298+
def test_that_distdir_is_removed(self):
299+
self.assert_path_does_not_exist(self.dist_dir)
300+
301+
def test_that_eggdir_is_removed(self):
302+
self.assert_path_does_not_exist(self.egg_dir)
303+
304+
def test_that_envdir_is_removed(self):
305+
self.assert_path_does_not_exist(self.env_dir)

0 commit comments

Comments
 (0)