首页 > 解决方案 > Install Python package from monorepo

问题描述

We have a private git monorepo which hosts a number of Python packages. Poetry was the dependency management tool initially chosen for the project. Anyway, due to this Poetry issue, it would not be accepted solution that involves creating new setup.py files.

A simplified version of the structure:

git-monorepo
├── pkg-1
│   ├── pkg
│   │   └── mod1.py
│   └── pyproject.toml
├── pkg-2
│   ├── pkg
│   │   └── mod2.py
│   └── pyproject.toml
└── lib
    ├── pkg
    │   └── lib.py
    └── pyproject.toml

The library distribution package lib is indepentent from any other package. However, pkg-1 depends on lib and pkg-2 depends on both pkg-1 and lib.

So, the question is:

How would be the proper way to use pip to install a package from this monorepo?

Let us consider as an example that we try to install pkg-1, where pkg-1/pyproject.toml includes the following lines:

...

[tool.poetry.dependencies]
lib = {path = "../lib/"}

...

The result from running pip, as explained in the VCS support documentation:

$ pip install -e git+https://gitlab.com/my-account/git-monorepo#"egg=pkg-1&subdirectory=pkg-1"

Traceback (most recent call last):
  File "/home/hblanco/.local/lib/python3.8/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3101, in __init__
    super(Requirement, self).__init__(requirement_string)
  File "/home/hblanco/.local/lib/python3.8/site-packages/pip/_vendor/packaging/requirements.py", line 115, in __init__
    raise InvalidRequirement("Invalid URL: {0}".format(req.url))
pip._vendor.packaging.requirements.InvalidRequirement: Invalid URL: ../lib

标签: pythongitpipmonorepopython-poetry

解决方案


推荐阅读