Skip to content

fix: detect Python package manager before installing in worktree setup#1109

Open
kuishou68 wants to merge 1 commit intoobra:mainfrom
kuishou68:fix/issue-1108-worktree-python-package-manager
Open

fix: detect Python package manager before installing in worktree setup#1109
kuishou68 wants to merge 1 commit intoobra:mainfrom
kuishou68:fix/issue-1108-worktree-python-package-manager

Conversation

@kuishou68
Copy link
Copy Markdown

Closes #1108

Problem

The using-git-worktrees skill unconditionally ran poetry install for any project containing a pyproject.toml:

# Old code
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then poetry install; fi

pyproject.toml is now the standard Python project metadata file — it is used by uv, pip, hatch, pdm, setuptools, and many other tools, the vast majority of which are not Poetry. Running poetry install on these projects either fails outright (if Poetry is not installed) or produces an incorrect environment.

Fix

Detect the actual package manager by inspecting file contents and lock files:

# New code
if [ -f pyproject.toml ]; then
  if grep -q '\[tool\.poetry\]' pyproject.toml; then
    poetry install
  elif [ -f uv.lock ]; then
    uv sync
  elif [ -f requirements.txt ]; then
    pip install -r requirements.txt
  else
    pip install -e .
  fi
elif [ -f requirements.txt ]; then
  pip install -r requirements.txt
fi

Detection heuristic:

Signal Action
[tool.poetry] in pyproject.toml poetry install
uv.lock present uv sync
requirements.txt present pip install -r requirements.txt
Generic pyproject.toml pip install -e .
Only requirements.txt pip install -r requirements.txt

Poetry projects are still handled correctly. Non-Poetry projects now get an appropriate install command instead of a Poetry error.

Changed Files

  • skills/using-git-worktrees/SKILL.md: updated "Run Project Setup" section

… setup

The previous code unconditionally ran `poetry install` for any project
containing pyproject.toml, breaking projects that use uv, pip, hatch,
pdm, or plain setuptools — the vast majority of modern Python projects.

New logic checks for [tool.poetry] in pyproject.toml, then falls back
to uv sync (if uv.lock exists), pip install -r requirements.txt, or
pip install -e . for generic pyproject.toml projects.

Closes obra#1108
Copy link
Copy Markdown

@Bortlesboat Bortlesboat left a comment

Choose a reason for hiding this comment

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

I verified the issue against current main locally, and this keeps the fix nicely scoped to the broken Run Project Setup snippet in skills/using-git-worktrees/SKILL.md.

One follow-up worth considering, but not necessarily a blocker for this PR: uv-managed projects can exist without a committed uv.lock, so [tool.uv] (or a similarly explicit signal in pyproject.toml) may eventually be worth checking too. Even with that edge case, this is still a clear improvement over unconditional poetry install for every pyproject.toml project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: using-git-worktrees skill runs for all pyproject.toml projects, breaking non-Poetry setups

2 participants