### Install dependencies with uv Source: https://github.com/osprey-oss/deptry/blob/main/docs/contributing.md Synchronize and install project dependencies using uv. ```bash uv sync ``` -------------------------------- ### Install pre-commit hooks Source: https://github.com/osprey-oss/deptry/blob/main/docs/contributing.md Install pre-commit hooks to automate linting and formatting checks at commit time. ```bash pre-commit install ``` -------------------------------- ### Example requirements.txt Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md This snippet shows a typical requirements.txt file that includes a reference to another requirements file. ```text -r cli-requirements.txt httpx==0.27.2 ``` -------------------------------- ### CLI Example: Requirements Files Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --requirements-files option to specify pip requirements files. ```shell deptry . --requirements-files requirements.txt,requirements-private.txt ``` -------------------------------- ### Install Deptry with pip Source: https://github.com/osprey-oss/deptry/blob/main/docs/index.md Install deptry using pip. Ensure this is done within your project's virtual environment. ```shell pip install deptry ``` -------------------------------- ### Example Deptry Output Source: https://github.com/osprey-oss/deptry/blob/main/README.md This is an example of the output you might see after running a deptry scan, indicating various dependency issues found in your project. ```console Scanning 2 files... foo/bar.py:1:0: DEP004 'numpy' imported but declared as a dev dependency foo/bar.py:2:0: DEP001 'matplotlib' imported but missing from the dependency definitions pyproject.toml: DEP002 'pandas' defined as a dependency but not used in the codebase Found 3 dependency issues. ``` -------------------------------- ### Example cli-requirements.txt Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md This snippet defines dependencies for a command-line interface, referenced from a main requirements file. ```python # cli-requirements.txt click==8.1.7 ``` -------------------------------- ### Install Deptry with pip Source: https://github.com/osprey-oss/deptry/blob/main/README.md Install deptry using pip. Ensure this is done within your project's virtual environment, as global installation may not function correctly. ```shell pip install deptry ``` -------------------------------- ### CLI Example for Experimental Namespace Package Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the command-line interface to enable the experimental namespace package support. ```shell deptry . --experimental-namespace-package ``` -------------------------------- ### TOML Example: Known First-Party Modules Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md List known first-party modules in pyproject.toml using known_first_party. ```toml [tool.deptry] known_first_party = ["bar", "foo"] ``` -------------------------------- ### CLI Example: Known First-Party Modules Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --known-first-party option to specify modules considered as first-party. ```shell deptry . --known-first-party bar --known-first-party foo ``` -------------------------------- ### TOML Example: Requirements Files Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Specify custom requirements files in pyproject.toml using requirements_files. ```toml [tool.deptry] requirements_files = ["requirements.txt", "requirements-private.txt"] ``` -------------------------------- ### CLI Example for Non-Dev Groups Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the command-line interface to specify dependency groups that should be treated as regular dependencies. ```shell deptry . --non-dev-dependency-groups "server,telemetry" ``` -------------------------------- ### TOML Example: Development Requirements Files Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Configure development requirements files in pyproject.toml using requirements_files_dev. ```toml [tool.deptry] requirements_files_dev = ["requirements-dev.txt", "requirements-tests.txt"] ``` -------------------------------- ### CLI Example: Specify pyproject.toml Configuration Path Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --config option to point to a specific pyproject.toml file. ```shell deptry . --config sub_directory/pyproject.toml ``` -------------------------------- ### Run tests with just Source: https://github.com/osprey-oss/deptry/blob/main/docs/contributing.md Execute all unit and functional tests using the 'just test' command. Requires 'just' to be installed. ```bash just test ``` -------------------------------- ### CLI Example: Development Requirements Files Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --requirements-files-dev option to specify development pip requirements files. ```shell deptry . --requirements-files-dev requirements-dev.txt,requirements-tests.txt ``` -------------------------------- ### Python CLI requirements file example Source: https://github.com/osprey-oss/deptry/blob/main/CHANGELOG.md Example of a Python CLI requirements file. This file can be included by a main requirements file using the '-r' directive. ```python # cli-requirements.txt click==8.1.7 ``` -------------------------------- ### CLI Example: Per-Rule Ignores Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --per-rule-ignores option to map rules to ignored packages/modules. ```shell deptry . --per-rule-ignores "DEP001=matplotlib,DEP002=pandas|numpy" ``` -------------------------------- ### CLI Example for PEP 621 Dev Groups Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the command-line interface with the deprecated `--pep621-dev-dependency-groups` option. ```shell deptry . --pep621-dev-dependency-groups "test,docs" ``` -------------------------------- ### CLI Example for Optional Dev Groups Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the command-line interface to specify optional dependency groups that should be considered development dependencies. ```shell deptry . --optional-dependencies-dev-groups "test,docs" ``` -------------------------------- ### Install Deptry with uv Source: https://github.com/osprey-oss/deptry/blob/main/README.md Use this command to add deptry as a development dependency when using uv for package management. ```shell uv add --dev deptry ``` -------------------------------- ### pip/pip-tools Requirements File Example Source: https://github.com/osprey-oss/deptry/blob/main/docs/supported-dependency-managers.md Specifies regular dependencies in `requirements.txt` and development dependencies in `dev-requirements.txt` for use with pip or pip-tools. ```python click>=8.0.0 orjson>=3.0.0 ``` ```python mkdocs==1.6.1 pytest==8.3.3 pytest-cov==5.0.0 ``` -------------------------------- ### CLI Example: Extend Exclude Patterns Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --extend-exclude option to add more patterns to the exclude list. ```shell deptry . --extend-exclude "a_directory|a_python_file\.py|a_pattern/.*" ``` -------------------------------- ### CLI Example: Ignore Notebooks Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --ignore-notebooks flag to prevent deptry from scanning notebook files. ```shell deptry . --ignore-notebooks ``` -------------------------------- ### Install Deptry with Poetry Source: https://github.com/osprey-oss/deptry/blob/main/README.md Use this command to add deptry as a development dependency when using Poetry for package management. ```shell poetry add --dev deptry ``` -------------------------------- ### CLI Example: Exclude Patterns Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --exclude option to specify patterns to exclude from source file searching. ```shell deptry . --exclude "a_directory|a_python_file\.py|a_pattern/.*" ``` -------------------------------- ### TOML Example: Exclude Patterns Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Configure exclude patterns in the [tool.deptry] section of pyproject.toml. ```toml [tool.deptry] exclude = ["a_directory", "a_python_file\\.py", "a_pattern/.*"] ``` -------------------------------- ### CLI Example: Ignore Rules Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --ignore option to specify a comma-separated list of rules to ignore. ```shell deptry . --ignore DEP003,DEP004 ``` -------------------------------- ### TOML Example: Ignore Rules Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Specify rules to ignore in the [tool.deptry] section of pyproject.toml. ```toml [tool.deptry] ignore = ["DEP003", "DEP004"] ``` -------------------------------- ### Handle string requirements files for setuptools dynamic dependencies Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md Deptry now correctly handles requirements files specified as strings for setuptools dynamic dependencies. This ensures compatibility with various project setups. ```python from setuptools import setup setup( # ... other arguments install_requires=[ "my-package==1.0.0", "another-package>=2.0.0", ], # ... other arguments ) ``` -------------------------------- ### TOML Example: Ignore Notebooks Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Set ignore_notebooks to true in pyproject.toml to disable searching in notebook files. ```toml [tool.deptry] ignore_notebooks = true ``` -------------------------------- ### JSON Output Example Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md This JSON structure represents the detected dependency issues. It includes error codes, messages, module names, and locations within the project files. ```json [ { "error": { "code": "DEP002", "message": "uvicorn defined as a dependency but not used in the codebase" }, "module": "uvicorn", "location": { "file": "pyproject.toml", "line": null, "column": null } }, { "error": { "code": "DEP002", "message": "uvloop defined as a dependency but not used in the codebase" }, "module": "uvloop", "location": { "file": "pyproject.toml", "line": null, "column": null } }, { "error": { "code": "DEP004", "message": "black imported but declared as a dev dependency" }, "module": "black", "location": { "file": "src/main.py", "line": 4, "column": 0 } }, { "error": { "code": "DEP003", "message": "httpx imported but it is a transitive dependency" }, "module": "httpx", "location": { "file": "src/main.py", "line": 6, "column": 0 } } ] ``` -------------------------------- ### TOML Example: Per-Rule Ignores Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Configure per-rule ignores in pyproject.toml for specific packages or modules. ```toml [tool.deptry.per_rule_ignores] DEP001 = ["matplotlib"] DEP002 = ["pandas", "numpy"] ``` -------------------------------- ### Misplaced Development Dependency Example Source: https://github.com/osprey-oss/deptry/blob/main/docs/rules-violations.md Illustrates a scenario where a package used in main application code is incorrectly placed under development dependencies. Shows the initial incorrect TOML configuration and the corrected version. ```toml [project] dependencies = ["httpx==0.23.1"] [tool.pdm.dev-dependencies] test = [ "orjson==3.8.3", "pytest==7.2.0", ] ``` ```python import httpx import orjson def make_http_request(): return httpx.get("https://example.com") def dump_json(): return orjson.dumps({"foo": "bar"}) ``` ```toml [project] dependencies = [ "httpx==0.23.1", "orjson==3.8.3", ] [tool.pdm.dev-dependencies] test = ["pytest==7.2.0"] ``` -------------------------------- ### Run tests with tox Source: https://github.com/osprey-oss/deptry/blob/main/docs/contributing.md Execute tests across all supported Python versions using tox. Requires multiple Python versions to be installed. ```bash tox ``` -------------------------------- ### Standard Library Dependency Violation Example Source: https://github.com/osprey-oss/deptry/blob/main/docs/rules-violations.md Demonstrates a violation where a standard library module is listed as a project dependency. Shows the initial TOML configuration with the standard library module and the corrected version after removal. ```toml [project] dependencies = [ "asyncio", ] ``` ```python import asyncio def async_example(): return asyncio.run(some_coroutine()) ``` ```toml [project] dependencies = [] ``` -------------------------------- ### TOML Example: Extend Exclude Patterns Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Configure extend_exclude patterns in pyproject.toml to add to the default exclude list. ```toml [tool.deptry] extend_exclude = ["a_directory", "a_python_file\\.py", "a_pattern/.*"] ``` -------------------------------- ### Handle TYPE_CHECKING imports Source: https://github.com/osprey-oss/deptry/blob/main/CHANGELOG.md Example of how imports guarded by TYPE_CHECKING are skipped when using from __future__ import annotations. ```python from __future__ import annotations from typing import TYPE_CHECKING if TYPE_CHECKING: # This import will not be extracted as it is guarded by `TYPE_CHECKING` and `from __future__ import annotations` # is used. This means the import should only be evaluated by type checkers, and should not be evaluated during runtime. import mypy_boto3_s3 ``` -------------------------------- ### CLI Example: Disable ANSI Characters Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --no-ansi flag to disable ANSI escape codes in the output. ```shell deptry . --no-ansi ``` -------------------------------- ### Detect Dynamic Imports with String Literals Source: https://github.com/osprey-oss/deptry/blob/main/docs/usage.md Example of a dynamic import using importlib.import_module with a string literal, which deptry can detect. ```python import importlib importlib.import_module("foo") # package 'foo' imported ``` -------------------------------- ### Ignore specific dependencies per rule with --per-rule-ignores Source: https://github.com/osprey-oss/deptry/blob/main/CHANGELOG.md Use the --per-rule-ignores flag to specify dependencies to ignore for particular error codes. For example, ignore DEP001 for matplotlib and DEP002 for pandas and numpy. ```bash deptry . --per-rule-ignores DEP001=matplotlib,DEP002=pandas|numpy ``` -------------------------------- ### Ignore Imports Guarded by TYPE_CHECKING Source: https://github.com/osprey-oss/deptry/blob/main/docs/usage.md Example of an import that will not be extracted by deptry because it is guarded by TYPE_CHECKING and uses 'from __future__ import annotations'. ```python from __future__ import annotations from typing import TYPE_CHECKING if TYPE_CHECKING: # This import will not be extracted as it is guarded by `TYPE_CHECKING` and `from __future__ import annotations` # is used. This means the import should only be evaluated by type checkers, and should not be evaluated during runtime. import mypy_boto3_s3 ``` -------------------------------- ### Setuptools Dynamic Metadata Configuration Source: https://github.com/osprey-oss/deptry/blob/main/docs/supported-dependency-managers.md Configures Setuptools to dynamically read regular and optional dependencies from `requirements.txt` and `cli-requirements.txt` files via `pyproject.toml`. ```toml [build-backend] requires = ["setuptools"] build-backend = "setuptools.build_meta" [project] name = "foo" dynamic = ["dependencies", "optional-dependencies"] [tool.setuptools.dynamic] dependencies = { file = ["requirements.txt"] } [tool.setuptools.dynamic.optional-dependencies] cli = { file = ["cli-requirements.txt"] } ``` -------------------------------- ### Enable GitHub Output via CLI Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --github-output flag to enable GitHub Actions annotations directly from the command line. ```shell deptry . --github-output ``` -------------------------------- ### Scan Project for Dependency Issues Source: https://github.com/osprey-oss/deptry/blob/main/README.md Run this command from the root directory of your project to initiate a scan for dependency issues. The tool will analyze imported modules against your project's declared dependencies. ```shell deptry . ``` -------------------------------- ### Navigate to deptry directory Source: https://github.com/osprey-oss/deptry/blob/main/docs/contributing.md Change the current directory to the cloned deptry repository. ```bash cd deptry ``` -------------------------------- ### Map Multiple Packages to Module Names via CLI Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Provide multiple package-to-module mappings on the command line, separated by commas. Multiple module names for a single package are separated by pipes. ```shell deptry . --package-module-name-map "foo-python=foo|bar,bar-python=bar" ``` -------------------------------- ### Run Deptry on Multiple Directories Source: https://github.com/osprey-oss/deptry/blob/main/docs/usage.md Scan multiple specified directories for dependencies. Useful for monorepos or projects with distinct source roots. ```shell deptry a_directory another_directory ``` -------------------------------- ### Specify Config File Location Source: https://github.com/osprey-oss/deptry/blob/main/docs/usage.md Run deptry and specify the location of the pyproject.toml configuration file using the --config argument. ```shell deptry --config ``` -------------------------------- ### Poetry Regular Dependencies (PEP 621 Fallback) Source: https://github.com/osprey-oss/deptry/blob/main/docs/supported-dependency-managers.md Extracts regular dependencies from `[tool.poetry.dependencies]` when `[project.dependencies]` is not set or is empty, following Poetry's behavior. ```toml [project] name = "foo" [tool.poetry.dependencies] httpx = "0.28.1" ``` -------------------------------- ### Commit and push changes Source: https://github.com/osprey-oss/deptry/blob/main/docs/contributing.md Stage all changes, commit them with a descriptive message, and push the branch to GitHub. ```bash git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature ``` -------------------------------- ### Support PEP 621 in Poetry 2.0+ Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md Deptry now supports defining project metadata in PEP 621 format, as introduced in Poetry 2.0. This allows for more standardized project configuration. ```text Poetry 2.0 introduced support for defining project metadata in PEP 621. This is now supported by deptry. ``` -------------------------------- ### Ignore specific dependencies per rule with --per-rule-ignores Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md Use the --per-rule-ignores flag to specify dependencies to ignore for particular error codes, providing granular control. ```bash deptry . --per-rule-ignores DEP001=matplotlib,DEP002=pandas|numpy ``` -------------------------------- ### Poetry Regular Dependencies (PEP 621 Precedence) Source: https://github.com/osprey-oss/deptry/blob/main/docs/supported-dependency-managers.md When `[project.dependencies]` is set, dependencies are only extracted from it. `[tool.poetry.dependencies]` is used to enrich existing dependencies or for sources, not to define new ones. ```toml [project] name = "foo" dependencies = ["httpx"] [tool.poetry.dependencies] httpx = { git = "https://github.com/encode/httpx", tag = "0.28.1" } urllib3 = "2.3.0" ``` -------------------------------- ### Map Package to Multiple Module Names in pyproject.toml Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Configure pyproject.toml to map a package name to multiple top-level module names, separated by commas. ```toml [tool.deptry.package_module_name_map] foo-python = [ "foo", "bar", ] ``` -------------------------------- ### Configure requirements files in pyproject.toml Source: https://github.com/osprey-oss/deptry/blob/main/CHANGELOG.md Override the default requirements file detection by specifying the file path in the project configuration. ```toml [tool.deptry] requirements_files = ["requirements.txt"] ``` -------------------------------- ### Enable GitHub Output in pyproject.toml Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Set the github_output option to true in pyproject.toml to enable GitHub Actions annotations. ```toml [tool.deptry] github_output = true ``` -------------------------------- ### Configure JSON Output in pyproject.toml Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Specify the file path for JSON output in your pyproject.toml configuration. ```toml [tool.deptry] json_output = "deptry_report.txt" ``` -------------------------------- ### Map Package to Module Name via CLI Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --package-module-name-map or -pmnm flag to specify package-to-module mappings on the command line. ```shell deptry . --package-module-name-map "foo-python=foo" ``` -------------------------------- ### Configure GitHub Warning Errors via CLI Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --github-warning-errors flag with a comma-separated list of error codes to set warning severity for specific issues. ```shell deptry . --github-warning-errors DEP0001,DEP0002 ``` -------------------------------- ### Enable Experimental Namespace Package Support Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Enable experimental support for PEP 420 namespace packages. This changes how local Python modules are identified, considering any Python file within a directory as indicative of a module. ```toml [tool.deptry] experimental_namespace_package = true ``` -------------------------------- ### Enable JSON Output via CLI Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Use the --json-output or -o flag to direct Deptry's output to a JSON file from the command line. ```shell deptry . --json-output deptry_report.txt ``` -------------------------------- ### Scan Project for Dependency Issues Source: https://github.com/osprey-oss/deptry/blob/main/docs/index.md Run deptry from the root directory of your project to scan for dependency issues. The tool will analyze imported modules against your project's dependencies. ```shell deptry . ``` -------------------------------- ### Specify pyproject.toml location with --config Source: https://github.com/osprey-oss/deptry/blob/main/CHANGELOG.md Use the --config argument to explicitly specify the location of pyproject.toml when it's not in the root directory. This is a change from previous versions where pyproject.toml was always searched for in the root directory. ```shell deptry src ``` ```shell deptry --config ../pyproject.toml src ``` -------------------------------- ### Create a new branch Source: https://github.com/osprey-oss/deptry/blob/main/docs/contributing.md Create a new branch for local development of a bug fix or new feature. ```bash git checkout -b name-of-your-bugfix-or-feature ``` -------------------------------- ### Configure Optional Dependencies as Dev Groups Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Specify which optional dependency groups from `pyproject.toml` should be treated as development dependencies. Useful for projects adhering to PEP 621 without a separate build tool for dev dependencies. ```toml [project] ... dependencies = ["httpx"] [project.optional-dependencies] plot = ["matplotlib"] test = ["pytest"] ``` ```toml [tool.deptry] optional_dependencies_dev_groups = ["test", "docs"] ``` -------------------------------- ### Specify pyproject.toml location with --config Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md Use the --config argument to explicitly specify the location of pyproject.toml when it's not in the root directory. This is useful for projects with non-standard configurations. ```shell deptry --config path/to/pyproject.toml src ``` -------------------------------- ### Poetry Development Dependencies in pyproject.toml Source: https://github.com/osprey-oss/deptry/blob/main/docs/supported-dependency-managers.md Defines development dependencies using Poetry's legacy `[tool.poetry.dev-dependencies]` and grouped dependencies under `[tool.poetry.group..dependencies]` in `pyproject.toml`. ```toml [tool.poetry.dev-dependencies] mypy = "1.14.1" ruff = "0.8.6" [tool.poetry.group.docs.dependencies] mkdocs = "1.6.1" [tool.poetry.group.test.dependencies] pytest = "8.3.3" pytest-cov = "5.0.0" ``` -------------------------------- ### Configure GitHub Warning Errors in pyproject.toml Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Specify a list of error codes to be reported as warnings instead of errors when using GitHub output. ```toml [tool.deptry] github_warning_errors = ["DEP0001", "DEP0002"] ``` -------------------------------- ### Configure PEP 621 Dev Dependency Groups (Deprecated) Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Deprecated option to specify PEP 621 dev dependency groups. Use `--optional-dependencies-dev-groups` instead. This configures which groups are treated as development dependencies. ```toml [tool.deptry] pep621_dev_dependency_groups = ["test", "docs"] ``` -------------------------------- ### Configure requirements.in as primary requirements file Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md This TOML configuration snippet shows how to set 'requirements.in' as the primary file for dependency management when using pip requirements format. This is useful for projects utilizing tools like pip-tools. ```toml [tool.deptry] requirements_files = ["requirements.txt"] ``` -------------------------------- ### Configure deptry with pre-commit Source: https://github.com/osprey-oss/deptry/blob/main/docs/usage.md Integrate deptry into your pre-commit hooks by adding it to your .pre-commit-config.yaml. Ensure the correct tag or commit hash is used for the repository revision. ```yaml - repo: https://github.com/osprey-oss/deptry.git rev: "" hooks: - id: deptry args: ["--ignore", "DEP001"] ``` -------------------------------- ### Configure per-rule ignores in pyproject.toml Source: https://github.com/osprey-oss/deptry/blob/main/CHANGELOG.md Configure per-rule ignores in the [tool.deptry.per_rule_ignores] section of pyproject.toml. This allows granular control over which dependencies are ignored for specific error codes. ```toml [tool.deptry.per_rule_ignores] DEP001 = ["matplotlib"] DEP002 = ["pandas", "numpy"] ``` -------------------------------- ### Run deptry with src directory Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md When running deptry with a source directory argument, it now searches for pyproject.toml in the current working directory and Python files within the specified source directory. ```shell deptry src ``` -------------------------------- ### PyPy 3.10 support dropped, 3.11 added Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md Support for PyPy 3.10 has been removed as it is unsupported. PyPy 3.11 is now the only tested and supported version for PyPy. ```text Support for PyPy 3.10 has been dropped, since it is unsupported. We now only test against PyPy 3.11, and only publish wheels for this version. ``` -------------------------------- ### Console Output with Location and Error Codes Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md Issues are now reported with file, line, and column information, along with specific error codes for easier identification. ```console foo/bar.py:11:11: DEP002 'an_import' imported but missing from the dependencies foo/bar.py:12:11: DEP002 'another_import' imported but missing from the dependencies foo/baz.py:13:11: DEP003 'cfgv' imported but it is a transitive dependency pyproject.toml: DEP001 'pandas' defined as a dependency but not used in the codebase ``` -------------------------------- ### Requirements files parsing with requirements-parser Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md Deptry now uses the `requirements-parser` library to parse dependencies from requirements files. This enables automatic extraction of nested requirements files without explicit configuration. ```python import os # Example of a requirements.txt file that includes another requirements file: # requirements.txt: # -r base.txt # package-a # base.txt: # package-b ``` -------------------------------- ### Clone deptry repository Source: https://github.com/osprey-oss/deptry/blob/main/docs/contributing.md Clone the forked deptry repository to your local machine after forking it on GitHub. ```bash cd git clone git@github.com:YOUR_NAME/deptry.git ``` -------------------------------- ### Console Issue Reporting Format Source: https://github.com/osprey-oss/deptry/blob/main/CHANGELOG.md Issues are now reported with file, line, and column information, along with error codes for specific issue types. ```console foo/bar.py:11:11: DEP002 'an_import' imported but missing from the dependencies foo/bar.py:12:11: DEP002 'another_import' imported but missing from the dependencies foo/baz.py:13:11: DEP003 'cfgv' imported but it is a transitive dependency pyproject.toml: DEP001 'pandas' defined as a dependency but not used in the codebase ``` -------------------------------- ### JSON Output Format with Error Codes and Location Source: https://github.com/osprey-oss/deptry/blob/main/CHANGELOG.md The JSON output now includes error codes and detailed location information for detected issues. ```json { "error": { "code": "DEP001", "message": "'seven' imported but missing from the dependency definitions" }, "module": "seven", "location": { "file": "foo/bar.py", "line": 2, "column": 0 } } ``` -------------------------------- ### Parse requirements.txt with nested files Source: https://github.com/osprey-oss/deptry/blob/main/CHANGELOG.md Deptry now supports parsing nested requirements files referenced with '-r ' using the 'requirements-parser' library. This impacts how dependencies are detected from multiple requirement files. ```text -r cli-requirements.txt httpx==0.27.2 ``` -------------------------------- ### uv Development Dependencies in pyproject.toml Source: https://github.com/osprey-oss/deptry/blob/main/docs/supported-dependency-managers.md Extracts uv-specific development dependencies from the `[tool.uv.dev-dependencies]` section in `pyproject.toml`, in addition to PEP 621 dependencies. ```toml [tool.uv] dev-dependencies = [ "mkdocs==1.6.1", "pytest==8.3.3", "pytest-cov==5.0.0", ] ``` -------------------------------- ### Add Missing Dependency Source: https://github.com/osprey-oss/deptry/blob/main/docs/rules-violations.md When a module is imported but not found in project dependencies, add it to `[project.dependencies]` to resolve DEP001. ```toml [project] dependencies = [] ``` ```python import httpx def make_http_request(): return httpx.get("https://example.com") ``` ```toml [project] dependencies = ["httpx==0.23.1"] ``` -------------------------------- ### Ignore specific error codes with --ignore flag Source: https://github.com/osprey-oss/deptry/blob/main/CHANGELOG.md Use the --ignore flag to specify exact error codes to skip, such as DEP001 for missing dependencies and DEP002 for unused dependencies. This replaces older skip flags. ```bash deptry . --ignore "DEP001,DEP002" ``` -------------------------------- ### PEP 621 Dependencies in pyproject.toml Source: https://github.com/osprey-oss/deptry/blob/main/docs/supported-dependency-managers.md Extracts regular and development dependencies defined using the PEP 621 standard in `pyproject.toml`. This includes dependencies from `[project]`, `[project.optional-dependencies]`, and `[dependency-groups]` sections. ```toml [project] name = "foo" dependencies = ["orjson>=3.0.0"] [project.optional-dependencies] cli = ["click>=8.0.0"] http = [ "httpx>=0.27.0", "uvicorn>=0.32.0", ] [dependency-groups] docs = ["mkdocs==1.6.1"] test = [ "pytest==8.3.3", "pytest-cov==5.0.0", ] ``` -------------------------------- ### Python 3.9 support dropped Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md Python 3.9 is no longer supported due to its end-of-life status. Ensure your project is using a supported Python version. ```text Support for Python 3.9 has been dropped, as it has reached its end of life. ``` -------------------------------- ### Map Package to Single Module Name in pyproject.toml Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Define a mapping in pyproject.toml to translate a package name to a single top-level module name, useful when names differ or packages are optional. ```toml [tool.deptry.package_module_name_map] foo-python = "foo" ``` -------------------------------- ### Configure Non-Dev Dependency Groups Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Specify dependency groups defined under `[dependency-groups]` in `pyproject.toml` that should be treated as regular dependencies, not development dependencies. ```toml [project] ... dependencies = ["httpx"] [dependency-groups] server = ["uvicorn"] telemetry = ["opentelemetry-sdk"] ``` ```toml [tool.deptry] non_dev_dependency_groups = ["server", "telemetry"] ``` -------------------------------- ### GitHub Actions Annotation Format Source: https://github.com/osprey-oss/deptry/blob/main/docs/configuration.md Dependency issues can be reported as GitHub Actions annotations for direct integration into CI/CD workflows. Violations are errors by default. ```shell ::error file=,line=,col=,title=:: ``` -------------------------------- ### Increase deptry Verbosity Source: https://github.com/osprey-oss/deptry/blob/main/docs/usage.md Use the --verbose flag to display more detailed information during the scanning process, including scanned Python files and identified imported modules. ```shell deptry . --verbose ``` -------------------------------- ### Ignore specific error codes with --ignore flag Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md Use the --ignore flag to specify exact error codes to ignore. This replaces older flags like --skip-unused. ```bash deptry . --ignore "DEP001,DEP002" ``` -------------------------------- ### Ignore Specific Violation Rules for Imports Source: https://github.com/osprey-oss/deptry/blob/main/docs/usage.md Shows how to ignore specific violation rules (e.g., DEP001, DEP003) for an import statement using an inline comment. ```python import foo # deptry: ignore[DEP001] import bar # deptry: ignore[DEP001,DEP003] ``` -------------------------------- ### PDM Development Dependencies in pyproject.toml Source: https://github.com/osprey-oss/deptry/blob/main/docs/supported-dependency-managers.md Extracts PDM development dependencies from the `[tool.pdm.dev-dependencies]` section in `pyproject.toml`. ```toml [tool.pdm.dev-dependencies] docs = ["mkdocs==1.6.1"] test = [ "pytest==8.3.3", "pytest-cov==5.0.0", ] ``` -------------------------------- ### Add Transitive Dependency Source: https://github.com/osprey-oss/deptry/blob/main/docs/rules-violations.md When a module is used but only available via another dependency, explicitly add it to `[project.dependencies]` to resolve DEP003. ```toml [project] dependencies = [ # Here `httpx` depends on `certifi` package. "httpx==0.23.1", ] ``` ```python import certifi import httpx def make_http_request(): return httpx.get("https://example.com") def get_certificates_location(): return certifi.where() ``` ```toml [project] dependencies = [ "certifi==2024.7.4", "httpx==0.23.1", ] ``` -------------------------------- ### Ignore files handling changes Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md Deptry's behavior for excluding files has been updated. Git-related ignore rules are now only used within Git repositories, and parent directory ignore files are no longer traversed by default. ```text Unless `--exclude` is used, _deptry_ excludes files found in common ignore files (`.gitignore`, `.ignore`, `$HOME/.config/git/ignore`. ...), by using `ignore` Rust crate. The default behaviour has been changed, so that now: - git-related ignore rules (`.gitignore`, `$HOME/.config/git/ignore`, ...) are only used if _deptry_ is run inside a git repository - `.gitignore` files that are in parent directories of the git repository from where deptry is run are not used (previously, _deptry_ would traverse parent directories up to the root system) If you were using `.gitignore` files for non-git repositories, you might want to switch to `.ignore` files, or use [`--extend-exclude`](https://deptry.com/usage/#extend-exclude). ``` -------------------------------- ### Configure ignored error codes in pyproject.toml Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md The 'ignore' key in pyproject.toml allows specifying error codes to ignore, superseding individual skip flags. ```toml [tool.deptry] skip_missing = true skip_unused = true ``` ```toml [tool.deptry] ignore = ["DEP001", "DEP002"] ``` -------------------------------- ### Configure ignored error codes in pyproject.toml Source: https://github.com/osprey-oss/deptry/blob/main/CHANGELOG.md Configure ignored error codes in the [tool.deptry] section of pyproject.toml. This replaces the older skip_* settings. ```toml [tool.deptry] ignore = ["DEP001", "DEP002"] ``` -------------------------------- ### Ignore Individual Import Statements Source: https://github.com/osprey-oss/deptry/blob/main/docs/usage.md Demonstrates how to ignore a specific import statement using an inline comment. This suppresses all violation rules for that import. ```python import foo # deptry: ignore ``` -------------------------------- ### Exclude Directories and Files with deptry Source: https://github.com/osprey-oss/deptry/blob/main/docs/usage.md Use the --exclude flag to specify directories or files to be ignored by deptry. This flag overwrites default exclusions and ignores .gitignore entries. ```shell deptry . --exclude bar --exclude ".*/foo/" deptry . --exclude "bar|.*/foo/" ``` -------------------------------- ### Remove Unused Dependency Source: https://github.com/osprey-oss/deptry/blob/main/docs/rules-violations.md If a dependency is listed but not imported in the codebase, remove it from `[project.dependencies]` to fix DEP002. ```toml [project] dependencies = [ "httpx==0.23.1", "requests==2.28.1", ] ``` ```python import httpx import requests def make_http_request(): return httpx.get("https://example.com") ``` ```toml [project] dependencies = ["httpx==0.23.1"] ``` -------------------------------- ### Extend Exclusions with deptry Source: https://github.com/osprey-oss/deptry/blob/main/docs/usage.md Use the --extend-exclude flag to add custom exclusions to the default set and still consider .gitignore entries. This is useful for maintaining default behavior while adding specific ignores. ```shell deptry . --extend-exclude bar --extend-exclude ".*/foo/" deptry . --extend-exclude "bar|.*/foo/" ``` -------------------------------- ### Ignore inline violations Source: https://github.com/osprey-oss/deptry/blob/main/docs/changelog.md Use inline comments to ignore specific dependency violations in your code. This is useful for cases where a violation is intentional or cannot be resolved. ```python import typing as t def my_function(x: int) -> str: # deptry: ignore return "hello" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.