用于将monkeypatches应用于python可执行文件的工具。

pymonke的Python项目详细描述


Build StatusCoverage Status

猴子

用于将monkeypatches应用于python可执行文件的工具。

安装

pip install pymonkey

注册修补程序

制作模块:

## mymod/pymonkey.py# Be sure to not import anything at the module scope# This ensures that import-hook patching will work better later# This is your chance to do argument parsing before running the target# executable.# This will be called after all of the patch hooks have been registered.defpymonkey_argparse(argv):# You'll be passed the arguments as a tuple.  Parse your specific arguments# and return your parsed state and the remaining arguments.# If you wish to forgo argparsing, simply `return None, argv`importargparseparser=argparse.ArgumentParser()parser.add_argument('--foo')returnparser.parse_known_args(argv)# This is your entry point.  It will be passed module objects after they have# been imported.  Check the module name and then apply your patch (if# applicable).# This will be called as a post-import hook so you'll have a chance to modify# the module before another module would import from it.# The parsed state computed above will be passed as `args`defpymonkey_patch(mod,args):# This callback will be called with *every* module that gets imported# Guard against the specific module you'd like to patchifmod.__name__!='module_to_patch':return# Apply your patches here to module_to_patchmod.foo=args.foo

并将入口点添加到setup.py:

setup(...,entry_points={'pymonkey':['mymod = mymod.pymonkey:pymonkey_patch'],'pymonkey.argparse':['mymod = mymod.pymonkey:pymonkey_argparse'],},...)

命令行用法

应用单个修补程序:

$ pymonkey mymod -- pip install simplejson

应用所有可用的修补程序:

$ pymonkey --all -- pip install simplejson

查看帮助

$ pymonkey --help

使用pymonkey设置入口点

在模块中:

## mymod_main.pyfrompymonkeyimportmake_entry_point# The first argument is a list of pymonkey patches to apply# The second argument is the entry point to runmain=make_entry_point(('mymod',),'pip')if__name__=='__main__':exit(main())

在setup.py中

setup(...,entry_points={'console_scripts':['pip-patched = mymod_main:main'],'pymonkey':['mymod = mymod.pymonkey:pymonkey_patch'],'pymonkey.argparse':['mymod = mymod.pymonkey:pymonkey_argparse'],},...)

然后,而不是

$ pymonkey mymod -- pip ...

现在您可以执行

$ pip-patched ...

使用pymonkey的东西

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

推荐PyPI第三方库


热门话题
来自Oozie Java Jobs的电子邮件   泛型Java映射。具有有界通配符的getOrDefault   java如何制作定制的Swing容器?   java断言使用正则表达式重新启动响应体   安卓 java正则表达式查找字符串中的所有空格   java循环语法不起作用   使用spring4@Transactional时,java事务不起作用   java三桨乒乓球命中检测   java Camera 2 Api错误不拍照的错误   java使用ServletContext从war外部读取Hibernate属性   性能如何禁用Java垃圾回收器?   如何通过MySQL触发器执行外部java函数?   使用Ecfbittorent下载torrent时出现java NegativeArraySizeException   java Android arraylist因迭代而崩溃   MyBatis中的java Delete查询没有删除任何内容