【问题标题】:Adding [aliases] fails with error: invalid command 'xyz'添加 [别名] 失败并出现错误:无效命令 'xyz'
【发布时间】:2020-08-31 14:00:48
【问题描述】:

尝试将cov = coverage report --show-missing 等快捷方式添加到 setup.cfg 的[aliases] 部分会导致python setup.py cov 失败并显示error: invalid command 'coverage'需要哪些额外的选项来支持这一点?

版本信息:

$ python -V
Python 3.7.3
$ pip list | egrep 'setuptools|pip|coverage|pytest'
coverage           5.2.1
pip                20.2.2
pytest             5.4.3
pytest-html        2.1.1
pytest-metadata    1.10.0
setuptools         50.0.0

setup.cfg:

[aliases]
test = coverage run -m pytest --html=pytest-report.html --self-contained-html
cov = coverage report --show-missing
covhtml = coverage html --title "Coverage report - xyz"

[tool:pytest]
testpaths = tests

[coverage:run]
branch = True
source = pyapp

[options]
# ...
install_requires =
    Flask==1.1.*
    psycopg2==2.8.*
    requests==2.*
    werkzeug==1.*
    click==7.*
setup_requires =
    pytest-runner
tests_require =
    coverage
    pytest
    pytest-html

【问题讨论】:

    标签: python python-3.x setuptools setup.py


    【解决方案1】:

    setup.cfg aliasessetup.py 创建别名,而不是一般命令。在您的情况下,python setup.py cov 相当于

    python setup.py coverage report --show-missing
    

    并且setup.py 抱怨它没有命令coverage

    【讨论】:

    • 嗯,好的。但我在几篇文章中看到了[aliases] test = pytestpytest 不是正式的子命令,对吧?那么是什么让这个案例奏效了呢?
    • (第二个问题 - 我想替代方案是包装脚本或 shell alias。还有其他特定于 Python 项目的想法吗?)
    • 我在想 Node 在 package.json 中的 scripts 键,它可以让你为几乎任何你想要的 npm 子命令起别名
    • 1.关于 pytest — 我尝试了别名,但它对我不起作用;如果setup.py includes tests_require=['pytest'], 这样python setup.py pytest 可以工作,它可能会工作。
    • edit:在我看来,使用 Makefile 非常适合在这里为项目中的常用命令起别名。
    猜你喜欢
    • 2022-07-03
    • 2021-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-14
    • 2019-02-16
    • 2018-10-05
    • 1970-01-01
    相关资源
    最近更新 更多