HitchKey启动器 - 设置开发环境。
项目描述
HitchKey
HitchKey是一个Python任务执行器,用于运行项目任务,如构建代码、运行测试、生成文档、代码审查、重新格式化以及触发部署。
它使用名为key.py的文件执行临时任务,并使用隔离的、自我更新的Python 3虚拟环境。要安装任务使用的包,只需在需求文件中添加它们的名称并运行任务即可。
作为一个任务执行器,它独特之处在于它试图仅作为任务执行器,并提供了一种安装用于构建代码、连接到服务器等工具的手段,而不是尝试自己执行这些操作。
它非常适合团队项目,因为项目可以用来构建一致的开发环境和开发任务,这些任务在不同机器上相对不变。
hitch/key.py
from commandlib import CommandError, Command, python, python_bin
from hitchrun import DIR, expected
# Usable path.py objects -- https://pathpy.readthedocs.io/en/stable/api.html
# DIR.gen -- build directory (~/.hitch/xxxxxx, where the symlink 'gen' links to)
# DIR.project -- the directory containng the "hitch" folder.
# DIR.key -- the directory this file - key.py is in.
# DIR.share -- ~/.hitch/share - build folder shared build artefacts.
# DIR.cur -- the directory "hk" was run in.
# If "expected" is used, no stacktrace will be displayed for that exception
@expected(CommandError)
def hello(argument):
"""
Try running "hk hello world".
"""
# https://pathpy.readthedocs.io/en/stable/api.html
DIR.gen.joinpath("hello.txt").write_text(argument)
# https://hitchdev.pythonlang.cn/commandlib/
Command("cat", "hello.txt").in_dir(DIR.gen).run()
@expected(CommandError)
def runcommand():
"""
Run python 3 code with the hk virtualenv.
"""
python("pythoncode.py").run() # run python code using this project's virtualenv
python_bin.python("pythoncode.py").run() # equivalent
hitch/hitchreqs.in
hitchrun
# add python packages here and they will be installed automagically
$ hk
Usage: hk command [args]
hello - Try running "hk hello world".
runcommand - Run python 3 code with the hk virtualenv.
Run 'hk help [command]' to get more help on a particular command.
hk --upgradepip - Upgrade hitch virtualenv's setuptools and pip
hk --upgrade - Upgrade all dependencies in hitchreqs.in
hk --cleanshare - Delete ~/.hitch/share/ folder.
hk --clean - Delete gen folder
开始使用
首先确保没有激活虚拟环境。
建议您在系统Python环境中安装bootstrap脚本。
sudo pip install hitchkey
此脚本体积小巧,无依赖项,支持Python 2和Python 3,并且只有一个可执行命令:hk。如果您愿意,也可以使用anaconda或pipsi来安装。
hk --demo key
hk helloworld
这将创建一个名为“hitch”的新目录,并将五样东西放入其中。
key.py
- 可以通过“hk命令”运行的函数。gen
- 指向gen文件夹的符号链接(例如~/.hitch/ltnd0x),其中包含hitchkey的Python 3虚拟环境和构建文件夹。hitchreqs.in
- 您想要在此虚拟环境中安装的Python包。hitchreqs.txt
- 所有包的编译和冻结列表(无需手动编辑)。__pycache__
- 包含key.py编译版本的文件夹。
如果您在文本编辑器中打开hitch/key.py并在该目录中运行'hk',您可以看到它的功能。
在使用hitchkey时已经存在key.py
安装后,您只需将cd切换到任何包含key.py文件或hitch/key.py文件的工程目录,然后运行'hk',它将设置环境,安装hitchreqs.txt中指定的所有包。
为什么选择hitchkey而不是make/pyinvoke/rake?
这个项目源于我反复创建的bash脚本,我称之为“dev.sh”,并将其保存在每个项目的根目录中。我会用它来运行各种开发环境工作流程任务,比如重建代码、运行测试或部署。
随着时间的推移,我发现我构建了越来越多复杂的工作流程,使用Python及其生态系统中的包变得更加容易。
项目详情
关闭
hitchkey-0.6.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5b6d18065ed46e69d4691eb0d3a7d238c74aa08281d6aee1590dcf75aca0ed9c |
|
MD5 | f1b511e135bf88d69269bdc89d9f8d49 |
|
BLAKE2b-256 | 60f98572b6862177d03b68123fa0e3ab85a9b0c53c77fdb5ab48330964c3a3f0 |