1

Here's the theoretical scenario:

Project_A and Project_B are two independent processes for the client. Both projects rely on a custom module called Module_X.

I have the following folder structure currently :

project_a
project_a/module_x

project_b
project_b/module_x

This functionally works but has the drawback of if I do a change in project_b/module_x I then have to manually copy over the updated contents of module_x to project_a/module_x so that they are congruent and I get consistent results between the two projects.

What is a better way in which I can handle this?

module_x is not able to be put up on pypi as it contains logic for sensitive information resources.

martineau
  • 119,623
  • 25
  • 170
  • 301
Dapper
  • 93
  • 1
  • 8
  • 1
    This question may be too opinion-based to be meaningfully answerable, as it depends highly on your needs for implementation. One strong suggestion, however, is to add it to the path already being checked for imports. See [Where should I put my own python module so that it can be imported](https://stackoverflow.com/questions/16196268/where-should-i-put-my-own-python-module-so-that-it-can-be-imported) – G. Anderson Aug 24 '21 at 20:35
  • 2
    You should *install your local dependency in each project as a requirement*. You can use a `pip` editable install if you want to make changes to `module_x` that would affect it's behavior once installed – juanpa.arrivillaga Aug 24 '21 at 20:37
  • @G.Anderson Okay I think I understand. I remove module_x from the project directories and instead run a pip install pointing to a local directory containing module_x If I understand the theory that means if I change module_x then both projects will have the update as they are referencing the same local directory containing module_x via pip. Am I picking up what you're putting down? – Dapper Aug 24 '21 at 20:44
  • You could add a path configuration file whose name has the form `name.pth` as described in the documentation for the [`site`](https://docs.python.org/3/library/site.html#module-site) module. – martineau Aug 24 '21 at 20:46
  • 1
    @Dapper if you want to be able to edit the code and have that affect things, you need to add the `-e` option to `pip install -e /path/to/module` and you have to do a minimal packaging setup – juanpa.arrivillaga Aug 24 '21 at 21:34

1 Answers1

-1

This will add that path to paths where python searches for modules

import sys
sys.path.insert(1, '/home/user/projectb')
Petr L.
  • 414
  • 5
  • 13