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

Added support for v2 poetry #53

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,70 +16,78 @@

jobs:
tests:
name: ${{ matrix.os }} / ${{ matrix.python-version }} ${{ matrix.suffix }}
name: ${{ matrix.os }} / ${{ matrix.python-version }} / ${{ matrix.poetry-version }} ${{ matrix.suffix }}
runs-on: ${{ matrix.image }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
os: [Ubuntu, macOS, Windows]
python-version: ["3.9", "3.10", "3.11"]
poetry-version: ["1.8.5", "2.0.1", ""]
include:
- os: Ubuntu
image: ubuntu-latest
- os: Windows
image: windows-latest
- os: macOS
image: macos-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

# Store full python version in a variable 'version'
- name: Get full Python version
id: full-python-version
run: echo "version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")" >> $GITHUB_OUTPUT

- name: Bootstrap poetry
run: |
curl -sL https://install.python-poetry.org | python - -y ${{ matrix.bootstrap-args }}
env:
POETRY_VERSION: ${{ matrix.poetry-version }}

- name: Update PATH
if: ${{ matrix.os != 'Windows' }}
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Update Path for Windows
if: ${{ matrix.os == 'Windows' }}
run: echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH

- name: Configure poetry
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v4
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ matrix.poetry-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
run: timeout 10s poetry run pip --version || rm -rf .venv

- name: Install dependencies
run: poetry install --with ci

- name: Install correct poetry version
if: matrix.poetry-version != ''
run: |
poetry run pip install "poetry==${{ matrix.poetry-version }}"

- name: Run pre-commit tests
run: |
poetry run pre-commit run --all-files

- name: Test with pytest
run: |
poetry run pytest -v

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions Job or Workflow does not set permissions
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://pre-commit.com/ for usage and config
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-toml
- id: check-yaml
Expand Down
262 changes: 127 additions & 135 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion poetry_monoranger_plugin/lock_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def execute(self, event: ConsoleCommandEvent):
"""
command = event.command
assert isinstance(command, (LockCommand, InstallCommand, UpdateCommand)), (
f"{self.__class__.__name__} can only be used for `poetry lock`, `poetry install`, and `poetry update` commands"
f"{self.__class__.__name__} can only be used for `poetry lock`, `poetry install`, `poetry update`, `poetry sync` commands"
)

io = event.io
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ classifiers = [

[tool.poetry.dependencies]
python = "^3.9"
poetry = ">=1.8.0,<1.9.0"
poetry = ">=1.8.0"

[tool.poetry.group.dev.dependencies]
ruff = ">=0.6.9,<0.10.0"
Expand Down
5 changes: 5 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from typing import TYPE_CHECKING
from unittest.mock import patch

import poetry.__version__
import pytest
from cleo.events.console_command_event import ConsoleCommandEvent
from cleo.events.console_events import COMMAND
from cleo.io.inputs.argv_input import ArgvInput
Expand All @@ -26,6 +28,9 @@
from poetry.console.commands.command import Command
from poetry.utils.env.base_env import Env

POETRY_V2 = poetry.__version__.__version__.startswith("2")
only_poetry_v2 = pytest.mark.skipif(POETRY_V2 is False, reason="requires poetry 2.0.0 or higher")


class MockApplication(Application):
"""A mock application that stored the last command class that was executed
Expand Down
17 changes: 13 additions & 4 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import tarfile

from tests.helpers import is_system_env
import pytest

from tests.helpers import POETRY_V2, is_system_env


def test_add(repo_manager, poetry_run):
Expand Down Expand Up @@ -67,7 +69,10 @@ def test_update(repo_manager, poetry_run):
poetry_run(v1_dir, "pkg_one", "add numpy<=1.25")
pkg_one_pyproject = (v1_dir / "pkg_one" / "pyproject.toml").read_text()
(v1_dir / "pkg_one" / "pyproject.toml").write_text(pkg_one_pyproject.replace("<=1.25", "<=1.26.4"))
poetry_run(v1_dir, "pkg_one", "lock --no-update")
if POETRY_V2:
poetry_run(v1_dir, "pkg_one", "lock")
else:
poetry_run(v1_dir, "pkg_one", "lock --no-update")
# This results in a lockfile with numpy==1.25 but pyproject.toml permits up to 1.26.5

root_lock = (v1_dir / "poetry.lock").read_text()
Expand Down Expand Up @@ -109,7 +114,8 @@ def test_lock(repo_manager, poetry_run):
assert root_pyproject == (v1_dir / "pyproject.toml").read_text() # root pyproject.toml is not modified


def test_install(repo_manager, poetry_run):
@pytest.mark.parametrize("sync", [True, False])
def test_install(repo_manager, poetry_run, sync: bool):
# Arrange
v1_dir = repo_manager.get_repo("v1", preinstalled=False)
envs_before = repo_manager.get_envs(v1_dir)
Expand All @@ -121,7 +127,10 @@ def test_install(repo_manager, poetry_run):
assert is_system_env(env)

# Act
result = poetry_run(v1_dir, "pkg_one", "install")
if sync:
result = poetry_run(v1_dir, "pkg_one", "sync") if POETRY_V2 else poetry_run(v1_dir, "pkg_one", "install --sync")
else:
result = poetry_run(v1_dir, "pkg_one", "install")

# Assert
assert result.exit_code == 0
Expand Down