Python package "click" causes "Error: Got unexpected extra arguments (sdist bdist_wheel)" when used in new package
Python package "click" causes "Error: Got unexpected extra arguments (sdist bdist_wheel)" when used in new package
我正在尝试创建一个可以用作终端命令的 Python 包。我的 setup.py 文件看起来像
import setuptools
# If the package is being updated (and not installed for the first time),
# save user-defined data.
try:
import checklist
update = True
except ModuleNotFoundError:
update = False
if update:
import os
import pickle
dir = os.path.join(os.path.dirname(checklist.__file__), 'user_settings')
files = {}
for file in os.listdir(dir):
files[file] = pickle.load(open(os.path.join(dir, file), "rb"))
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="SampleName",
version="0.2.0",
author="Author1, Author2",
author_email="email@email.com",
description="words words words.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/samplesample/sample1",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
],
entry_points='''
[console_scripts]
checklist=checklist.checklist:cli
''',
python_requires='>=3.7',
package_data={"checklist":["user_settings/*.pkl"]},
include_package_data=True,
)
if update:
for key in files:
pickle.dump(files[key], open(os.path.join(dir, key), "wb"))
当我尝试使用命令
创建 checklist
包时
python setup.py sdist bdist_wheel
我收到消息
Error: Got unexpected extra arguments (sdist bdist_wheel)
当我从我的环境中删除 click
时,轮子的创建没有问题。这看起来很奇怪,因为我的代码使用 click
.
import os
import sys
import csv
import click
import datetime as dt
from datetime import datetime
from contextlib import suppress
import pickle
class UI:
def __init__(self):
<set variables>...
<some methods>...
# noinspection SpellCheckingInspection
class Checklist(UI):
def __init__(self):
<set variables>...
# start the process...
while self.step_index < len(self.to_do):
with suppress(ExitException):
self.step()
def step(self):
self.__getattribute__(self.to_do[self.step_index])()
self.step_index += 1
self.overwrite = False
<some methods>...
@click.command()
def cli():
Checklist()
cli()
这可能是什么原因造成的?我该如何解决?
令人惊讶的是,与最佳实践的一些小偏差如何链接在一起产生一个大问题。 :-)
click
的问题如下。如果安装了 click
,您的 setup.py
将导入您在上面向我们展示的模块。并且模块 在导入时 运行s cli()
,表示 cli()
调用 @click.command()
并解析命令行(用于 setup.py
,不适用于 click
) 并产生错误。
如果未安装 click
,您的 setup.py
会尝试导入 checklist
,但失败 ModuleNotFoundError
。在 setup.py
中捕获并忽略了异常并继续安装。
为了解决这个问题,使 checklist
成为一个既可以是 运行(调用 cli()
)又可以在不调用 cli()
的情况下导入的模块:
def main():
cli()
if __name__ == '__main__':
main()
我正在尝试创建一个可以用作终端命令的 Python 包。我的 setup.py 文件看起来像
import setuptools
# If the package is being updated (and not installed for the first time),
# save user-defined data.
try:
import checklist
update = True
except ModuleNotFoundError:
update = False
if update:
import os
import pickle
dir = os.path.join(os.path.dirname(checklist.__file__), 'user_settings')
files = {}
for file in os.listdir(dir):
files[file] = pickle.load(open(os.path.join(dir, file), "rb"))
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="SampleName",
version="0.2.0",
author="Author1, Author2",
author_email="email@email.com",
description="words words words.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/samplesample/sample1",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
],
entry_points='''
[console_scripts]
checklist=checklist.checklist:cli
''',
python_requires='>=3.7',
package_data={"checklist":["user_settings/*.pkl"]},
include_package_data=True,
)
if update:
for key in files:
pickle.dump(files[key], open(os.path.join(dir, key), "wb"))
当我尝试使用命令
创建checklist
包时
python setup.py sdist bdist_wheel
我收到消息
Error: Got unexpected extra arguments (sdist bdist_wheel)
当我从我的环境中删除 click
时,轮子的创建没有问题。这看起来很奇怪,因为我的代码使用 click
.
import os
import sys
import csv
import click
import datetime as dt
from datetime import datetime
from contextlib import suppress
import pickle
class UI:
def __init__(self):
<set variables>...
<some methods>...
# noinspection SpellCheckingInspection
class Checklist(UI):
def __init__(self):
<set variables>...
# start the process...
while self.step_index < len(self.to_do):
with suppress(ExitException):
self.step()
def step(self):
self.__getattribute__(self.to_do[self.step_index])()
self.step_index += 1
self.overwrite = False
<some methods>...
@click.command()
def cli():
Checklist()
cli()
这可能是什么原因造成的?我该如何解决?
令人惊讶的是,与最佳实践的一些小偏差如何链接在一起产生一个大问题。 :-)
click
的问题如下。如果安装了 click
,您的 setup.py
将导入您在上面向我们展示的模块。并且模块 在导入时 运行s cli()
,表示 cli()
调用 @click.command()
并解析命令行(用于 setup.py
,不适用于 click
) 并产生错误。
如果未安装 click
,您的 setup.py
会尝试导入 checklist
,但失败 ModuleNotFoundError
。在 setup.py
中捕获并忽略了异常并继续安装。
为了解决这个问题,使 checklist
成为一个既可以是 运行(调用 cli()
)又可以在不调用 cli()
的情况下导入的模块:
def main():
cli()
if __name__ == '__main__':
main()