88import invoke
99
1010# shared function
11- def rmrf (dirs , verbose = True ):
12- "Silently remove a list of directories"
13- if isinstance (dirs , str ):
14- dirs = [dirs ]
11+ def rmrf (items , verbose = True ):
12+ "Silently remove a list of directories or files "
13+ if isinstance (items , str ):
14+ items = [items ]
1515
16- for dir_ in dirs :
16+ for item in items :
1717 if verbose :
18- print ("Removing {}" .format (dir_ ))
19- shutil .rmtree (dir_ , ignore_errors = True )
18+ print ("Removing {}" .format (item ))
19+ shutil .rmtree (item , ignore_errors = True )
20+ # rmtree doesn't remove bare files
21+ try :
22+ os .remove (item )
23+ except FileNotFoundError :
24+ pass
2025
2126
2227# create namespaces
@@ -32,14 +37,14 @@ def rmrf(dirs, verbose=True):
3237@invoke .task
3338def pytest (context ):
3439 "Run tests and code coverage using pytest"
35- context .run ("pytest --cov=cmd2 --cov-report=html" )
40+ context .run ("pytest --cov=cmd2 --cov-report=term --cov-report= html" )
3641namespace .add_task (pytest )
3742
3843@invoke .task
3944def pytest_clean (context ):
40- "Remove pytest cache directories"
45+ "Remove pytest cache and code coverage files and directories"
4146 #pylint: disable=unused-argument
42- dirs = ['.pytest-cache' , '.cache' , 'htmlcov' ]
47+ dirs = ['.pytest-cache' , '.cache' , 'htmlcov' , '.coverage' ]
4348 rmrf (dirs )
4449namespace_clean .add_task (pytest_clean , 'pytest' )
4550
@@ -56,17 +61,6 @@ def tox_clean(context):
5661 rmrf ('.tox' )
5762namespace_clean .add_task (tox_clean , 'tox' )
5863
59- @invoke .task
60- def codecov_clean (context ):
61- "Remove code coverage reports"
62- #pylint: disable=unused-argument
63- dirs = set ()
64- for name in os .listdir (os .curdir ):
65- if name .startswith ('.coverage' ):
66- dirs .add (name )
67- rmrf (dirs )
68- namespace_clean .add_task (codecov_clean , 'coverage' )
69-
7064
7165#####
7266#
@@ -158,25 +152,25 @@ def clean_all(context):
158152 pass
159153namespace_clean .add_task (clean_all , 'all' )
160154
161- @invoke .task
155+ @invoke .task ( pre = [ clean_all ])
162156def sdist (context ):
163157 "Create a source distribution"
164158 context .run ('python setup.py sdist' )
165159namespace .add_task (sdist )
166160
167- @invoke .task
161+ @invoke .task ( pre = [ clean_all ])
168162def wheel (context ):
169163 "Build a wheel distribution"
170164 context .run ('python setup.py bdist_wheel' )
171165namespace .add_task (wheel )
172166
173- @invoke .task (pre = [clean_all , sdist , wheel ])
167+ @invoke .task (pre = [sdist , wheel ])
174168def pypi (context ):
175169 "Build and upload a distribution to pypi"
176170 context .run ('twine upload dist/*' )
177171namespace .add_task (pypi )
178172
179- @invoke .task (pre = [clean_all , sdist , wheel ])
173+ @invoke .task (pre = [sdist , wheel ])
180174def pypi_test (context ):
181175 "Build and upload a distribution to https://test.pypi.org"
182176 context .run ('twine upload --repository-url https://test.pypi.org/legacy/ dist/*' )
0 commit comments