轻松跟踪代码库中使用的代码段
snipt的Python项目详细描述
尖刻的
snipty是一个方便的“像包管理器”工具,可以帮助您跟踪代码库中的代码片段。
偷笑背后的动机是 片段再次干燥。有很多好的代码太小了,无法独立成为合法的包 最后一次又一次地复制到你的代码库。snipty想:
- 自动从远程代码片段网站下载代码片段,
- 管理一个
snipty.yml
文件以显式枚举代码中的代码段依赖项, - 允许在代码库和/或代码段源中进行代码段更改时轻松跟踪这些更改。
你可以在中篇文章中读到how Snipty was born and what problem it tries to address。
快速启动
代码段安装
我们假设您将代码片段存储在代码片段网站的某个位置(如github gist或ghostbin)。 要在代码库中安装代码段,请转到代码库根目录并键入:
$ snipty install helpers/example_1.py https://ghostbin.com/paste/egbue
✔️ Snippet helpers/example_1 installed from https://ghostbin.com/paste/egbue
$ ls helpers
__init__.py example_1.py
snipty检测到这是python片段(通过给定的扩展)
并自动在项目根路径之前的所有子目录上创建__init__.py
,
因此,您的代码片段将从python中导入。
此时,在代码库中创建了一个特殊的文件snipty.yml
。你应该在你的
代码版本控制系统。
包含多个文件的片段
一些代码片段站点(如gist)允许您在单个url下定义多个文件。snipty通过创建 一个目录(而不是单个文件),并将所有代码段文件放置在此目录中。
安装包含多个文件的代码段:
$ snipty install helpers/django https://gist.github.com/cypreess/6670a99b2c1cd7b52b24057f68a1debd
✔️ Snippet helpers/django installed from https://gist.github.com/cypreess/6670a99b2c1cd7b52b24057f68a1debd
$ ls helpers/django
__init__.py left_pad.py middleware.py
删除和移动片段
安装代码段后,无法将其再次安装到其他位置,因为snipty会警告您 可能的代码重复。
$ snipty install snippets/a https://gist.github.com/cypreess/bc7b4d7c46b9a4cf1411c87b5c65d3d5
✔️ Snippet snippets/a installed from https://gist.github.com/cypreess/bc7b4d7c46b9a4cf1411c87b5c65d3d5
$ snipty install snippets/a https://gist.github.com/cypreess/bc7b4d7c46b9a4cf1411c87b5c65d3d5
Snippet 'snippets/a' has been already installed.
片段维护
要检查代码库中的代码段是否与远程链接不同,请键入:
$ snipty check
✔ Snippet snippets/left_pad present and up to date.
或单个包裹:
$ snipty check snippets/left_pad
✔ Snippet snippets/left_pad present and up to date.
通过添加参数--diff
:
snipty check --diff snippets/left_pad
❌ Snippet snippets/left_pad file left_pad.py is not present.
❌ Snippet snippets/left_pad file middleware.py has changed.
class EmptyMiddleware:
+ middleware_empty = True
- pass
如果所有代码段不变,检查将产生0的退出状态,否则退出状态将等于
已更改代码段计数。有用的环境变量:
SNIPTY_PYTHON
-snipty应该用来运行自己的python解释器SNIPTY_ROOT_PATH
-默认的snipty行为是根据当前目录处理所有相对路径; 可以使用此路径或-p
/--path
参数来验证它SNIPTY_TMP
-ovveride下载片段的临时目录
需要帮助
拉式请求非常受欢迎。
- 需要更多的下载程序
- 需要测试!
- 所需文档