deptry icon indicating copy to clipboard operation
deptry copied to clipboard

Support uv workspaces

Open cospectrum opened this issue 1 year ago • 2 comments

Environment

  • deptry version: 0.23.0
  • Python version: 3.10.16
  • Operating system (e.g. Ubuntu 22.04, Windows 11): macos

Describe the issue

uv run deptry . for uv-workspace gives bad results that on location.

Minimal way to reproduce the issue

project structure:

root/
  pyproject.toml
  uv.lock
  packages/
    first/
      pyproject.toml
      src/
        first/
          __init__.py
          ...
    second/
      pyproject.toml
      src/
        second/
          __init__.py

root pyproject.toml:

[project]
name = "uv-workspace"
version = "0.1.0"
description = "uv workspace"
readme = "README.md"
requires-python = ">=3.10"
dependencies = []

[tool.uv.workspace]
members = ["packages/*"]

first pyproject.toml:

[project]
name = "first"
version = "0.1.0"
description = "first"
readme = "README.md"
requires-python = ">=3.10"
dependencies = ["second", "b"] # note: there is no "a", but it is imported in the `src/first/*` files for more complex behavior

[tool.uv.sources]
second = { workspace = true }

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

second pyproject.toml:

[project]
name = "second"
version = "0.1.0"
description = "second"
readme = "README.md"
requires-python = ">=3.10"
dependencies = []

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

root/packages/first/src/first/*.py files contain imports for the following modules: second, a, b and first (import from itself).

uv run deptry . inside the root dir warns about the following depndencies of the first module: b, first, second. uv run deptry . inside the first dir warns about the following depndencies of the first module: a, first.

Expected behavior

  1. each leaf package must be analyzed as if deptry was running from its root.
  2. therefore, deptry from the root package should warn about a dependency of thefirst project.
  3. deptry should not warn about "import from itself".

Additional context

cospectrum avatar Feb 20 '25 01:02 cospectrum

Yeah uv workspaces are not handled for now, we'd have to explicitly add support for them.

mkniewallner avatar Feb 22 '25 10:02 mkniewallner

My current workaround for this is to go into each workspace package folder and run deptry from there. Works ok.

Thanks for this library!

sander76 avatar Jun 13 '25 10:06 sander76