Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I work with multiple git branches of a python module?
    text
    copied!<p>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.</p> <p>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'. </p> <p>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. </p> <p>How do I set myself up such that each copy of the module uses its own associated 'foo'? Thanks.</p> <p>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 <code>if __name__ == '__main__':</code>, which from what I've read does not play with relative imports: </p> <ul> <li><p><a href="http://mail.python.org/pipermail/python-list/2006-October/408945.html" rel="nofollow noreferrer">http://mail.python.org/pipermail/python-list/2006-October/408945.html</a></p></li> <li><p><a href="http://www.velocityreviews.com/forums/t502905-relative-import-broken.html" rel="nofollow noreferrer">http://www.velocityreviews.com/forums/t502905-relative-import-broken.html</a></p></li> </ul> <p>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?</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload