How to specify github access token in pyproject.toml with an environment variable, or something similar?
Asked Answered
L

2

13

I want to install a package from my private GitHub repository. Using GitHub access token, I can specify it like this:

[tool.poetry.dependencies]
python = "^3.8"
<package> = {git = "https://<token>@github.com/<user>/<repo>", rev = "0.1.3"}

And it works. But, I don't want to specify my access token in pyproject.toml directly. Is there some other way I can specify it?

Lagomorph answered 19/7, 2021 at 20:24 Comment(3)
Any solution you found??Casualty
Unfortunately I still couldn't find any solution.Raki
I also searched a lot, did not get anything yet. Looks like there's no way to do this.Casualty
E
2

You can use the private repositories configuration (never tried it with github though)

see: https://python-poetry.org/docs/repositories/

If you can configure github to accept basic http authorization then you can run

poetry config http-basic.<private-repo-ref> username password

Note though, that if you cannot configure github for basic auth dont create the repository with the url containing the token, this url is also written to the lock file which you are commiting to git...

Ex answered 30/8, 2021 at 6:13 Comment(2)
This is not working , throwing 403 error, I will have to try another optionFarah
@EspoirMurhabazi I got this working with Poetry 1.6.1. Following the guidelines as indicated above: poetry source add --priority=supplemental foo_pypi <pypi url> poetry config http-basic.foo_pypi <username> <access token> poetry add --source foo_pypi name_of_package_in_foo_pypiHelenhelena
H
1

1. Option: Use an SSH Key

Create a SSH key for your Github repo and add it to poetry (see this answer here)

poetry add git+ssh://[email protected]/account/repo

Afterwards you should be able to simply install your poetry environment.

2. Use the GITHUB_TOKEN environmental variable

You can define the GITHUB_TOKEN environmental variable which is then used by poetry (See Github documentation).

export GITHUB_TOKEN=your_github_token
Humfrey answered 28/2 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.