如何让 VirtualEnv 使用自定义版本的 setuptools?

发布于 2024-11-06 17:31:31 字数 605 浏览 4 评论 0原文

我工作的大公司使用自定义版本的Setuptools。这个 setuptools 的私有分支旨在解决我们组织特有的某些网络和安全困难。最重要的是,标准安装工具和分发工具都无法在我们的环境中按预期工作。

我想开始在系统上使用 Ian Bicking 出色的 VirtualEnv 工具,特别是在我们的测试系统中,我们需要能够为测试代码设置大量沙盒区域 - 例如在我们的持续集成环境中。

不幸的是,每当我尝试构建新的虚拟环境时,virtualenv 工具都会尝试获取并安装最新的官方版本的Setuptools。由于上述原因,这会失败,而且还因为公司防火墙会阻止该操作。

我不想安装官方版本:

setuptools-0.6c11-py2.4.egg

我想安装我们的自定义版本,它可能被称为:

setuptools-foo-0.6c11-py2.4.egg

这个鸡蛋总是可以保证在系统的全局站点包中找到。我还可以保证它存在于我们所有的公司鸡蛋服务器中。

你能帮我让我的 virtualenv 使用我定制的 setuptools 而不是常规版本的 setuptools 吗?

The large corporation that I work for uses a custom version of Setuptools. This private fork of setuptools is intended to deal with certain networking and security difficulties that are unique to our organization. The bottom line is that neither the standard Setuptools nor Distribute would work as expected on our environment.

Id like to start using Ian Bicking's excellent VirtualEnv tool on systems, particularly in our test systems where we need to be able to set up a large number of sandboxed areas for test-code - e.g. in our continuous integration environment.

Unfortunately any time I try to build a new virtual environment the virtualenv tool tries to obtain and install the latest official version of Setuptools. This would fail for the reason stated above, and also because the corporate firewall would block the action.

Instead of installing the official version:

setuptools-0.6c11-py2.4.egg

I'd like to install our customized version which might be called something like:

setuptools-foo-0.6c11-py2.4.egg

This egg can always be guaranteed to be found in the system's global site-packages. I can also guarantee that it's present in all of our corporate egg servers.

Can you help me make my virtualenv use my customized setuptools instead of the regular version of setuptools.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

゛时过境迁 2024-11-13 17:31:31

该名称硬编码在 virtualenv.py 中。您必须修补 virtualenv.py 或将修补后的 setuptools Egg 命名为“setuptools-0.6c11-py2.4.egg”

The name is hardcoded in virtualenv.py. You have to either patch virtualenv.py or name your patched setuptools egg 'setuptools-0.6c11-py2.4.egg'

书间行客 2024-11-13 17:31:31

我开始编写自己的包装脚本来导入 virtualenv。主要原因是我使用 dpkgs 来安装大部分依赖项,包括 distribute,因此我希望在创建新环境时避免下载额外的副本 - 这样做的好处是运行速度更快。

这是您可以用来开始的基线包装器。我添加了一条注释,您可以在其中插入一些代码来符号链接/将自定义 setuptools 代码复制到 virtualenv 中:

import os, subprocess, sys, virtualenv

# virtualenv changed its internal api slightly after 1.5. 
NEW_API = (1, 5)

def get_version(version):
    return tuple([int(v) for v in version.split('.')])

def main():
    # set the logging level here
    level = virtualenv.Logger.level_for_integer(0)
    logger = virtualenv.Logger([(level, sys.stdout)])
    virtualenv.logger = logger

    # insert your command-line parsing code here, if needed
    root = sys.argv[1]

    home, lib, inc, bin = virtualenv.path_locations(root)
    result = virtualenv.install_python(home, lib, inc, bin,
            site_packages=True, clear=False)
    pyexec = os.path.abspath(result)
    version = get_version(virtualenv.virtualenv_version)
    if version < NEW_API:
        virtualenv.install_distutils(lib, home)
    else:
        virtualenv.install_distutils(home)
    virtualenv.install_activate(home, bin)

    # insert whatever post-virtualenv-setup code you need here 

if __name__ == '__main__':
    main()

用法:

% python wrapper.py [path]

I've taken to writing my own wrapper scripts which import virtualenv. The main reason is that I use dpkgs to install most of my dependencies, including distribute, so I like to avoid downloading additional copies when I create a new environment - this has a bonus that it runs much faster.

Here is a baseline wrapper you can use to start with. I've added a comment where you could insert some code to symlink/copy your custom setuptools code into the virtualenv:

import os, subprocess, sys, virtualenv

# virtualenv changed its internal api slightly after 1.5. 
NEW_API = (1, 5)

def get_version(version):
    return tuple([int(v) for v in version.split('.')])

def main():
    # set the logging level here
    level = virtualenv.Logger.level_for_integer(0)
    logger = virtualenv.Logger([(level, sys.stdout)])
    virtualenv.logger = logger

    # insert your command-line parsing code here, if needed
    root = sys.argv[1]

    home, lib, inc, bin = virtualenv.path_locations(root)
    result = virtualenv.install_python(home, lib, inc, bin,
            site_packages=True, clear=False)
    pyexec = os.path.abspath(result)
    version = get_version(virtualenv.virtualenv_version)
    if version < NEW_API:
        virtualenv.install_distutils(lib, home)
    else:
        virtualenv.install_distutils(home)
    virtualenv.install_activate(home, bin)

    # insert whatever post-virtualenv-setup code you need here 

if __name__ == '__main__':
    main()

Usage:

% python wrapper.py [path]
沧笙踏歌 2024-11-13 17:31:31

选项 --extra-search-dir 允许定义包含所需版本的 setuptools 的本地目录。 文档对此进行了解释。

There's the option --extra-search-dir that allows to define a local directory containing the desired version of setuptools. This is explained in the docs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文