虚拟机管理系统有哪些?vm虚拟机管理系统( 三 )


tox -av能显示出定义在tox.ini中所有的任务:
$ tox -av
default environments:
default -> Invoke pytest to run automated tests

additional environments:
build -> Build the package in isolation according to PEP517, see https://github.com/pypa/build
clean -> Remove old distribution files and temporary build artifacts (./build and ./dist)
docs -> Invoke sphinx-build to build the docs
doctests -> Invoke sphinx-build to run doctests
linkcheck -> Check for broken links in the documentation
publish -> Publish the package you have been developing to a package index server. By default, it uses testpypi. If you really want to publish your package to be publicly accessible in PyPI, use the `-- --repository pypi` option.

要执行哪个命令便用tox -e build,tox -e docs等, 下面是如何使用 PyScaffold 的动图:https://yanbin.blog/wp-content/uploads/2021/09/pyscaffold-demo.gif
在我体验 tox 命令过程中,每一步好像都比较慢,应该是创建虚拟机要花些时间 。tox 使用教程
PyBuilder最好再看另一个构建工具 PyBuilder,它所创建出的目录结构很接近于 Maven, 下面来瞧瞧
$pip install pybuilder
$mkdir sample && cd sample # 项目目录需手工创建
$pyb --start-project # 回答一些问题后创建所需的目录和文件

完后看下它的目录结构:
【虚拟机管理系统有哪些?vm虚拟机管理系统】$ tree sample
.
├── build.py
├── docs
├── pyproject.toml
├── setup.py
└── src
├── main
│ ├── python
│ └── scripts
└── unittest
└── python

构建过程仍然是用pyb命令,可用pyb -h查看帮助,pyb -t列出所有的任务, PyBuilder 的任务是以插件的方式加入的,插件配置在build.py文件中 。
$ pyb -t sample
Tasks found for project "sample":
*** yze - Execute*** ysis plugins.
depends on tasks: prepare run_unit_tests
clean - Cleans the generated output.
compile_sources - Compiles source files that need compilation.
depends on tasks: prepare
coverage - <no description available>
depends on tasks: verify
install - Installs the published project.
depends on tasks: package publish(optional)
package - Packages the application. Package a python application.
depends on tasks: compile_sources run_unit_tests(optional)
prepare - Prepares the project for building. Creates target VEnvs
print_module_path - Print the module path.
print_scripts_path - Print the script path.
publish - Publishes the project.
depends on tasks: package verify(optional) coverage(optional)
run_integration_tests - Runs integration tests on the packaged application.
depends on tasks: package
run_unit_tests - Runs all unit tests. Runs unit tests based on Python's unittest module
depends on tasks: compile_sources
upload - Upload a project to PyPi.
verify - Verifies the project and possibly integration tests.
depends on tasks: run_integration_tests(optional)
$ pyb run_unit_tests sample

PyBuilder 也是在构建或测试之前创建虚拟环境, 从 0.12.9 版开始可通过参数--no-venvs跳过创建虚拟环境这一步 。使用了--no-venvs的话 Python 代码将会在运行pyb的当前 Python 环境中执行,所需的依赖将要手工安装 。
项目的依赖也要定义在build.py文件中
@init
def set_properties(project):
project.depends_on('boto3', '>=1.18.52')
project.build_depends_on('mock')

随后在执行pyb创建虚拟环境时就会安装上面的依赖,并在其中运行测试与构建 。
Poetry最后一个 Poetry, 感觉这是一个更为成熟,项目活跃度也更高的 Python 构建,它有着更强大的信赖管理功能,用

推荐阅读