Skip to content

Commit

Permalink
fix: Use twine through cli call
Browse files Browse the repository at this point in the history
  • Loading branch information
relekang committed Nov 22, 2018
1 parent c04872d commit ab84beb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 41 deletions.
14 changes: 1 addition & 13 deletions semantic_release/pypi.py
@@ -1,31 +1,19 @@
"""PyPI
"""
from invoke import run
from twine import settings
from twine.commands import upload as twine_upload


def upload_to_pypi(
dists: str = 'sdist bdist_wheel',
username: str = None,
password: str = None,
skip_existing: bool = False
):
"""Creates the wheel and uploads to pypi with twine.
:param dists: The dists string passed to setup.py. Default: 'bdist_wheel'
:param username: PyPI account username string
:param password: PyPI account password string
:param skip_existing: Continue uploading files if one already exists. (Only valid when
uploading to PyPI. Other implementations may not support this.)
"""
run('python setup.py {}'.format(dists))
twine_upload.upload(
settings.Settings(
username=username,
password=password,
skip_existing=skip_existing,
),
['dist/*'],
)
run('twine upload -u {} -p {}'.format(username, password))
run('rm -rf build dist')
35 changes: 7 additions & 28 deletions tests/test_pypi.py
Expand Up @@ -7,34 +7,13 @@

class PypiTests(TestCase):
@mock.patch('semantic_release.pypi.run')
@mock.patch('twine.commands.upload.upload')
def test_upload_without_arguments(self, mock_upload, mock_run):
upload_to_pypi()
def test_upload_without_arguments(self, mock_run):
upload_to_pypi(username='username', password='password')
self.assertEqual(
mock_run.call_args_list,
[mock.call('python setup.py sdist bdist_wheel'), mock.call('rm -rf build dist')]
[
mock.call('python setup.py sdist bdist_wheel'),
mock.call('twine upload -u username -p password'),
mock.call('rm -rf build dist')
]
)
mock_upload.assert_called_once_with(
dists=['dist/*'],
sign=False,
identity=None,
username=None,
password=None,
comment=None,
sign_with='gpg',
config_file='~/.pypirc',
skip_existing=False,
cert=None,
client_cert=None,
repository_url=None
)

@mock.patch('semantic_release.pypi.run')
@mock.patch('twine.commands.upload.upload')
def test_upload_with_arguments(self, mock_upload, mock_run):
upload_to_pypi(dists='sdist')
self.assertEqual(
mock_run.call_args_list,
[mock.call('python setup.py sdist'), mock.call('rm -rf build dist')]
)
self.assertTrue(mock_upload.called)

0 comments on commit ab84beb

Please sign in to comment.