跳转到主要内容

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 (21.9 KB 查看哈希值)

上传时间

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面