From 7f12732b92bac338d444041847748b6d91ab12e6 Mon Sep 17 00:00:00 2001 From: Andrew Watts Date: Wed, 27 Jan 2016 20:57:03 -0800 Subject: [PATCH] Add 409 status code suport to --skip-existing twine only supported the 400 status code when deciding to skip an upload. However, alternative implementations of pypi, for example [pypiserver](http://github.com/pypiserver/pypiserver), use a 409 status code. --- AUTHORS | 1 + tests/test_upload.py | 13 +++++++++++++ twine/commands/upload.py | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 74456d69..6392a197 100644 --- a/AUTHORS +++ b/AUTHORS @@ -14,3 +14,4 @@ Rodrigue Cloutier Tyrel Souza (https://tyrelsouza.com) Adam Talsma Jens Diemer (http://jensdiemer.de/) +Andrew Watts diff --git a/tests/test_upload.py b/tests/test_upload.py index 596de80d..da723d5c 100644 --- a/tests/test_upload.py +++ b/tests/test_upload.py @@ -101,6 +101,19 @@ def test_skip_existing_skips_files_already_on_PyPI(monkeypatch): package=pkg) is True +def test_skip_existing_skips_files_already_on_pypiserver(monkeypatch): + # pypiserver (https://pypi.python.org/pypi/pypiserver) responds with 409 + response = pretend.stub( + status_code=409, + reason='A file named "twine-1.5.0-py2.py3-none-any.whl" already ' + 'exists for twine-1.5.0.') + + pkg = package.PackageFile.from_filename(WHEEL_FIXTURE, None) + assert upload.skip_upload(response=response, + skip_existing=True, + package=pkg) is True + + def test_skip_upload_respects_skip_existing(monkeypatch): response = pretend.stub( status_code=400, diff --git a/twine/commands/upload.py b/twine/commands/upload.py index f194d8af..dc3a697c 100644 --- a/twine/commands/upload.py +++ b/twine/commands/upload.py @@ -56,7 +56,7 @@ def find_dists(dists): def skip_upload(response, skip_existing, package): filename = package.basefilename msg = 'A file named "{0}" already exists for'.format(filename) - return (response.status_code == 400 and + return (response.status_code in [400, 409] and response.reason.startswith(msg) and skip_existing)