为需要一些初始设置的命令运行包装器
项目描述
一个命令行工具,用于创建可执行文件的包装器
理由
exec-wrappers在您需要单个可执行文件但必须执行某些设置才能运行时非常有用。
如果您使用某种环境隔离方式,如conda、schroot、virtualenv,您可能希望配置GUI应用程序(如IDE)以使用这些环境中可用的可执行文件。
但通常需要创建一个脚本,执行一些设置/激活步骤,然后运行命令,而为每个可执行文件创建这样的脚本是非常繁琐的。
exec-wrappers通过检测可执行文件并为每个文件创建包装器来自动化这一过程。它还提供了一些常见工具的包装器。
此外,由于包装器旨在非交互式使用,因此它们通常比交互式对应物简单得多。
例如,conda包装器比执行激活和运行命令要快得多
常规激活
$ 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
示例
conda
$ create-wrappers -t conda -b ~/miniconda/envs/test/bin -d /tmp/conda_wrappers --conda-env-dir ~/miniconda/envs/test
virtualenv
$ create-wrappers -t virtualenv -b ~/python3-env/bin -d /tmp/virtualenv_wrappers --virtual-env-dir ~/python3-env
schroot
$ 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 是免费和开源软件
问题
如果您遇到任何问题,请 提交问题 并附上详细描述。
项目详情
exec-wrappers-1.1.4.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | d9c0aedec7cf14c4fc5d44deaa48ae35dfa8c5bc8b4a1bb58c4a7387f071fdb0 |
|
MD5 | b8f8a9964de5efbba0bda469cd318f92 |
|
BLAKE2b-256 | fcded2b98c930387c4348017621290048e072fdc19997c387033c789eb437943 |
exec_wrappers-1.1.4-py2.py3-none-any.whl 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | b457265eb858a70946b5d4e47caad5762eb1de0b6e67748bc661f67a4fd6a0fa |
|
MD5 | 55530613aa1e5cf35442847bb77d6801 |
|
BLAKE2b-256 | 7858e23e561a0b2bd7b9e67c2486b553e9150602ec53c0d90fc582bc543880cc |