Search code examples
pythondependency-managementpython-poetrypyproject.toml

Specify separate sources for different packages in pyproject.toml


My project has various private python packages developed internally in my organization. I am using [tool.poetry.source] to specify the PyPi server. I have a use case to specify custom PyPi server url for different packages. This is the content of my pyproject.toml

[tool.poetry.dependencies]
python = "^3.8"
package-a = "0.1.2"
package-b = "0.2.1"
package-c = "0.4.2"

[[tool.poetry.source]]
name = "internal-repo-1"
url = "https://<private-repo-1>"

[[tool.poetry.source]]
name = "internal-repo-2"
url = "https://<private-repo-2>"

I want to use private-repo-1 from package-a and private-repo-2 for package-b and package-c. How can this be achieved ? Also can this be achieved without scanning all the private repositories for each and every package? I am using poetry for dependency management.


Solution

  • This is described in the docs:

    [tool.poetry.dependencies]
    python = "^3.8"
    package-a = { version = "0.1.2", source = "internal-repo-1" }
    package-b = { version = "0.2.1", source = "internal-repo-2" }
    package-c = { version = "0.4.2", source = "internal-repo-2" }
    
    [[tool.poetry.source]]
    name = "internal-repo-1"
    url = "https://<private-repo-1>"
    
    [[tool.poetry.source]]
    name = "internal-repo-2"
    url = "https://<private-repo-2>"