Skip to content

Commit

Permalink
feat: Add configuration to customize handling of dists
Browse files Browse the repository at this point in the history
Relates to #115
  • Loading branch information
relekang committed Aug 5, 2019
1 parent b45703d commit 2af6f41
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
7 changes: 7 additions & 0 deletions docs/configuration.rst
Expand Up @@ -29,3 +29,10 @@ All configuration described here belongs in ``setup.cfg`` in a section:
``commit_message``
Long description to append to the version number. This can be useful to skip
pipelines in your CI tool

``dist_path``
The relative path to the folder for dists configured for setuptools. This allows for
customized setuptools processes. Default dist.

``remove_dist``
Flag for whether the dist folder should be removed after a release. Default: true
2 changes: 2 additions & 0 deletions semantic_release/cli.py
Expand Up @@ -164,6 +164,8 @@ def publish(**kwargs):
password=os.environ.get('PYPI_PASSWORD'),
# We are retrying, so we don't want errors for files that are already on PyPI.
skip_existing=retry,
remove_dist=config.getboolean('semantic_release', 'remove_dist'),
path=config.get('semantic_release', 'dist_path'),
)

if check_token():
Expand Down
2 changes: 2 additions & 0 deletions semantic_release/defaults.cfg
Expand Up @@ -8,3 +8,5 @@ commit_parser=semantic_release.history.angular_parser
upload_to_pypi=true
version_source=commit
commit_message=Automatically generated by python-semantic-release
dist_path=dist
remove_dist=true
14 changes: 9 additions & 5 deletions semantic_release/pypi.py
Expand Up @@ -7,9 +7,11 @@

def upload_to_pypi(
dists: str = 'sdist bdist_wheel',
path: str = 'dist',
username: str = None,
password: str = None,
skip_existing: bool = False
skip_existing: bool = False,
remove_dist: bool = True
):
"""Creates the wheel and uploads to pypi with twine.
Expand All @@ -21,14 +23,16 @@ def upload_to_pypi(
"""
if username is None or password is None or username == "" or password == "":
raise ImproperConfigurationError('Missing credentials for uploading')
run('rm -rf dist')
if remove_dist:
run(f'rm -rf {path}')
run('python setup.py {}'.format(dists))
run(
'twine upload -u {} -p {} {} {}'.format(
'twine upload -u {} -p {} {} {}/*'.format(
username,
password,
'--skip-existing' if skip_existing else '',
'dist/*'
path
)
)
run('rm -rf dist')
if remove_dist:
run(f'rm -rf {path}')
21 changes: 21 additions & 0 deletions tests/test_pypi.py
Expand Up @@ -18,3 +18,24 @@ def test_upload_without_arguments(self, mock_run):
mock.call('rm -rf dist')
]
)

@mock.patch('semantic_release.pypi.run')
def test_upload_without_arguments(self, mock_run):
upload_to_pypi(username='username', password='password', remove_dist=False)
self.assertEqual(
mock_run.call_args_list,
[
mock.call('python setup.py sdist bdist_wheel'),
mock.call('twine upload -u username -p password dist/*'),
]
)

@mock.patch('semantic_release.pypi.run')
def test_upload_with_custom_path(self, mock_run):
upload_to_pypi(path='custom-dist', username='username', password='password')
args = mock_run.call_args_list
self.assertEqual(args[0], mock.call('rm -rf custom-dist'),)
self.assertEqual(args[1], mock.call('python setup.py sdist bdist_wheel'),)
self.assertEqual(args[2], mock.call(
'twine upload -u username -p password custom-dist/*'),)
self.assertEqual(args[3], mock.call('rm -rf custom-dist'))

0 comments on commit 2af6f41

Please sign in to comment.