Skip to content

Commit

Permalink
feat: adapting tests and code-style actions to avoid using venv when …
Browse files Browse the repository at this point in the history
…called by poetry (#423)
  • Loading branch information
RobPasMue committed Mar 14, 2024
1 parent 0746034 commit c88503b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
24 changes: 9 additions & 15 deletions code-style/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,24 @@ runs:
python-version: ${{ inputs.python-version }}
use-cache: ${{ inputs.use-python-cache }}

- name: "Create virtual environment"
- name: "Upgrade pip and disable virtual environment (for poetry only)"
shell: bash
run: |
python -m pip install --upgrade pip
python -m venv .venv
- name: "Store venv activation mechanism depending on OS"
shell: bash
run: |
if [[ "$RUNNER_OS" == "Linux" ]]; then
echo "ACTIVATE_VENV=$(echo 'source .venv/bin/activate')" >> $GITHUB_ENV
elif [[ "$RUNNER_OS" == "macOS" ]]; then
echo "ACTIVATE_VENV=$(echo 'source .venv/bin/activate')" >> $GITHUB_ENV
elif [[ "$RUNNER_OS" == "Windows" ]]; then
echo "ACTIVATE_VENV=$(echo 'source .venv/Scripts/activate')" >> $GITHUB_ENV
if grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then
# For projects using poetry, do not use a virtual environment.
# Poetry uses virtual environments to install its dependencies, but this might
# lead to problems if it is not activated prior to executing poetry commands.
# Store POETRY_VIRTUALENVS_CREATE=false in the GitHub environment to prevent
# poetry from creating a virtual environment.
#
echo "POETRY_VIRTUALENVS_CREATE=false" >> $GITHUB_ENV
fi
- name: "Install project (if required)"
if: inputs.skip-install == 'false'
shell: bash
run: |
${{ env.ACTIVATE_VENV }}
if grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then
python -m pip install poetry
python -m poetry install
Expand All @@ -133,14 +129,12 @@ runs:
- name: "Install pre-commit"
shell: bash
run: |
${{ env.ACTIVATE_VENV }}
python -m pip install pre-commit
pre-commit install
- name: "Run pre-commit"
shell: bash
run: |
${{ env.ACTIVATE_VENV }}
pre-commit run --all-files --show-diff-on-failure
# ------------------------------------------------------------------------
Expand Down
28 changes: 22 additions & 6 deletions tests-pytest/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,30 @@ runs:
python-version: ${{ inputs.python-version }}
use-cache: ${{ inputs.use-python-cache }}

- name: "Update pip"
- name: "Upgrade pip and disable virtual environment (for poetry only)"
shell: bash
run: python -m pip install -U pip
run: |
python -m pip install --upgrade pip
if grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then
# For projects using poetry, do not use a virtual environment.
# Poetry uses virtual environments to install its dependencies, but this might
# lead to problems if it is not activated prior to executing poetry commands.
# Store POETRY_VIRTUALENVS_CREATE=false in the GitHub environment to prevent
# poetry from creating a virtual environment.
#
echo "POETRY_VIRTUALENVS_CREATE=false" >> $GITHUB_ENV
fi
- name: "Install Python library"
- name: "Install project (if required)"
if: inputs.skip-install == 'false'
shell: bash
run: python -m pip install .
run: |
if grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then
python -m pip install poetry
python -m poetry install
else
python -m pip install .
fi
- name: "Install X Virtual Frame Buffer"
shell: bash
Expand Down Expand Up @@ -135,8 +152,7 @@ runs:
if: env.EXISTS_TESTS_REQUIREMENTS == 'false'
run: |
if grep -q 'build-backend = "poetry\.core\.masonry\.api"' "pyproject.toml"; then
python -m pip install poetry
poetry install --with tests
python -m poetry install --with tests
else
python -m pip install .[tests]
fi
Expand Down

0 comments on commit c88503b

Please sign in to comment.