@@ -147,12 +147,26 @@ class PyPICommands:
147147 # https://github.com/pypa/twine
148148 # I tried using "poetry publish -u $TWINE_USERNAME -p $TWINE_PASSWORD"; the command didn't fail, but nothing was uploaded
149149 # I also tried setting $TWINE_USERNAME and $TWINE_PASSWORD on the environment, but then "twine upload" didn't work for some reason.
150- TWINE_UPLOAD = "twine upload dist/*"
150+ TWINE_UPLOAD = "twine upload {repo} dist/*"
151151
152152 # https://www.npmjs.com/package/conventional-github-releaser
153153 GITHUB_RELEASE = "conventional-github-releaser -p angular -v"
154154
155155
156+ def remove_previous_builds () -> bool :
157+ """Remove previous builds under the /dist directory."""
158+ dist_dir = (Path (os .curdir ) / "dist" ).resolve ()
159+ if not dist_dir .exists ():
160+ return False
161+
162+ click .echo (f"Removing previous builds on { dist_dir } " )
163+ try :
164+ rmtree (str (dist_dir ))
165+ except OSError :
166+ return False
167+ return True
168+
169+
156170@click .group ()
157171def pypi ():
158172 """Commands to publish packages on PyPI."""
@@ -193,12 +207,7 @@ def full(ctx, part, allow_dirty: bool):
193207 shell (PyPICommands .BUMP_VERSION .format (allow_dirty = allow_dirty_option , part = part ))
194208 shell (f"{ PyPICommands .CHANGELOG } -s" )
195209
196- try :
197- dist_dir = (Path (os .curdir ) / "dist" ).resolve ()
198- print (f"Removing previous builds on { dist_dir } " )
199- rmtree (str (dist_dir ))
200- except OSError :
201- pass
210+ remove_previous_builds ()
202211
203212 shell (PyPICommands .BUILD_POETRY )
204213 shell ("ls -l dist" )
@@ -219,7 +228,8 @@ def full(ctx, part, allow_dirty: bool):
219228 "Create the tag but don't push it yet (conventional-github-releaser will do that)" ,
220229 PyPICommands .GIT_TAG .format (new_version ),
221230 ),
222- ("Upload the files to PyPI via Twine" , PyPICommands .TWINE_UPLOAD ),
231+ ("Upload the files to TestPyPI via Twine" , PyPICommands .TWINE_UPLOAD .format (repo = "-r testpypi" )),
232+ ("Upload the files to PyPI via Twine" , PyPICommands .TWINE_UPLOAD .format (repo = "" )),
223233 ("Create a GitHub release" , PyPICommands .GITHUB_RELEASE ),
224234 )
225235 for header , command in commands :
@@ -247,7 +257,7 @@ def extra_poetry():
247257@extra_poetry .command ()
248258def setup_py ():
249259 """Use poetry to generate a setup.py file from pyproject.toml."""
250- rmtree ( "./dist" )
260+ remove_previous_builds ( )
251261 shell ("poetry build" )
252262 shell ("tar -xvzf dist/*.gz --strip-components 1 */setup.py" )
253263 shell ("black setup.py" )
0 commit comments