@@ -31,14 +31,14 @@ def flush(self):
3131
3232 def write (self , message ):
3333 self .flush ()
34- self .out .write (message + ' \n ' )
34+ self .out .write (message + " \n " )
3535 self .out .flush ()
3636
3737 def info (self , message ):
38- self .write (' [INFO] %s' % message )
38+ self .write (" [INFO] %s" % message )
3939
4040 def warn (self , message ):
41- self .write (' [WARN] %s' % message )
41+ self .write (" [WARN] %s" % message )
4242
4343
4444log = Log ()
@@ -48,64 +48,70 @@ def confirm(question):
4848 while True :
4949 response = input (question ).lower ().strip ()
5050
51- if not response or response in ('n' , 'no' ):
51+ if not response or response in ("n" , "no" ):
5252 return False
5353
54- if response in ('y' , ' yes' ):
54+ if response in ("y" , " yes" ):
5555 return True
5656
57- print (' Focus, kid! It is either (y)es or (n)o' , file = sys .stderr )
57+ print (" Focus, kid! It is either (y)es or (n)o" , file = sys .stderr )
5858
5959
6060@task (default = True )
6161def help (ctx ):
6262 """Lists available tasks and usage."""
63- ctx .run (' invoke --list' )
63+ ctx .run (" invoke --list" )
6464 log .write ('Use "invoke -h <taskname>" to get detailed help for a task.' )
6565
6666
67- @task (help = {
68- 'docs' : 'True to clean up generated documentation, otherwise False' ,
69- 'bytecode' : 'True to clean up compiled python files, otherwise False.' ,
70- 'builds' : 'True to clean up build/packaging artifacts, otherwise False.' })
67+ @task (
68+ help = {
69+ "docs" : "True to clean up generated documentation, otherwise False" ,
70+ "bytecode" : "True to clean up compiled python files, otherwise False." ,
71+ "builds" : "True to clean up build/packaging artifacts, otherwise False." ,
72+ }
73+ )
7174def clean (ctx , docs = True , bytecode = True , builds = True ):
7275 """Cleans the local copy from compiled artifacts."""
7376
7477 with chdir (BASE_FOLDER ):
7578 if builds :
76- ctx .run (' python setup.py clean' )
79+ ctx .run (" python setup.py clean" )
7780
7881 if bytecode :
7982 for root , dirs , files in os .walk (BASE_FOLDER ):
8083 for f in files :
81- if f .endswith (' .pyc' ):
84+ if f .endswith (" .pyc" ):
8285 os .remove (os .path .join (root , f ))
83- if ' .git' in dirs :
84- dirs .remove (' .git' )
86+ if " .git" in dirs :
87+ dirs .remove (" .git" )
8588
8689 folders = []
8790
8891 if docs :
89- folders .append (' docs/api/generated' )
92+ folders .append (" docs/api/generated" )
9093
91- folders .append (' dist/' )
94+ folders .append (" dist/" )
9295
9396 if bytecode :
94- for t in (' src' , ' tests' ):
95- folders .extend (glob .glob (' {}/**/__pycache__' .format (t ), recursive = True ))
97+ for t in (" src" , " tests" ):
98+ folders .extend (glob .glob (" {}/**/__pycache__" .format (t ), recursive = True ))
9699
97100 if builds :
98- folders .append (' build/' )
99- folders .append (' src/compas_occ.egg-info/' )
101+ folders .append (" build/" )
102+ folders .append (" src/compas_occ.egg-info/" )
100103
101104 for folder in folders :
102105 rmtree (os .path .join (BASE_FOLDER , folder ), ignore_errors = True )
103106
104107
105- @task (help = {
106- 'rebuild' : 'True to clean all previously built docs before starting, otherwise False.' ,
107- 'doctest' : 'True to run doctests, otherwise False.' ,
108- 'check_links' : 'True to check all web links in docs for validity, otherwise False.' })
108+ @task (
109+ help = {
110+ "rebuild" : "True to clean all previously built docs before starting, otherwise False." ,
111+ "doctest" : "True to run doctests, otherwise False." ,
112+ "check_links" : "True to check all web links in docs for validity, otherwise False." ,
113+ }
114+ )
109115def docs (ctx , doctest = False , rebuild = False , check_links = False ):
110116 """Builds package's HTML documentation."""
111117
@@ -116,8 +122,8 @@ def docs(ctx, doctest=False, rebuild=False, check_links=False):
116122 if doctest :
117123 testdocs (ctx )
118124
119- opts = '-E' if rebuild else ''
120- ctx .run (' sphinx-build {} -b html docs dist/docs' .format (opts ))
125+ opts = "-E" if rebuild else ""
126+ ctx .run (" sphinx-build {} -b html docs dist/docs" .format (opts ))
121127
122128 if check_links :
123129 linkcheck (ctx , rebuild = rebuild )
@@ -126,23 +132,23 @@ def docs(ctx, doctest=False, rebuild=False, check_links=False):
126132@task ()
127133def lint (ctx ):
128134 """Check the consistency of coding style."""
129- log .write (' Running flake8 python linter...' )
130- ctx .run (' flake8 src' )
135+ log .write (" Running flake8 python linter..." )
136+ ctx .run (" flake8 src" )
131137
132138
133139@task ()
134140def testdocs (ctx ):
135141 """Test the examples in the docstrings."""
136- log .write (' Running doctest...' )
137- ctx .run (' pytest --doctest-modules' )
142+ log .write (" Running doctest..." )
143+ ctx .run (" pytest --doctest-modules" )
138144
139145
140146@task ()
141147def linkcheck (ctx , rebuild = False ):
142148 """Check links in documentation."""
143- log .write (' Running link check...' )
144- opts = '-E' if rebuild else ''
145- ctx .run (' sphinx-build {} -b linkcheck docs dist/docs' .format (opts ))
149+ log .write (" Running link check..." )
150+ opts = "-E" if rebuild else ""
151+ ctx .run (" sphinx-build {} -b linkcheck docs dist/docs" .format (opts ))
146152
147153
148154@task ()
@@ -152,79 +158,102 @@ def check(ctx):
152158 with chdir (BASE_FOLDER ):
153159 lint (ctx )
154160
155- log .write (' Checking MANIFEST.in...' )
156- ctx .run (' check-manifest' )
161+ log .write (" Checking MANIFEST.in..." )
162+ ctx .run (" check-manifest" )
157163
158- log .write (' Checking metadata...' )
159- ctx .run (' python setup.py check --strict --metadata' )
164+ log .write (" Checking metadata..." )
165+ ctx .run (" python setup.py check --strict --metadata" )
160166
161167
162- @task (help = {
163- 'checks' : 'True to run all checks before testing, otherwise False.' })
168+ @task (help = {"checks" : "True to run all checks before testing, otherwise False." })
164169def test (ctx , checks = False , doctest = False ):
165170 """Run all tests."""
166171 if checks :
167172 check (ctx )
168173
169174 with chdir (BASE_FOLDER ):
170- cmd = [' pytest' ]
175+ cmd = [" pytest" ]
171176 if doctest :
172- cmd .append (' --doctest-modules' )
177+ cmd .append (" --doctest-modules" )
173178
174- ctx .run (' ' .join (cmd ))
179+ ctx .run (" " .join (cmd ))
175180
176181
177182@task
178183def prepare_changelog (ctx ):
179184 """Prepare changelog for next release."""
180- UNRELEASED_CHANGELOG_TEMPLATE = '## Unreleased\n \n ### Added\n \n ### Changed\n \n ### Removed\n \n \n ## '
185+ UNRELEASED_CHANGELOG_TEMPLATE = (
186+ "## Unreleased\n \n ### Added\n \n ### Changed\n \n ### Removed\n \n \n ## "
187+ )
181188
182189 with chdir (BASE_FOLDER ):
183190 # Preparing changelog for next release
184- with open (' CHANGELOG.md' , 'r+' ) as changelog :
191+ with open (" CHANGELOG.md" , "r+" ) as changelog :
185192 content = changelog .read ()
186193 changelog .seek (0 )
187- changelog .write (content .replace (
188- '## ' , UNRELEASED_CHANGELOG_TEMPLATE , 1 ))
194+ changelog .write (content .replace ("## " , UNRELEASED_CHANGELOG_TEMPLATE , 1 ))
189195
190- ctx .run ('git add CHANGELOG.md && git commit -m "Prepare changelog for next release"' )
196+ ctx .run (
197+ 'git add CHANGELOG.md && git commit -m "Prepare changelog for next release"'
198+ )
191199
192200
193- @task (help = {
194- 'gh_io_folder' : 'Folder where GH_IO.dll is located. Defaults to the Rhino 6.0 installation folder (platform-specific).' ,
195- 'ironpython' : 'Command for running the IronPython executable. Defaults to `ipy`.' })
201+ @task (
202+ help = {
203+ "gh_io_folder" : "Folder where GH_IO.dll is located. Defaults to the Rhino 6.0 installation folder (platform-specific)." ,
204+ "ironpython" : "Command for running the IronPython executable. Defaults to `ipy`." ,
205+ }
206+ )
196207def build_ghuser_components (ctx , gh_io_folder = None , ironpython = None ):
197208 """Build Grasshopper user objects from source"""
198209 with chdir (BASE_FOLDER ):
199- with tempfile .TemporaryDirectory ('actions.ghcomponentizer' ) as action_dir :
200- target_dir = source_dir = os .path .abspath ('src/compas_ghpython/components' )
201- ctx .run ('git clone https://github.com/compas-dev/compas-actions.ghpython_components.git {}' .format (action_dir ))
210+ with tempfile .TemporaryDirectory ("actions.ghcomponentizer" ) as action_dir :
211+ target_dir = source_dir = os .path .abspath ("src/compas_ghpython/components" )
212+ ctx .run (
213+ "git clone https://github.com/compas-dev/compas-actions.ghpython_components.git {}" .format (
214+ action_dir
215+ )
216+ )
202217
203218 if not gh_io_folder :
204219 import compas_ghpython
205- gh_io_folder = compas_ghpython .get_grasshopper_plugin_path ('6.0' )
220+
221+ gh_io_folder = compas_ghpython .get_grasshopper_plugin_path ("6.0" )
206222
207223 if not ironpython :
208- ironpython = ' ipy'
224+ ironpython = " ipy"
209225
210226 gh_io_folder = os .path .abspath (gh_io_folder )
211- componentizer_script = os .path .join (action_dir , 'componentize.py' )
212-
213- ctx .run ('{} {} {} {} --ghio "{}"' .format (ironpython , componentizer_script , source_dir , target_dir , gh_io_folder ))
214-
215-
216- @task (help = {
217- 'release_type' : 'Type of release follows semver rules. Must be one of: major, minor, patch.' })
227+ componentizer_script = os .path .join (action_dir , "componentize.py" )
228+
229+ ctx .run (
230+ '{} {} {} {} --ghio "{}"' .format (
231+ ironpython ,
232+ componentizer_script ,
233+ source_dir ,
234+ target_dir ,
235+ gh_io_folder ,
236+ )
237+ )
238+
239+
240+ @task (
241+ help = {
242+ "release_type" : "Type of release follows semver rules. Must be one of: major, minor, patch."
243+ }
244+ )
218245def release (ctx , release_type ):
219246 """Releases the project in one swift command!"""
220- if release_type not in ('patch' , 'minor' , 'major' ):
221- raise Exit ('The release type parameter is invalid.\n Must be one of: major, minor, patch.' )
247+ if release_type not in ("patch" , "minor" , "major" ):
248+ raise Exit (
249+ "The release type parameter is invalid.\n Must be one of: major, minor, patch."
250+ )
222251
223252 # Run checks
224- ctx .run (' invoke check test' )
253+ ctx .run (" invoke check test" )
225254
226255 # Bump version and git tag it
227- ctx .run (' bump2version %s --verbose' % release_type )
256+ ctx .run (" bump2version %s --verbose" % release_type )
228257
229258 # Prepare the change log for the next release
230259 prepare_changelog (ctx )
0 commit comments