Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python pip - development mode with local dependencies

Background

I have two python projects. Project A and Project B.

Each project has its own virtual environment and its own setup.py.

Both projects are not pure py files and has "build" process like building extensions, generate source etc.

A is dependent on B (setup.py install_requires points on B).

Each project is built and published/distributed as a wheel to pypi on-premise repository.

pip install w/wo -e (development mode) of project A, nicely installs project B into project A venv site-packages.

So far everything is working nicely and "by the book".

Now, my story get complicated ...

I would like to develop the two projects together without having to publish B in order A to consume it.

As example, I would like to:

  1. Change something in B.
  2. build B (setup.py build).
  3. NOT publish B as wheel to pypi.
  4. Goal - Project A will "know" the modified Project B. WITHOUT manually tweaking sys.path.

I actually want the pip install -e of project A to install project B in development mode too.

After some reading I understood (hopefully correctly) that one can define a "distribution" as a local source folder by --find-links flag.

I defined project B root folder in --find-links.

I tried it with (on project A setup.py folder):

  1. pip install . -e --find-links = file:///path/to/B

  2. pip install . -e --find-links = git+file://path/to/B

Both did not work.

BTW, Puting in the path to B wheel or egg of B,

ex: pip install . -e --find-links = file:///path/to/B.whl

did work but this is not what I am looking for.

Hope you are still with me :-) (sorry for the tedious story)

What am I missing?

Tx

like image 452
Lior Cohen Avatar asked Jun 20 '18 22:06

Lior Cohen


People also ask

How does PIP work with dependencies?

It needs to work out the dependencies of the requested packages, the dependencies of those dependencies, and so on. Over the course of the dependency resolution process, pip will need to download distribution files of the packages which are used to get the dependencies of a package.

What happens when you run Pip as a module in Python?

When you run pip as a module, Python loads the module in memory and allows the package to be removed while it is being used. You can run packages as if they were scripts if the package provides a top-level script __main__.py.

How to use PIP to install a specific version of Python?

You can change the logical operator to >= to tell pip to install an exact or greater version that has been published. When you set a new environment using the requirments.txt file, pip looks for the latest version that satisfies the requirement and installs it.

How to enable development mode in Python?

The Python Development Mode can only be enabled at the Python startup. Its value can be read from sys.flags.dev_mode. Changed in version 3.8: The io.IOBase destructor now logs close () exceptions.


1 Answers

Let me try and restate the problem:

  • You work on two python packages, package A and package B. A depends on B.
  • You have chosen to develop these two packages in separate virtual environments.
  • You would like to make some local changes to package B and have package A use the modified version of package B.

I apologize if I'm missing something here, but why not simply install both packages in the same virtual environment, which will make this problem go away?

I.e. after creating your environment, you install package B in editable mode, followed by installing package A. Any changes in B will be picked up by A, no changes needed.

like image 179
leopold.talirz Avatar answered Oct 16 '22 07:10

leopold.talirz