如何使用python模块的多个git分支? [英] How do I work with multiple git branches of a python module?

查看:80
本文介绍了如何使用python模块的多个git分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用git来允许我在同时编写的模块中处理多个功能.我目前正在使用SVN,只有一个工作区,所以我的PYTHONPATH上只有工作区.我意识到这并不理想,所以我想知道是否有人可以建议一种更合适"的方式来做到这一点.

I want to use git to allow me to work on several features in a module I'm writing concurrently. I'm currently using SVN, with only one workspace, so I just have the workspace on my PYTHONPATH. I'm realizing this is less than ideal, so I was wondering if anyone could suggest a more 'proper' way of doing this.

让我详细说明一个假设情况: 我说我有一个模块鸡蛋",以及子模块"foo"和"bar". "bar"中的组件使用foo中的代码,因此eggs/bar/a.py可能会导入eggs.foo".

Let me elaborate with a hypothetical situation: I say I have a module 'eggs', with sub-modules 'foo' and 'bar'. Components in 'bar' use code in foo, so eggs/bar/a.py may 'import eggs.foo'.

说鸡蛋"在git存储库中.我想尝试对"foo"进行一些更改,因此我将其复制.问题在于,eggs/bar中的"import eggs.foo"在PYTHONPATH中找到了原始存储库,因此最终使用了旧的"foo"而不是我修改过的存储库.

Say that 'eggs' is in a git repository. I want to try out some changes to 'foo', so I copy it. The problem is that 'import eggs.foo' in eggs/bar finds the original repository in the PYTHONPATH, so it ends up using the old 'foo' instead of my modified one.

我如何设置自己,以使模块的每个副本都使用其自身关联的'foo'?谢谢.

How do I set myself up such that each copy of the module uses its own associated 'foo'? Thanks.

edit-感谢您提供指向相对进口的指针.我已经阅读了它,可以看到如何应用它.我使用它的一个问题是我已经建立了一个相当大的代码库,而且我还没有太整洁,因此大多数模块在if __name__ == '__main__':下都具有快速的自检"功能,该功能来自于我读过没有与相对进口:

edit- Thanks for the pointer to relative imports. I've read up on it and I can see how to apply it. One problem I'd have with using it is that I've built up a fairly large codebase, and I haven't been too neat about it so most modules have a quick 'self-test' under if __name__ == '__main__':, which from what I've read does not play with relative imports:

http://www.velocityreviews.com/forums/t502905-relative-import-broken.html

我能够谷歌搜索的另一个解决方案是故意操纵sys.path,这似乎是一个更糟糕的黑客.还有其他可能性吗?

The other solution I've been able to google up is to deliberately manipulate sys.path, which seems like an even worse hack. Are there any other possibilities?

编辑-感谢您的建议.我本来会误解git分支,所以指出分支正是我想要的.尽管如此,我之前从未听说过相对进口产品,因此也要感谢.我学到了一些新东西,可能会结合使用.

edit - Thanks for the suggestions. I'd originally misunderstood git branches, so as pointed out branches are exactly what I want. Nonetheless, I hadn't heard of relative imports before so thanks for that as well. I've learnt something new and may incorporate its use.

推荐答案

也许我的理解不正确,但是git似乎是这里的解决方案,因为git的分支不需要单独的路径.

Maybe I'm not understanding correctly, but it seems that git would be the solution here, since git's branches don't need separate paths.

为您的egg模块的每个工作版本创建一个分支.然后,当您签出该分支时,整个模块将更改为与子模块版本匹配的状态.然后,您可以在分支之间来回合并所需的内容.

Create a branch for each working version of your eggs module. Then when you checkout that branch, the entire module is changed to a state matching the version of your sub-module. You could then merge what you need back and forth between the branches.

正如S.Lott所指出的那样,也许进行一点重构也不会造成伤害;)

And as S.Lott pointed out, may a little refactoring couldn't hurt either ;)

这篇关于如何使用python模块的多个git分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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