用于运行通过一个键调用的自定义项目命令套件的工具。

projectke的Python项目详细描述


项目键

projectkey是一个框架,它允许您在 python来自动执行常见的项目任务。

然后可以使用“k”从项目中的任何文件夹运行这些命令 钥匙。

例如:

$ k help
Usage: k command [args]

Yourproject development environment commands.

                runserver - Run django debug web server on port 8000
                    shell - Run django shell.
                  upgrade - pip upgrade on all packages and freeze to requirements afterwards.
                     smtp - Run development smtp server on port 25025.
  striptrailingwhitespace - strip the trailing whitespace from all files in your mercurial repo.
              inspectfile - Inspect file(s) for pylint violations.

Run 'k help [command]' to get more help on a particular command.

三步快速启动

步骤1:按如下方式安装:

$ sudo pip install projectkey

步骤2:在项目的根文件夹中创建一个key.py文件,如下所示:

#!/usr/bin/python"""Yourproject development environment commands."""fromprojectkeyimportcd,run,run_return,runnable,ignore_ctrlcdefrunserver():"""Run django debug web server on port 8080."""print"Running webserver..."# Run simple shell commands, assuming you are in the same directory as your key.py file.run("./venv/bin/python manage.py runserver_plus 8080 --traceback --settings=yourproject.special_settings")@ignore_ctrlc# Projectkey will ignore the user pressing ctrl-C when running this commanddefshell():"""Run django shell."""print"Running shell..."# ...since you want the python shell to decide what to do with Ctrl-C.run("./venv/bin/python manage.py shell --settings=yourproject.special_settings")defupgrade():"""pip upgrade on all packages and freeze to requirements afterwards."""# Copy and paste in whole bash scripts if you like...run("""
        ./venv/bin/pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs ./venv/bin/pip install -U
        ./venv/bin/pip freeze > ./requirements.txt
    """)defsmtp():"""Run development smtp server on port 25025."""print"Running SMTP server..."run("python -m smtpd -n -c DebuggingServer localhost:25025")defstriptrailingwhitespace():"""strip the trailing whitespace from all files in your mercurial repo."""# Get the output of shell commands...repofiles=run_return("hg locate *.py").split('\n')# ...and write simple, short, python scripts to do stuff with it.repofiles.remove('')forfilenameinrepofiles:withopen(filename,'r')asfh:new=[line.rstrip()forlineinfh]withopen(filename,'w')asfh:[fh.write('%s\n'%line)forlineinnew]definspectfile(*filenames):"""Inspect file(s) for pylint violations."""# You can also change to the directory that the k command was run from, if you need that.cd(CWD)run("{0}/venv/bin/pylint --rcfile={0}/pylintrc -r n {1}".format(KEYDIR,' '.join(filenames)))# Add this and you can run the file directly (e.g. python key.py smtp) as well as by running "k smtp".runnable(__name__)

第3步:在项目的任何文件夹中运行“k”命令:

$ k inspectfile onefile.py twofiles.py
[ Runs pylint on those files ]

步骤4:添加更多命令。

功能

  • 使用docstrings自动生成文档。
  • 在任何命令中使用变量keydir或cwd来引用key.py的目录或运行k的目录。
  • 通过命令行将任何参数传递给方法(也可以使用可选参数和可变参数数)。
  • “自动完成”是现成的。
  • 使用快捷命令“Run”直接运行shell命令列表,这样您就可以直接从现有shell脚本复制粘贴。
  • 有选择地忽略CTRL—C(默认情况下,它试图停止和退出)。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何在Java中以反射方式使用泛型参数调用方法?   java分配给另一个变量的变量是否更改(原始变量更改)第二个变量是否更改?   java没有此类元素异常(警告:服务器未提供任何stacktrace信息)   java检查用户是否经过密码验证或与某个提供者进行了验证   java在向“价格”和“数量”列单元格添加数据时更新JTable中的“金额”列单元格   Android Studio找不到java编译器   java“在foo类的公共方法中,哪个变量(实例或本地)起作用?”   java动态Log4j2 LogfilePath   java使用OO编程避免多个嵌套if   java有没有办法在IntelliJ更改跟踪中突出显示未保存或更改的行   Java中两个矩阵相乘的数组   java打印包含阿拉伯字符的字符串会导致问号。如何修复?   java为什么声明整型静态会导致代码中出现错误?   java在使用@Bean Spring注释创建Bean时遇到异常   java是否将JavaCV添加为依赖项,以便在Raspberry PI上运行?   java如何使用trycatch测试注入的mock   java如何在不同的环境(开发、测试、生产)中维护相同的数据表?   java将Char转换为KeyEvent