Reputation: 73
We have multiple projects using common python code.
File Structure:
Parent_folder
--Project_folder
--Project_A
--(source code)
--Project_B
--(source code)
--Common_folder
--Common_library_A
--__init__.py
--(source code)
--Common_library_B
--__init__.py
--(source code)
For Project_A to import Common_library_A I can use:
path = os.path.join(dirname(abspath(__file__)),"\\..\\..\\Common_folder\\")
sys.path.append(path)
import common_library_A
or I can look for 'parent_folder' on the current working directory, and use that as a base path to add common_folder to, which I then add to the sys path.
We can't use a fixed path, as different branches will need to use the version of the code in their branch.
Is there a 'cleaner' way of doing this?
Upvotes: 1
Views: 88
Reputation: 14863
I think it is ok. If you encounter problems you can change it.
Usually the common_folder is called site-packages. common_library_A and common_library_B would be installed separately into the site-packages folder.
But if you work in a version-control-system and everything in Parent_folder should be of the same version, then site-packages is no solution.
Upvotes: 1