42

I want to automate the upload process bug in some cases the python setup.py upload fails because pypi server already have the save version uploaded.

How can I force it to upload, from the script (i know I can remove the old variant using the web interface).

sorin
  • 161,544
  • 178
  • 535
  • 806
  • 1
    I had the same problem but could not find a way to do it with current pypi and setuptools. – Dilawar Jan 29 '14 at 13:02
  • 7
    Especially with the existence of the [test pypi](https://testpypi.python.org/pypi) server, this seems ridiculous. Even if you remove that existing version from the server you can't re-upload that version, saying "this filename has previously been used, you should use a different version. This should at least be possible on the test server. Bad form, pypi. – user1978019 Apr 30 '15 at 06:37
  • 3
    The test server, meant to learn the real thing, should in my opinion behave like the real thing. And any change should force a new version subnumber. Because if you took the trouble to upload an improvement, why not grant the user the privilige to download it? Allowing deleted versions to be overwritten could be a potential source of chaos. Who will tell what is a significant change and what not. – Jacques de Hooge Jun 18 '15 at 11:46
  • I wish I had more than one upvote to give @obsoleteaccount. Even if your change is "just a bug fix," overwriting existing or deleted versions opens the door for someone to upload "just a breaking change." Think of it as another case of "explicit is better than implicit" if that helps. – Foobie Bletch Sep 18 '15 at 14:36
  • `snap` application packages have a revision number along with their version number. I often update my snapstore application with the same version (when I have a extremely small change), and it adds next revision to let the users know a update is published. Disappointed to see PyPI doesn't have something like this. Even manually deleting the version won't help. – Eular Feb 23 '22 at 06:21

2 Answers2

42

A late answer, but: it seems everybody agrees you can't overwrite existing pypi uploads, or re-upload a fixed version after you delete a broken version. However, it seems actually possible and officially supported: "build numbers" are a feature that nobody has ever used or remembers they exist, but that seems to work, at least for me.

The trick is to rename the files in the following pattern:

mypackage-0.31.0-py2.py3-none-any.whl
mypackage-0.31.0-1-py2.py3-none-any.whl
mypackage-0.31.0-2-py2.py3-none-any.whl

The "-1" or "-2" are build numbers. If pip finds all these files for the same release, it will pick the one with the highest build number. It also seems to work if it finds only a single file with a non-zero build number, so you can use that after you deleted the original.

(This is very quickly mentioned in the documentation at https://www.python.org/dev/peps/pep-0427/#file-name-convention but I wouldn't have guessed its use without Daniel Holth pointing it out to me. Thanks Daniel!)

I have no idea why the internet contains so many people convinced it can't be done. I myself only learned about it yesterday and thought I should try to pass on that information.

Insert here the usual warning about not to abuse that feature. A typical example for when I think you should use this is after one of the wheels was badly built and you need to replace it with a correctly-built wheel from the same sources

Armin Rigo
  • 12,048
  • 37
  • 48
  • 4
    When I did this trick, I renamed the `.whl` and `.tar.gz` files as described and it worked but it showed up on pypi with a build number not of `1` but of `post1`. So I renamed to `1.1.0-1` but the version on pypi was `1.1.0.post1`. Other than that this works. – gene_wood Nov 15 '20 at 00:15
  • I tried to use the same trick on the source package, to update the source code in a way that doesn't change any of the wheels. That doesn't work. Looks like there is no solution for that short of rebuilding all the wheels and making a full release. – Armin Rigo Nov 29 '20 at 14:02
  • 2
    This worked nicely. In order to upload the new `tar.gz` archive, you need to remove the old one first. Otherwise, you'll get `400 Only one sdist may be uploaded per release`. – Julian Heinovski Jun 13 '22 at 11:36
  • Unfortunately, it doesn't appear this can be used to update project descriptions. I tried it on the test server and the description is the same even after deleting the original wheel. – ptth222 May 26 '23 at 19:10
8

Here's an actual answer, not just me adding more pontification in the comments. Found this thread:

https://www.reddit.com/r/Python/comments/35xr2q/howto_overwrite_package_when_reupload_to_pypi/

That refers to this:

http://comments.gmane.org/gmane.comp.python.distutils.devel/22739

Saying it can't be done.

Also note the comment in the reddit thread about reading semver.org and incrementing the micro version for patches.

Foobie Bletch
  • 300
  • 2
  • 8