Skip to content

Commit 06283f1

Browse files
committed
python: allow custom proxy for poetry
1 parent 784a520 commit 06283f1

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

python/deploy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@ if [ -f "${CURRENT_DIR}/poetry.lock" ]; then
208208
fi
209209
pip install poetry${POETRY_VERSION_SPEC}
210210
poetry config virtualenvs.create false
211+
212+
# Configure custom Poetry repositories from environment variables
213+
# Format: POETRY_REPOSITORIES_<NAME>_URL=<URL>
214+
# Example: POETRY_REPOSITORIES_ARTIFACTORY_URL=https://artifactory.example.com/pypi/simple
215+
for var in $(env | grep '^POETRY_REPOSITORIES_.*_URL=' | cut -d= -f1); do
216+
# Extract repository name from variable name
217+
# POETRY_REPOSITORIES_ARTIFACTORY_URL -> ARTIFACTORY
218+
repo_name=$(echo "$var" | sed 's/^POETRY_REPOSITORIES_//' | sed 's/_URL$//' | tr '[:upper:]' '[:lower:]')
219+
repo_url="${!var}"
220+
221+
if [ -n "$repo_url" ]; then
222+
echo "Configuring Poetry repository: $repo_name -> $repo_url"
223+
poetry source add --priority=primary "$repo_name" "$repo_url"
224+
fi
225+
done
226+
211227
# Check if lock file needs updating and regenerate if needed
212228
if ! poetry check --lock 2>/dev/null; then
213229
echo "Lock file out of sync, regenerating..."

tests/python/tests.bats

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,4 +468,26 @@ EOF
468468

469469
rm ${CURRENT_DIR}/pyproject.toml ${CURRENT_DIR}/poetry.lock
470470
unset PYTHON_VERSION
471+
}
472+
473+
@test "install from poetry.lock with custom repository" {
474+
unset PYTHON_VERSION
475+
export POETRY_REPOSITORIES_ARTIFACTORY_URL=https://pypi.org/simple
476+
cp pyproject.toml poetry.lock ${CURRENT_DIR}/
477+
478+
run /var/lib/tsuru/deploy
479+
assert_success
480+
481+
[[ "$output" == *"poetry.lock detected"* ]]
482+
[[ "$output" == *"Configuring Poetry repository: artifactory -> https://pypi.org/simple"* ]]
483+
484+
pushd ${CURRENT_DIR}
485+
run pip freeze
486+
popd
487+
488+
assert_success
489+
[[ "$output" == *"msgpack"* ]]
490+
491+
rm ${CURRENT_DIR}/pyproject.toml ${CURRENT_DIR}/poetry.lock
492+
unset POETRY_REPOSITORIES_ARTIFACTORY_URL
471493
}

0 commit comments

Comments
 (0)