Skip to content

Commit

Permalink
fix: improve detection of poetry 2 projects (#274)
Browse files Browse the repository at this point in the history
Projects created with poetry >= 2.0 don't necessarily include a
tool.poetry table in the pyproject.toml. Thus poethepoet cannot
rely on the presence or absence of this table to tell whether
it is appropriate to default to using the PoetryExecutor to run
tasks with poetry's venv.

It seems the best remaining indicator is the content of the
build-system which poetry still configures consistently, although
this is less ideal.
  • Loading branch information
nat-n authored Jan 26, 2025
1 parent cb5ee7b commit b3b6df5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions poethepoet/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ def verbosity(self) -> int:

@property
def is_poetry_project(self) -> bool:
return (
self._project_config.path.name == "pyproject.toml"
and "poetry" in self._project_config.full_config.get("tool", {})
full_config = self._project_config.full_config
return self._project_config.path.name == "pyproject.toml" and (
"poetry" in full_config.get("tool", {})
or (
# Fallback required to work out of the box with some poetry 2.0 projects
full_config.get("build-system", {}).get("build-backend", "")
== "poetry.core.masonry.api"
)
)

@property
Expand Down
2 changes: 1 addition & 1 deletion poethepoet/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _get_config(cls, application: Application) -> "PoeConfig":
# Try respect poetry's '--directory' if set
try:
pyproject_dir = application.poetry.pyproject_path.parent
except AttributeError:
except (AttributeError, RuntimeError):
pyproject_dir = None

poe_config = PoeConfig(cwd=pyproject_dir)
Expand Down

0 comments on commit b3b6df5

Please sign in to comment.