我为依赖python 3.6的私有库安装程序创建了setup.py。我试图使该文件对以前尝试在python版本上安装的用户更加友好,并意识到我的想法存在重大缺陷。
我在setup.py中使用f-strings,而仅在> = 3.6 中起作用!
任何试图运行setup.py的人都不会进入检查解释器版本的第一行代码。因此,这让我想到了创建setup.py文件的准则以及可能存在的其他语法限制,这些限制会阻止setup.py在多个环境中正常运行。
#!/usr/bin/env python3
"""
PIP Install script for XXXXXX packages
"""
import sys
if sys.version_info < (3,6):
sys.exit('Sorry, Python < 3.6 is not supported')
from setuptools import setup
NAME = 'abcutil'
AUTHOR = 'XXXXXXXXXX'
CLASSIFIERS = """\
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
Programming Language :: Python
Programming Language :: Python :: 3
Topic :: Software Development
Operating System :: Microsoft :: Windows
Operating System :: Unix
Operating System :: MacOS
"""
MAJOR = 1
MINOR = 1
MICRO = 0
ISRELEASED = False
VERSION = f'{MAJOR}.{MINOR}.{MICRO}'
setup(name = NAME,
maintainer = AUTHOR,
version=VERSION,
maintainer_email = 'XXXXXXX',
description='XXXXXXX utility packages',
author = AUTHOR,
download_url = 'https://gitlabXXXXXXXX/XXXXXXX',
license = 'BSD',
classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
python_requires=">=3.6",
packages=[NAME, f"{NAME}.selenium", f"{NAME}.regression_helpers"],
install_requires = ['selenium==3.9', 'requests>=2.18.4', 'python-dateutil', 'pytz'],
dependency_links=['']
)
运行以上操作将为您提供:
$ python setup.py
File "setup.py", line 30
VERSION = f'{MAJOR}.{MINOR}.{MICRO}'
^
SyntaxError: invalid syntax
我的问题实际上有两个方面: