Search code examples
pythonuploadpipsetuptoolspypi

PyPi is adding dashes "-" to the beginning and end of version name


I'm trying to upload my package onto PyPI but it will not work. It looks like PyPi or setuptools is adding - before and after my version name. Originally, I had the following version: ß-2018.8 but I don't think unicode characters work. I then moved it to beta-2018.8 but that didn't work either. I even tried a basic 2018.8 but still the same error?!

Can anyone help me figure out what is happening?

My pip version:

pip 18.0 from /Users/mu/anaconda/envs/py3_clone/lib/python3.6/site-packages/pip (python 3.6)

My command:

python setup.py register sdist upload

My error:

Submitting dist/thisismypackagename--2018.08-.tar.gz to 

https://upload.pypi.org/legacy/
Upload failed (400): '-2018.08-' is an invalid value for Version. Error: Start and end with a letter or numeral containing only ASCII numeric and '.', '_' and '-'. See https://packaging.python.org/specifications/core-metadata
error: Upload failed (400): '-2018.08-' is an invalid value for Version. Error: Start and end with a letter or numeral containing only ASCII numeric and '.', '_' and '-'. See https://packaging.python.org/specifications/core-metadata

My __init__.py:

# =======
# Version
# =======
__version__="beta-2018.08"

My setup.py

import re
from setuptools import setup

# Version
version = None
with open("./thisismypackagename/__init__.py", "r") as f:
    for line in f.readlines():
        line = line.strip()
        if line.startswith("__version__"):
            version = line.split("=")[-1].strip()

setup(name='thisismypackagename',
      version=version,
      description='package description',
      author='Josh L. Espinoza',
      packages=["thisismypackagename"],
      zip_safe=False)

This is my directory structure:

thisismypackagename
    | thisismypackagename
    | thisismypackagename | __init__.py
    | setup.py

Solution

  • It's because the double quotes around the version:

    version = None
    with open("./thisismypackagename/__init__.py", "r") as f:
        for line in f.readlines():
            line = line.strip()
            if line.startswith("__version__"):
                version = line.split("=")[-1].strip()
    print version
    # "beta-2018.08"
    

    And PyPI is substituting double quotes to dashes. Get rid of double quotes and problem solves:

    version = line.split("=")[-1].strip().strip('"')