@@ -69,34 +69,36 @@ def help(ctx):
6969 'builds' : 'True to clean up build/packaging artifacts, otherwise False.' })
7070def clean (ctx , docs = True , bytecode = True , builds = True ):
7171 """Cleans the local copy from compiled artifacts."""
72- if builds :
73- ctx .run ('python setup.py clean' )
7472
75- if bytecode :
76- for root , dirs , files in os .walk (BASE_FOLDER ):
77- for f in files :
78- if f .endswith ('.pyc' ):
79- os .remove (os .path .join (root , f ))
80- if '.git' in dirs :
81- dirs .remove ('.git' )
73+ with chdir (BASE_FOLDER ):
74+ if builds :
75+ ctx .run ('python setup.py clean' )
8276
83- folders = []
77+ if bytecode :
78+ for root , dirs , files in os .walk (BASE_FOLDER ):
79+ for f in files :
80+ if f .endswith ('.pyc' ):
81+ os .remove (os .path .join (root , f ))
82+ if '.git' in dirs :
83+ dirs .remove ('.git' )
8484
85- if docs :
86- folders .append ('docs/api/generated' )
85+ folders = []
8786
88- folders .append ('dist/' )
87+ if docs :
88+ folders .append ('docs/api/generated' )
8989
90- if bytecode :
91- for t in ('src' , 'tests' ):
92- folders .extend (glob .glob ('{}/**/__pycache__' .format (t ), recursive = True ))
90+ folders .append ('dist/' )
9391
94- if builds :
95- folders . append ( 'build/' )
96- folders .append ( 'src/compas.egg-info/' )
92+ if bytecode :
93+ for t in ( 'src' , 'tests' ):
94+ folders .extend ( glob . glob ( '{}/**/__pycache__' . format ( t ), recursive = True ) )
9795
98- for folder in folders :
99- rmtree (os .path .join (BASE_FOLDER , folder ), ignore_errors = True )
96+ if builds :
97+ folders .append ('build/' )
98+ folders .append ('src/compas.egg-info/' )
99+
100+ for folder in folders :
101+ rmtree (os .path .join (BASE_FOLDER , folder ), ignore_errors = True )
100102
101103
102104@task (help = {
@@ -105,32 +107,36 @@ def clean(ctx, docs=True, bytecode=True, builds=True):
105107 'check_links' : 'True to check all web links in docs for validity, otherwise False.' })
106108def docs (ctx , doctest = False , rebuild = True , check_links = False ):
107109 """Builds package's HTML documentation."""
110+
108111 if rebuild :
109112 clean (ctx )
110113
111- if doctest :
112- ctx .run ('sphinx-build -E -b doctest docs dist/docs' )
114+ with chdir (BASE_FOLDER ):
115+ if doctest :
116+ ctx .run ('sphinx-build -E -b doctest docs dist/docs' )
113117
114- ctx .run ('sphinx-build -E -b html docs dist/docs' )
118+ ctx .run ('sphinx-build -E -b html docs dist/docs' )
115119
116- if check_links :
117- ctx .run ('sphinx-build -E -b linkcheck docs dist/docs' )
120+ if check_links :
121+ ctx .run ('sphinx-build -E -b linkcheck docs dist/docs' )
118122
119123
120124@task ()
121125def check (ctx ):
122126 """Check the consistency of documentation, coding style and a few other things."""
123- log .write ('Checking MANIFEST.in...' )
124- ctx .run ('check-manifest --ignore-bad-ideas=test.so,fd.so,smoothing.so,drx_c.so' )
125127
126- log .write ('Checking metadata...' )
127- ctx .run ('python setup.py check --strict --metadata' )
128+ with chdir (BASE_FOLDER ):
129+ log .write ('Checking MANIFEST.in...' )
130+ ctx .run ('check-manifest --ignore-bad-ideas=test.so,fd.so,smoothing.so,drx_c.so' )
131+
132+ log .write ('Checking metadata...' )
133+ ctx .run ('python setup.py check --strict --metadata' )
128134
129- # log.write('Running flake8 python linter...')
130- # ctx.run('flake8 src tests setup.py')
135+ # log.write('Running flake8 python linter...')
136+ # ctx.run('flake8 src tests setup.py')
131137
132- # log.write('Checking python imports...')
133- # ctx.run('isort --check-only --diff --recursive src tests setup.py')
138+ # log.write('Checking python imports...')
139+ # ctx.run('isort --check-only --diff --recursive src tests setup.py')
134140
135141
136142@task (help = {
@@ -140,11 +146,29 @@ def test(ctx, checks=False, doctest=False):
140146 if checks :
141147 check (ctx )
142148
143- cmd = ['pytest' ]
144- if doctest :
145- cmd .append ('--doctest-modules' )
149+ with chdir (BASE_FOLDER ):
150+ cmd = ['pytest' ]
151+ if doctest :
152+ cmd .append ('--doctest-modules' )
153+
154+ ctx .run (' ' .join (cmd ))
155+
156+
157+ @task
158+ def prepare_changelog (ctx ):
159+ """Prepare changelog for next release."""
160+ UNRELEASED_CHANGELOG_TEMPLATE = '## Unreleased\n \n ### Added\n \n ### Changed\n \n ### Removed\n \n \n ## '
161+
162+ with chdir (BASE_FOLDER ):
163+ # Preparing changelog for next release
164+ with open ('CHANGELOG.md' , 'r+' ) as changelog :
165+ content = changelog .read ()
166+ changelog .seek (0 )
167+ changelog .write (content .replace (
168+ '## ' , UNRELEASED_CHANGELOG_TEMPLATE , 1 ))
169+
170+ ctx .run ('git add CHANGELOG.md && git commit -m "Prepare changelog for next release"' )
146171
147- ctx .run (' ' .join (cmd ))
148172
149173
150174@task (help = {
@@ -170,7 +194,20 @@ def release(ctx, release_type):
170194
171195 if len (dist_files ):
172196 ctx .run ('twine upload --skip-existing %s' % dist_files )
197+
198+ prepare_changelog (ctx )
173199 else :
174200 raise Exit ('No files found to release' )
175201 else :
176202 raise Exit ('Aborted release' )
203+
204+
205+ @contextlib .contextmanager
206+ def chdir (dirname = None ):
207+ current_dir = os .getcwd ()
208+ try :
209+ if dirname is not None :
210+ os .chdir (dirname )
211+ yield
212+ finally :
213+ os .chdir (current_dir )
0 commit comments