Search code examples
gitlabpython-poetrypyproject.toml

How to add dependency in pyproject.toml from gitlab private package registry


I am using poetry for dependency and packaging of my project.

One of my python package maintained in gitlab package registry . And the pip installation command goes straight forward

pip install <my_package> --index-url https://__token__:<your_personal_token>@gitlab.com/api/v4/projects/<project_id>/packages/pypi/simple

But I am unable to add this to my pyproject.toml dependency from gitlab package registry

This command works for me

[tool.poetry.dependencies]
<my_package> = {git = "https://<token_name>:<>@gitlab.com/lululemon/global-tech-services/retail-engineering-department/dsp/dsp-logging.git"}

But its not getting installed from package registry rather directly from the codebase .


Solution

  • I am able to fix it by adding poetry source. Below are the commands to add a package dependency from gitlab package registry

    poetry source add --secondary foo https://gitlab.com/api/v4/projects/<project_id>/packages/pypi/simple
    poetry config http-basic.foo <token_key> <token_value>
    poetry add <package> --source=foo