Skip to content Skip to sidebar Skip to footer

How To Place A Common Code For Different Projects

I've got two python projects in a separate folders. And I also have a common code which I use in both of my projects. What is the best way to organize to them on filesystem to use

Solution 1:

I would check out the distribution utils for python (start here). You can set each project as its own separate package and then install each package on your machine as you would any other python package. In addition, you can symlink the package on your local machine, such that if your projects are co-dependent, any changes in project A can immediately be accessed by code in other projects without having to re-install project A after making changes.

In general keeping things separate makes it easier to manage.

Although, it would be helpful to know what these projects are. Are they all separate libraries or apps you are writing?

Solution 2:

The package_dir option in distutils/setup-tools can insert a package (in your case, common_lib) at a location within the distribution tree that is different from the source tree (https://docs.python.org/2/distutils/setupscript.html#listing-whole-packages).

But as far as I can tell this only works properly when creating a binary distribution (setup.py bdist); I ran into this problem too here: Inconsistent behaviour of bdist vs sdist when distributing a Python package.

Post a Comment for "How To Place A Common Code For Different Projects"