I've dealt with this issue using revision control; in my case, Mercurial.
Lets say I have this directory structure:
Projects\python\
general_libs\
.hg
__init__.py
acldict.py
easy_csv.py
easy_tar.py
fake_file.py
list_extract.py
state_machine.py
tag_extract.py
timeout.py
user_agents.py
scraper_libs\
.hg
__init__.py
something_else.py
py_prog\
libs\
I'm writing a program called py_prog
. I wish to use code from the libraries general_libs
and scraper_libs
but I want the method to maintain 'linkage' between the 'copy' and the original location.
In this instance, both general_libs
and scraper_libs
are mercurial repositories.
Mercurial (and git) offer the clone
command. This command clones the source repository to (if not otherwise specified) the current directory. With a cloned repository, you are able to push and pull updates to and from the original repository without needing to recopy or overwrite.
Navigating in a console to Projects\python\py_prog\libs
I run the mercurial commands:
Projects\python\py_prog\libs> hg clone ..\..\general_libs
Projects\python\py_prog\libs> hg clone ..\..\scraper_libs
The directory structure now looks like:
Projects\python\
general_libs\
.hg
__init__.py
acldict.py
easy_csv.py
easy_tar.py
fake_file.py
list_extract.py
state_machine.py
tag_extract.py
timeout.py
user_agents.py
scraper_libs\
.hg
__init__.py
something_else.py
py_prog\
py_prog.py
libs\
general_libs\
.hg
__init__.py
acldict.py
easy_csv.py
easy_tar.py
fake_file.py
list_extract.py
state_machine.py
tag_extract.py
timeout.py
user_agents.py
scraper_libs\
.hg
__init__.py
something_else.py
Now I can import these libraries functions without changing the system path.
py_prog.py:
from libs.scraper_libs.something_else import something
Alternatively, you could achieve a similar outcome (although without the other benefits of revision control) using symlinks (in *nix) or junction points (in Windows).