-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add initial support for uv (#816)
* refactor(dependency): move `pep621` to `pep621.base` * refactor(dependency): move `pdm` to `pep621.pdm` * refactor(pep621): simplify logic * refactor(pep621): get dev dependencies from main `get` * refactor(pep621): remove useless argument for PEP 508 extraction * style(pdm): move misplaced dataclass attribute * feat(pep621): add uv dependency getter * feat(dependency): detect uv * test(functional): test against uv * docs: mention uv support * docs(uv): better document dev dependencies
- Loading branch information
1 parent
4e82f7a
commit 673086e
Showing
19 changed files
with
423 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING | ||
|
||
from deptry.dependency_getter.pep621.base import PEP621DependencyGetter | ||
from deptry.utils import load_pyproject_toml | ||
|
||
if TYPE_CHECKING: | ||
from deptry.dependency import Dependency | ||
|
||
|
||
@dataclass | ||
class UvDependencyGetter(PEP621DependencyGetter): | ||
""" | ||
Class to get dependencies that are specified according to PEP 621 from a `pyproject.toml` file for a project that | ||
uses uv for its dependency management. | ||
""" | ||
|
||
def _get_dev_dependencies(self, dev_dependencies_from_optional: list[Dependency]) -> list[Dependency]: | ||
""" | ||
Retrieve dev dependencies from pyproject.toml, which in uv are specified as: | ||
[tool.uv] | ||
dev-dependencies = [ | ||
"pytest==8.3.2", | ||
"pytest-cov==5.0.0", | ||
"tox", | ||
] | ||
Dev dependencies marked as such from optional dependencies are also added to the list of dev dependencies found. | ||
""" | ||
dev_dependencies = super()._get_dev_dependencies(dev_dependencies_from_optional) | ||
|
||
pyproject_data = load_pyproject_toml(self.config) | ||
|
||
dev_dependency_strings: list[str] = [] | ||
try: | ||
dev_dependency_strings = pyproject_data["tool"]["uv"]["dev-dependencies"] | ||
except KeyError: | ||
logging.debug("No section [tool.uv.dev-dependencies] found in pyproject.toml") | ||
|
||
return [*dev_dependencies, *self._extract_pep_508_dependencies(dev_dependency_strings)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[project] | ||
# PEP 621 project metadata | ||
# See https://www.python.org/dev/peps/pep-0621/ | ||
name = "foo" | ||
version = "0.0.1" | ||
requires-python = ">=3.8" | ||
dependencies = [ | ||
"pkginfo==1.11.1", | ||
"tomli==2.0.1", | ||
"urllib3==2.2.2", | ||
] | ||
|
||
[project.optional-dependencies] | ||
foo = [ | ||
"click==8.1.7", | ||
"isort==5.13.2", | ||
] | ||
bar = ["requests==2.32.3"] | ||
|
||
[tool.uv] | ||
dev-dependencies = [ | ||
"black==24.8.0", | ||
"mypy==1.11.1", | ||
"pytest==8.2.0", | ||
"pytest-cov==5.0.0", | ||
] | ||
|
||
[tool.deptry] | ||
pep621_dev_dependency_groups = ["bar"] | ||
|
||
[tool.deptry.per_rule_ignores] | ||
DEP002 = ["pkginfo"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from os import chdir, walk | ||
from pathlib import Path | ||
|
||
import black | ||
import click | ||
import mypy | ||
import pytest | ||
import pytest_cov | ||
import white as w | ||
from urllib3 import contrib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "9f4924ec-2200-4801-9d49-d4833651cbc4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import click\n", | ||
"from urllib3 import contrib\n", | ||
"import tomli" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.11" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.