1

我有一个我想保持最新的模块,我想知道这是否是一个坏主意:

在 site-packages 目录中有一个模块 (mod1.py),它将另一个模块从其他位置复制到 site-packages 目录,然后从该模块导入 *。

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 *

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

from mod1 import function1

这行得通....但是有更好的方法吗?

更新

这是当前的过程...在源代码控制下有一个具有单个模块的项目:站点包目录 mod1.py 中还有一个正在setup.py 运行的setup.py副本。mod1.py

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

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

4

3 回答 3

2

真的想这样做吗?这意味着您只需提交源代码控制即可非常轻松地将代码滚动到生产应用程序。对于不了解您的设置的人来说,我认为这是一个令人讨厌的副作用。

话虽如此,这似乎是一个很好的解决方案——您可能希望在网络文件调用周围添加一些异常处理,因为这些调用很容易失败。

于 2009-03-10T20:45:11.863 回答
1

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

No install. No copy.

.pth files are described here.

于 2009-03-10T22:49:36.697 回答
0

The original strategy of having other developers copy mod1.py into their site-packages in order to use the module sounds like it's the real problem. Why aren't they just using the same source control are you are?

This auto-copying will make it hard to do rollbacks, especially if other developers copy your strategy. Imagine this same system used for dozens and dozens of files. And then imagine you actually do want to use a version of mod1.py that is not the latest for something.

于 2009-03-11T02:03:18.573 回答