Skip to content
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
8 changes: 8 additions & 0 deletions src/usethis/_integrations/backend/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import Literal

from usethis._config import usethis_config
from usethis._console import warn_print
from usethis._integrations.backend.poetry.used import is_poetry_used
from usethis._integrations.backend.uv.available import is_uv_available
from usethis._integrations.backend.uv.used import is_uv_used
from usethis._types.backend import BackendEnum
Expand All @@ -12,6 +14,12 @@ def get_backend() -> Literal[BackendEnum.uv, BackendEnum.none]:
if usethis_config.backend is not BackendEnum.auto:
return usethis_config.backend

if is_poetry_used():
warn_print(
"This project is using Poetry, which is not fully supported by usethis."
)
return BackendEnum.none

if is_uv_used() or is_uv_available():
return BackendEnum.uv

Expand Down
Empty file.
15 changes: 15 additions & 0 deletions src/usethis/_integrations/backend/poetry/used.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from usethis._config import usethis_config
from usethis._integrations.file.pyproject_toml.io_ import PyprojectTOMLManager


def is_poetry_used() -> bool:
pyproject_toml_manager = PyprojectTOMLManager()

return (
(usethis_config.cpd() / "poetry.lock").exists()
or (usethis_config.cpd() / "poetry.toml").exists()
or (
pyproject_toml_manager.path.exists()
and ["tool", "poetry"] in pyproject_toml_manager
)
)
20 changes: 20 additions & 0 deletions tests/usethis/_integrations/backend/test_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,23 @@ def mock_call_uv_subprocess(*_, **__):

# Assert
assert result == BackendEnum.none

def test_poetry_used(self, tmp_path: Path, capfd: pytest.CaptureFixture):
# Arrange
(tmp_path / "poetry.lock").touch()

# Act
with change_cwd(tmp_path), usethis_config.set(backend=BackendEnum.auto):
result = get_backend()

# Assert
# N.B. poetry is not fully supported, so we use the none backend for now.
# Later, this might change to a poetry backend.
assert result == BackendEnum.none

out, err = capfd.readouterr()
assert not err
assert (
out
== "⚠ This project is using Poetry, which is not fully supported by usethis.\n"
)