Skip to main content

Using poetry

Make sure AWS CLI has set with an account in the o-akodnm2nsf org id. (ECS org).

1. Create a scripts.py file

This file needs to be at the root of your project:

scripts.py
from subprocess import run, PIPE, STDOUT, Popen

def login():
repo_std = run(["aws", "codeartifact", "get-repository-endpoint", "--domain", "neev", "--domain-owner", "529730085565", "--repository", "pypi", "--format", "pypi", "--query", "repositoryEndpoint", "--region", "eu-west-2", "--output", "text"], capture_output=True)
if repo_std.stderr:
error_text = repo_std.stderr.decode("utf-8")
raise Exception(error_text)

access_key_std = run(["aws", "codeartifact", "get-authorization-token", "--domain", "neev", "--domain-owner", "529730085565", "--query", "authorizationToken", "--region", "eu-west-2", "--output", "text"], capture_output=True)
if access_key_std.stderr:
error_text = access_key_std.stderr.decode("utf-8")
raise Exception(error_text)

repo = repo_std.stdout.decode('utf-8').strip()
access_key = access_key_std.stdout.decode('utf-8').strip()
run(["poetry", "config", "repositories.neev", repo])
run(["poetry", "config", "http-basic.neev", "aws", access_key])

def publish():
with Popen("poetry publish --build -r neev", stdout=PIPE, stderr=STDOUT) as process:
for line in process.stdout:
print(line.decode('utf8').strip())

note

The publish function here is only meant for the CI pipeline. It will not work on your local machine.

2. Update pyproject.toml

Add the following to your pyproject.toml file:

pyproject.toml
[tool.poetry.scripts]
login = "scripts:login"

[[tool.poetry.source]]
name = "neev"
url = "https://neev-529730085565.d.codeartifact.eu-west-2.amazonaws.com/pypi/pypi/simple/"

The first blocks adds a command which we would use in step 3. The second block adds a private repository from which we will install Neev packages.

3. Login via the custom script

poetry run login
tip

If you get "An error occurred (ResourceNotFoundException) when calling the GetAuthorizationToken operation: Domain not found. Domain 'neev' owned by account '529730085565' does not exist."
Then make sure the aws cli has been set with an account in the o-akodnm2nsf org id. (ECS org).

caution

The token is valid for 12 hours by default. You'll need to call this command again to get a new token.

4. Install a package

poetry add example-package-math