Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adapting tests and code-style actions to avoid using venv when called by poetry #423

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
RobPasMue marked this conversation as resolved.
Show resolved Hide resolved
#
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
26 changes: 20 additions & 6 deletions tests-pytest/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,28 @@ 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.
# Store POETRY_VIRTUALENVS_CREATE=false in the GitHub environment to prevent
# poetry from creating a virtual environment.
RobPasMue marked this conversation as resolved.
Show resolved Hide resolved
RobPasMue marked this conversation as resolved.
Show resolved Hide resolved
#
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure you can call poetry from python. I think it installs as command line tool

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are completely right - my bad

else
python -m pip install .
fi

- name: "Install X Virtual Frame Buffer"
shell: bash
Expand Down Expand Up @@ -135,8 +150,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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you see in the previous version it doesnt call with python.

python -m poetry install --with tests
else
python -m pip install .[tests]
fi
Expand Down