项目的简单任务自动化。
pepython的Python项目详细描述
佩皮森
需要帮助组织项目的任务吗?打电话给佩皮森!
安装
pip install pepython
快速启动
在根目录的tasks.py
文件中定义任务。请注意,依赖关系只是任务本身主体中的方法调用。这允许通过/转发和更灵活的模式,而不仅仅是前/后依赖项。
frompepython.task_defimporttask,s@taskdefclean(*args):s("rm -rf build dist *.egg-info")@taskdefbuild(*args):clean()s("pipenv run python setup.py sdist bdist_wheel")@taskdefpublish(*args):s("pipenv run twine upload dist/*",interactive=True)@taskdefbuild_and_publish(*args):build()publish()
那就叫佩皮森来!
$ pepython --help
Usage:
pepython [--defs-path path-to-your-tasks-definitions.py] task [task params ...]
$ pepython clean
Executed task 'clean' successfuly.
$ pepython build_and_publish
Enter your username: your-name-here
Enter your password: ************
Uploading distributions to https://test.pypi.org/legacy/
Uploading pepython-0.1.0-py2-none-any.whl
100%|█████████████████████████████████████████████████████| 7.77k/7.77k [00:00<00:00, 42.6kB/s]
Uploading pepython-0.1.0.tar.gz
100%|█████████████████████████████████████████████████████| 5.65k/5.65k [00:01<00:00, 4.74kB/s]
Executed task 'build_and_publish' successfuly.
如果您需要task参数,它们是自然定义的:
@taskdeftask_args(first_arg,second_arg,*rest_of_args):print("You've passed {} and {} as the 2 first parms, then passed:\n{}.".format(first_arg,second_arg,rest_of_args))
$ pepython task_args a b c d e
You've passed a and b as the 2 first parms, then passed:
('c', 'd', 'e').
Executed task 'task_args' successfuly.
主要的思想是使用Python进行任务自动化,所有的灵活性,但不会失去外壳。这就是为什么有s()
(缩写为shell)。除了上面显示的interactive
参数(请参见输出中的密码提示),它还有其他一些可能性:
交互进程很容易通过管道传递给用户:
@taskdefchange_pass():s("passwd",interactive=True)
$ pepython change_pass
Changing password for nando.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Executed task 'change_pass' successfuly.
而其他非交互进程则可以由任务管理:
@taskdefprocess_python_files():ls_result=s("ls *py",fail_fast=False,verbose=True)ifnotls_result.ok:exit("No python files here")python_files_raw=ls_result.value['out'].split("\n")python_files=[f.strip()forfinpython_files_rawiff.strip()]print("These are the python files in this directory:\n{}".format(python_files))
$ pepython process_python_files
Executed shell command 'ls *py'
exit code was: 0
stdout was:
setup.py
tasks.py
stderr was:
These are the python files in this directory:
[u'setup.py', u'tasks.py']
Executed task 'shell_returned_values' successfuly.
开发
确保您有最新的pip
和pipenv
版本:
pip install --update pip pipenv
要开始开发,请通过以下方式启动环境:
pipenv shell pipenv install -d
这个工具使用^{
若要添加application依赖项,请将其添加到setup.py
中,并保留宽松的版本定义。然后,只需pipenv install -e .
来安装依赖项。pipenv锁定机制将按预期工作,因为pepython本身位于Pipfile
的[packages]
部分(检查Pipfile.lock
,您将在那里找到dep)。
要添加development依赖项,请通过pipenv install -d <my-dependency>
将其添加到Pipfile
。
这样,包定义就只有一个真实的来源。无需在setup.py
和Pipfile*
中重复deps。
许可证
这个项目是在麻省理工学院的许可下授权的-请参阅^{