运行需要一些初始设置的命令的包装器
exec-wrappers的Python项目详细描述
在可执行文件周围创建包装器的命令行工具
基本原理
exec-wrappers在需要单个可执行文件时非常有用,但必须进行一些设置 在执行之前。
如果使用诸如conda、schroot之类的环境隔离进行开发, virtualenv您可能想配置一个像ide这样的gui应用程序来使用可执行文件 在这些环境中可用。
但通常必须创建一个脚本来执行一些设置/激活步骤,然后运行命令 但是为每个可执行文件创建这样的脚本是很乏味的。
exec-wrappers在检测可执行文件并为每个文件创建一个包装器时,有助于实现自动化。 其中之一。它还为常用工具提供了一些包装器。
另外,由于包装器是非交互使用的,它们通常比 互动的对手。
例如,conda包装器比执行activate和命令要快得多:
- 常规激活:
$ echo'source activate test 2> /dev/null; "$@"' > /tmp/activate-and-run && chmod a+x /tmp/activate-and-run $ time /tmp/activate-and-run python --version Python 2.7.11 :: Continuum Analytics, Inc. real 0m0.354s user 0m0.288s sys 0m0.040s
- 使用由exec-wrappers: 创建的python包装器
$ time /tmp/conda_wrappers/python --version Python 2.7.11 :: Continuum Analytics, Inc. real 0m0.003s user 0m0.000s sys 0m0.000s
如果您以非交互方式执行命令,那么低开销非常重要。
功能
- 自动检测给定目录中的可执行文件
- 用普通shell和批处理脚本编写的包装器
- 低开销(尽可能低)
- 常用工具的内置包装器
要求
python是创建包装器的唯一依赖项。 要正确使用生成的包装器,需要包装器使用的工具(conda、schroot等)。
安装
$ python setup.py install
工作原理
创建conda包装器:
$ create-wrappers -t conda --bin-dir ~/miniconda/envs/test/bin --dest-dir /tmp/conda_wrappers --conda-env-dir ~/miniconda/envs/test
这将在/tmp/conda_wrappers中为中找到的每个可执行文件创建一个包装 ~/miniconda/envs/test/bin。 因此,如果运行python包装器:
$ /tmp/conda_wrappers/python -c "import sys; print(sys.executable)"
/home/username/miniconda/envs/test/bin/python
它实际上会激活conda环境并设置必要的变量,然后执行 真正的python解释器。例如,您可以使用包装器来配置IDE。
还将创建一个run-in脚本,您可以使用它运行任意命令:
$ /tmp/conda_wrappers/run-in bash -c 'echo $CONDA_DEFAULT_ENV'
/home/username/miniconda/envs/test
示例
- 条件:
$ create-wrappers -t conda -b ~/miniconda/envs/test/bin -d /tmp/conda_wrappers --conda-env-dir ~/miniconda/envs/test
- 虚拟机:
$ create-wrappers -t virtualenv -b ~/python3-env/bin -d /tmp/virtualenv_wrappers --virtual-env-dir ~/python3-env
- 施罗特:
$ create-wrappers -t schroot -b ~/chroots/centos5/bin -d /tmp/schroot_wrappers --schroot-name centos5
$ create-wrappers -t schroot -b ~/chroots/centos5/bin -d /tmp/schroot_wrappers --schroot-name centos5 --schroot-options="-p -d /"
- 自定义:
$ echo -e '#!/bin/sh\necho "$@"' > /tmp/custom-script && chmod a+x /tmp/custom-script $ create-wrappers -t custom --custom-script=/tmp/custom-script -b /usr/bin -d /tmp/custom_wrappers
- 仅包装指定的文件:
$ create-wrappers -t schroot -f gcc:gdb -d /tmp/schroot_wrappers --schroot-name centos5
- 链式多包装纸:
$ create-wrappers -t conda -b ~/miniconda/envs/test/bin -d /tmp/conda_wrappers --conda-env-dir ~/miniconda/envs/test $ create-wrappers -t schroot -b /tmp/conda_wrappers -d /tmp/schroot_wrappers --schroot-name centos5
许可证
根据MIT许可证的条款分发,exec-wrappers是免费的开源软件
问题
如果您遇到任何问题,请file an issue连同详细说明。