Skip to content

Commit

Permalink
Merge pull request #74 from coveo/feat/poetry-2-0-sync
Browse files Browse the repository at this point in the history
feat: support the new `poetry sync` command
  • Loading branch information
jonapich authored Feb 11, 2025
2 parents 2745eab + b34784f commit 33f6ad3
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 60 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/coveo-stew.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ on:


jobs:
pyprojectci:
name: pyproject ci
compatibility:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
poetry-version: [""]
python-version: ["3.9", "3.x"]
poetry-version: ["==1.8.5", ""] # empty means latest
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
Expand All @@ -43,11 +42,10 @@ jobs:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ matrix.poetry-version }}


publish:
name: Publish to pypi.org
runs-on: ubuntu-latest
needs: pyprojectci
needs: compatibility

steps:
- name: Checkout repository
Expand Down
14 changes: 13 additions & 1 deletion coveo_stew/poetry_backward_compatibility.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functools import lru_cache
from typing import Callable, Dict, Optional
from typing import Callable, Dict, List, Optional

from packaging.version import Version

Expand All @@ -24,3 +24,15 @@ def get_verb(verb: str, environment: Optional[PythonEnvironment]) -> str:
return old_verb

return verb


def get_install_sync_command(sync_target_environment: Optional[PythonEnvironment]) -> List[str]:
"""Returns the `poetry install --sync` command equivalent for this version of poetry."""
if find_poetry_version(sync_target_environment) >= Version("2.0.0"):
# 2.0.0 ditched "poetry install --sync" for "poetry sync"
return ["sync"]

# backward compatibility
# 1.2.0 and below use `poetry install --remove-untracked` flag
# 1.2.1 renamed `--remove-untracked` to `--sync`
return ["install", get_verb("--sync", sync_target_environment)]
14 changes: 8 additions & 6 deletions coveo_stew/stew.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from coveo_stew.metadata.poetry_api import PoetryAPI
from coveo_stew.metadata.python_api import PythonFile
from coveo_stew.metadata.stew_api import StewPackage
from coveo_stew.poetry_backward_compatibility import get_verb
from coveo_stew.poetry_backward_compatibility import get_install_sync_command
from coveo_stew.utils import load_toml_from_path

ENVIRONMENT_PATH_PATTERN: Final[Pattern] = re.compile(
Expand Down Expand Up @@ -147,8 +147,7 @@ def lock_is_outdated(self) -> bool:

# yolo: use the dry run output to determine if the lock is too old
dry_run_output = self.poetry_run(
"install",
get_verb("--sync", self.activated_environment()),
*get_install_sync_command(self.activated_environment()),
"--dry-run",
capture_output=True,
)
Expand Down Expand Up @@ -363,9 +362,12 @@ def install(
def _generate_poetry_install_command(
self, sync_target_environment: Optional[PythonEnvironment] = None, quiet: bool = False
) -> List[str]:
command: List[str] = ["install"]
if sync_target_environment:
command.append(get_verb("--sync", sync_target_environment))
command: List[str] = (
get_install_sync_command(sync_target_environment)
if sync_target_environment
else ["install"]
)

if quiet and not self.verbose:
command.append("--quiet")
if self.options.all_extras:
Expand Down
Loading

0 comments on commit 33f6ad3

Please sign in to comment.