[Solved] Setuptools-SCM with TestPyPi, Error: HTTPError 400, invalid version PEP 440

Smallest and probably the fastest solution(s) for the problem stated above.

Why is this happening?

Well, because setuptools_scm is smart and looking out for you.
This simple functionality of tweaking the versions of packages when deploying on PyPi or TestPyPi locally results in conflict with PEP 440 leading to the deployment resulting in HTTPError 400 (Client Error). Reason is simple, this is to prevent accidental local deployments from folks when releasing their packages. You must be getting an error similar to this.

HTTPError: 400 Client Error: '0.6.1.dev4+gdf99fe2' is an invalid value for Version. Error: Can't use PEP 440 local versions. See https://packaging.python.org/specifications/core-metadata for url: https://test.pypi.org/legacy/

Well, I wanted to punch through this wall and really wanted to test my package and I am sure many of you would like to play the same. But, do be careful with it. Here you go.

# This your normal setup.py of your normal package with the blessed 
# package that manages your versions for you. 
from setuptools import setup

setup(
    use_scm_version=True,
)

Here’s what would be needed to make it work.

from setuptools import setup

def local_scheme(version):
    return ""

setup(
    use_scm_version={"local_scheme": local_scheme},
)

Pretty simple, what we are trying to do here. We are replacing the local bit of the setuptools_scm version scheme with nothing. Long story short it will be compatible with PEP 440. Have a happy deployment, and as always DON’T PUSH this to PRODUCTION.

Goodie, live in the mix folks.

BONUS

You can also use the dirty scheme if you do like to put test release on the Python Package Index. It will add the tag dirty in your version number. Pretty nifty.

Leave a Reply

Your email address will not be published. Required fields are marked *