方便的与virtualenv的shell接口

virtualenv-sh的Python项目详细描述


这个项目是我个人的virtualenvwrapper(一组shell函数 方便使用virtualenv)。 像很多人一样,我用了很多年的virtualenvwrapper,但是它变得有点重了 随着时间的推移。我终于发现自己等了太久才有新的炮弹发射 尽管我倾向于只使用基本功能。

这个项目是为了解决这个问题。我借了些聪明的东西 放弃我认为昂贵或不昂贵的东西 很有意思,还增加了一两个我自己的特色。第一优先权 这个项目是速度。代码几乎是纯shell脚本,尽管 可以是对grep或sed等标准工具的一次或两次调用。

请注意,此实现可能不适合您。我可能已经摆脱了 你喜欢的一个功能,不是因为它很贵,就是因为我 不在乎。我可能不小心放弃了修复或解决方法 因为一些我没遇到的环境。我可能刚刚介绍过 新的bug(shell是一种容易以微妙的方式出错的语言)。继续 你自己的风险。

安装

virtualenv sh可以与pip或easy_一起安装。要使用它,你需要 在shell环境中生成一个shell脚本。默认情况下,pip或 easy_install应该将其安装到/usr/local/bin。如果你使用bash或zsh, 您应该导入特定于shell的脚本;否则,可以尝试 普通的。在shell的init脚本(.bashrc, .zshrc等):

. /usr/local/bin/virtualenv-sh.bash
. /usr/local/bin/virtualenv-sh.zsh
. /usr/local/bin/virtualenv-sh.sh

不需要其他东西。只有一个环境变量可以 用于配置,即在家工作。这是你收藏的路径 ,您可以将其留空以接受 ${HOME}/.virtualenvs。假设virtualenv本身在 路径。

WORKON_HOME=${HOME}/.virtualenvs

zsh

如果使用zsh,则可以使用 最佳性能,尽管这需要从 机器。您可以直接下载源代码或尝试:

> pip install --upgrade --no-install virtualenv-sh
> cd build/virtualenv-sh
> sudo make install

这将在您的路径中找到zsh,使用它编译virtualenv-sh.zwc,然后 安装到/usr/local/bin。现在可以自动加载这些函数并 初始化virtualenv-sh。您可能需要参考函数部分 如果您不熟悉此过程,请在zsh手册中自动加载:

# Configure all virtualenv-sh functions for autoloading
fpath=(/usr/local/bin/virtualenv-sh $fpath)
autoload -w /usr/local/bin/virtualenv-sh

# Call the main initialization function
virtualenv_sh_init

使用

virtualenv sh的基本命令与 虚拟说唱歌手。这里有一个简短的概述:

^{tt3}$

Creates a new virtual_env in ^{tt4}$. All arguments are passed directly to ^{tt2}$. The new virtual_env will become active. Unlike virtualenvwrapper, this takes no additional arguments.

rmvirtualenv <env_name>

Deletes an existing virtual_env. If this virtual_env is currently active, it is deactivated first as a courtesy.

workon [<env_name>]

Activates the named virtual_env. If another virtual_env is currently active, it will be deactivated first. Without arguments, it will list the available virtual_envs. In compatible shells, you can choose a virtual_env from a menu.

autoworkon

Automatically sets the virtual_env based on special files. See below.

deactivate

Deactivates the current virtual_env (as when using ^{tt2}$ directly).

lsvirtualenvs

Prints a list of the virtual_envs you’ve created.

cdvirtualenv [subdir]

Changes the current directory to the root of the active virtual_env, or a subdirectory thereof.

lssitepackages

Lists the contents of the active virtual_env’s site-packages directory.

cdsitepackages [subdir]

Changes the currect directory to the site-packages directory of the active virtual_env, or a subdirectory thereof.

挂钩

virtualenv sh支持与 虚拟说唱歌手。全局钩子是$workn_home中的文件;本地钩子是 $workun_home/{virtual_env}/bin中的文件。钩子是通过采购来实现的 在当前shell上下文中。

initialize (global)

Called at the end of virtualenv_sh_init.

premkvirtualenv、postkvirtualv、prermvirtualenv、postkvirtualenv(全局)

Called at the beginning and end of mkvirtualenv and rmvirtualenv.

预激活、后激活(全局、本地);预激活、后停用(本地、全局)

Called in the order indicated around activation and deactivation of a virtual_env.

此外,virtualenv sh允许您动态注册 执行挂钩时调用:

virtualenv_sh_add_hook <hook_name> <function_name>
virtualenv_sh_remove_hook <hook_name> <function_name>

例如:

my_virtualenv_cleanup()
{
    # Do some stuff here
}

virtualenv_sh_add_hook postdeactivate my_virtualenv_cleanup

注册的钩子函数总是在所有全局和本地钩子之后执行 剧本。

自动训练

autoworkn是一个新命令,旨在自动更新 基于当前目录的虚拟环境。注意没有标准 当当前目录更改时运行函数的shell机制–和 许多shell都没有这样的机制,所以安装它取决于您。如果 你在用好吧,你可以用:

autoload -U add-zsh-hook
add-zsh-hook chpwd autoworkon

autoworkn函数将从当前目录中遍历文件系统 直到它到达根目录或找到一个名为“.wung”的项。如果这是 一个可读的文件,它将把第一行作为虚拟环境的名称 启动它。有一些特殊规则需要记住:

  • autoworkon always stops at the first .workon it finds. It’s perfectly reasonable to have .workon files at multiple points in a directory tree to use different virtual_envs at different levels.
  • An empty or unreadable .workon file is interpreted as “no virtual_env”. This is useful if you want to deactivate the automatic virtual_env in a particular subtree.
  • If you activate a virtual_env manually, autoworkon will never override it. autoworkon will only change your active virtual_env if it is unset or was previously set by autoworkon.

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

推荐PyPI第三方库


热门话题
ApachePOI如何通过java从excel文件中删除空白列?   linux到后台Java服务应用程序的简单发送/接收接口   java ActionBarPullToRefresh什么都没发生   java从millis获取错误的整数天   java相同的代码在两个不同的包上表现不同   java将每个新的char元素写入一个文件(如果被覆盖)   mysql如何在Java中通过外键链接的多个表中插入数据   java环境下mysql网络文件访问   java当使用构建器模式时,为什么我不应该重用builderobject来访问对象配置?   java jQueryServlet post异常失败   java应该使用什么逻辑来创建像《愤怒的小鸟》中那样的锁屏   java Android:在不滑动的情况下更改ViewPager中的片段   java在使用我的程序逻辑时获得空输出