PyPi 在版本名称的开头和结尾添加破折号“-”

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

我正在尝试将我的包上传到 PyPI,但它不起作用。看起来 PyPisetuptools 在我的版本名称前后添加了 -。最初,我有以下版本:ß-2018.8 但我认为 unicode 字符不起作用。然后我将其移至 beta-2018.8 但这也不起作用。我什至尝试了基本的 2018.8 但仍然是同样的错误?!

谁能帮我弄清楚发生了什么事?

我的 pip 版本:

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

我的命令:

python setup.py register sdist upload

我的错误:

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

我的__init__.py:

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

我的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)

这是我的目录结构:

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

这是因为版本周围的双引号:

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"

并且 PyPI 将双引号替换为破折号。去掉双引号,问题解决:

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