OpenDataAlex
OpenDataAlex

Reputation: 1475

PyCharm poetry.lock failing due to private aws codeartifact repository

I've set up my project in PyCharm to use poetry and have a private repository in AWS CodeArtifact that I need to reference. Manually I got that working and the install/lock process works fine via terminal. However, if I use the built in poetry integration, it throws an error because it can't access the token I set like in the terminal.

What is the best way to handle this? I've tried setting the env variables in my profile (on Ubuntu) but the variable for the token just returns the command (i.e. aws codeartifact get-authorization-token...) and not the actual value.

Upvotes: 1

Views: 846

Answers (1)

Amit Goldstein
Amit Goldstein

Reputation: 907

Use dotenv plugin to store these variables in the virtual env.

To install the plugin run: poetry self add poetry-dotenv-plugin

Then run a script that will create this .env locally (in the root of the repository). For example:

 echo "POETRY_HTTP_BASIC_CODEARTIFACT_USERNAME=username" >> .env
 echo "POETRY_HTTP_BASIC_CODEARTIFACT_PASSWORD=$(aws codeartifact get-authorization-token --domain my_domain --domain-owner 12345678 --query authorizationToken --output text --region eu-central-1)" >> .env

Now any run of poetry will first consume this .env file so as long as you keep it updated, it will work both in terminal and from the Pycharm UI.

Upvotes: 2

Related Questions