Skip to content

Commit

Permalink
use python virtualenv
Browse files Browse the repository at this point in the history
  • Loading branch information
SashaLsnko committed Jun 5, 2023
1 parent d6b8ee8 commit cf82401
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/commands/set-parameters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ steps:
MAPPING: << parameters.mapping >>
OUTPUT_PATH: << parameters.output-path >>
CONFIG_PATH: << parameters.config-path >>
shell: /usr/bin/env python3
command: <<include(scripts/create-parameters.py)>>
CREATE_PIPELINE_SCRIPT: <<include(scripts/create-parameters.py)>>
command: <<include(scripts/create-parameters.sh)>>
17 changes: 8 additions & 9 deletions src/scripts/create-parameters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3

import json
import os
import re
Expand Down Expand Up @@ -137,10 +135,11 @@ def create_parameters(output_path, config_path, head, base, mapping):
write_parameters_from_mappings(mappings, changes, output_path, config_path)


create_parameters(
os.environ.get('OUTPUT_PATH'),
os.environ.get('CONFIG_PATH'),
os.environ.get('CIRCLE_SHA1'),
os.environ.get('BASE_REVISION'),
os.environ.get('MAPPING')
)
if __name__ == "__main__":
create_parameters(
os.environ.get('OUTPUT_PATH'),
os.environ.get('CONFIG_PATH'),
os.environ.get('CIRCLE_SHA1'),
os.environ.get('BASE_REVISION'),
os.environ.get('MAPPING')
)
35 changes: 35 additions & 0 deletions src/scripts/create-parameters.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -e
set -o pipefail

if [ -f .python-version ]; then
# Create a temp directory
circleci_temp_dir="$(mktemp -d)"
# Move .python-version out of the directory
mv .python-version "$circleci_temp_dir"/.python-version
fi

curl "https://bootstrap.pypa.io/get-pip.py" -o "circleci_get_pip.py"
python3 circleci_get_pip.py --user

python3 -m pip install --user virtualenv

echo "Create python virtual environment for path-filtering"
virtualenv path-filtering-venv -p /usr/bin/python3

echo "Activate python virtual environment"
# shellcheck source=/dev/null
. path-filtering-venv/bin/activate

echo "${CREATE_PIPELINE_SCRIPT}" > circleci_create_parameters_script.py

echo "Creating pipeline parameters"
python3 circleci_create_parameters_script.py

if [ -f "$circleci_temp_dir"/.python-version ]; then
# Move .python-version back
mv "$circleci_temp_dir"/.python-version .python-version
fi

echo "Deactivate python virtual environment for path-filtering"
deactivate

0 comments on commit cf82401

Please sign in to comment.