fpgmaas/deptry

Deptry not analyzing [tool.poetry.group.dev.dependencies] deps

Closed this issue · 2 comments

First off thanks for this really great and useful tool, it's been easy to use and valuable.

I'm not sure this is a bug, however reading through the documentation leads me to believe it may be.

Basically, what I'm seeing is that deptry doesn't seem to care what is specified under [tool.poetry.group.dev.dependencies] in pyproject.toml. This is the pyroject.toml I am using (with some truncation):

[tool.poetry]
...

[[tool.poetry.source]]
...

[[tool.poetry.source]]
...

[tool.poetry.dependencies]
python = "~3.10"
boto3 = "^1.26.76"
delta-spark = "2.4.0"
pyspark = "3.4.1"
nbformat = ">=5.0"
jupyter = "^1.0.0"
nbconvert = "^7.8.0"
bokeh = "^2.0.0"
databricks-sdk = "^0.10.0"
scikit-learn = "^1.3.2"
catboost = "^1.2.2"
lightgbm = "^4.1.0"
pyyaml = "^6.0.1"
s3fs = "^2023.12.1"
datasketches = "^4.1.0"
pytz = "2024.1"
numpy = "^1.26.4"
pandas = "^1.5.3"
statsmodels = "^0.14"
ipython = "^8.21.0"
scipy = "^1.13.0"
matplotlib = "^3.8.4"
botocore = "^1.34.69"

[tool.poetry.group.dev.dependencies]
black = "23.1.0"
cruft = "^2.10.2"
deptry = "^0.16.1"
flake8 = "6.1.0"
mypy = "^1.1.1"
pre-commit = "^3.1.1"
pytest = "^7.2.2"
pytest-cov = "^4.0.0"
pytest-sugar = "^0.9.6"
pyspark-test = "^0.2.0"
pytest-xdist = "^3.2.1"
pytest-mock = "3.8.2"
pytest-profiling = "^1.7.0"
freezegun = "^1.5.0"
types-six = "^1.16.21.9"
types-python-dateutil = "^2.8.19.14"
types-pyyaml = "^6.0.12.12"
types-pytz = "^2024.1.0.20240417"

[tool.poetry-dynamic-versioning]
enable = true
style = 'pep440'

[build-system]
requires = ["poetry-core>=1.1.0", "poetry-dynamic-versioning"]
build-backend = "poetry_dynamic_versioning.backend"

[tool.black]
line-length = 140
skip-string-normalization = true
target_version = ['py39']

[tool.mypy]
files = 'pyspark_data_science_jobs'
python_version = '3.10'
check_untyped_defs = false
warn_incomplete_stub = true
follow_imports = 'silent'
ignore_missing_imports = true
mypy_path = 'stubs'
implicit_optional = true
exclude = [
    '.*/closed_loop/doc/.*'
]

[tool.pytest.ini_options]
minversion = "7.0"
log_cli = false
log_cli_level = "ERROR"
console_output_style = "progress"
addopts = "--cov --maxfail=2 -n 4 --durations=10"
testpaths = ["tests"]

[tool.cruft]
skip = [".git"]

[tool.deptry.per_rule_ignores]
DEP002 = ["delta-spark", "jupyter"]

When running poetry run deptry . the dependencies under [tool.poetry.group.dev.dependencies] aren't analyzed, even though some deps are unused.

Expected behavior

Is this expected? I feel like the tool should be flagging unused deps in this case.

System [please complete the following information]:

  • OS: MacOS 14.4.1 (Ventura) and Ubuntu 20.04
  • Language Version: Python 3.10
  • Poetry version: 1.5.1

Hi, this is the expected behaviour. In most situations, developement dependencies are not meant to be used in "production" code, but instead could be used during testing (for instance pytest), or invoked as CLIs (for instance mypy). As noted in https://deptry.com/usage/#excluding-files-and-directories, deptry will try its best to exclude non-production files by default (e.g. test files). So it would not be reliable for deptry to guess if a development dependency is indeed used or not, especially for the ones invoked as CLIs.

Reading the documentation for DEP002 though, we don't explicitly mention that development dependencies are not considered for this check, so maybe we can add a small note about that.

@mkniewallner thanks for the explanation here, that does make sense. I do think a brief mention of this in the docs could be helpful, even if this is probably obvious to some devs.