导入时自动获取文件的最新版本 [英] Automatically fetching latest version of a file on import

查看:33
本文介绍了导入时自动获取文件的最新版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模块想要更新,我想知道这是否是一个坏主意:

I have a module that I want to keep up to date, and I'm wondering if this is a bad idea:

有一个模块(mod1.py)在复制一个的 site-packages 目录与其他模块不同的模块位置到站点包目录,然后导入 * from那个模块.

Have a module (mod1.py) in the site-packages directory that copies a different module from some other location into the site-packages directory, and then imports * from that module.

import shutil
from distutils.sysconfig import get_python_lib
p_source = r'\\SourceSafeServer\mod1_current.py'
p_local = get_python_lib() + r'\mod1_current.py'
shutil.copyfile(p_source, p_local)
from mod1_current import *

现在我可以在任何模块中执行此操作,并且它将始终是最新版本:

Now I can do this in any module, and it will always be the latest version:

from mod1 import function1

这行得通......但是有没有更好的方法来做到这一点?

This works.... but is there a better way of doing this?

更新

这是当前的过程...有一个在源代码控制下的项目,它有一个模块:mod1.py 还有一个 setup.py 正在运行setup.pymod1.py 复制到 site-packages 目录.

Here is the current process... there is a project under source-control that has a single module: mod1.py There is also a setup.py Running setup.py copies mod1.py to the site-packages directory.

使用模块的开发人员必须运行 setup.py 来更新模块.有时,他们没有,没有最新版本会导致问题.

Developers that use the module must run setup.py to update the module. Sometimes, they don't and not having the latest version causes problems.

我希望能够只签入新版本,并且任何导入该模块的代码每次都会自动获取最新版本,而无需任何人运行 setup.py

I want to be able to just check-in the a new version, and any code that imports that module will automatically grab the latest version every time, without anyone having to run setup.py

推荐答案

在某些情况下,我们将 .pth 文件放在 Python 站点包目录中..pth 文件命名了我们的各种 SVN 检出目录.

In some cases, we put .pth files in the Python site-packages directory. The .pth files name our various SVN checkout directories.

无需安装.没有副本.

.pth 文件在here.

这篇关于导入时自动获取文件的最新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆