|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | from pathlib import Path |
4 | | -from typing import TYPE_CHECKING |
5 | 4 |
|
6 | | -from usethis._config import usethis_config |
7 | 5 | from usethis._config_file import DotCodespellRCManager |
8 | 6 | from usethis._console import how_print |
9 | | -from usethis._file.pyproject_toml.errors import PyprojectTOMLNotFoundError |
10 | 7 | from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager |
11 | | -from usethis._file.pyproject_toml.requires_python import ( |
12 | | - MissingRequiresPythonError, |
13 | | - get_required_minor_python_versions, |
14 | | -) |
15 | 8 | from usethis._file.setup_cfg.io_ import SetupCFGManager |
16 | | -from usethis._integrations.pre_commit import schema as pre_commit_schema |
17 | | -from usethis._python.version import PythonVersion |
18 | | -from usethis._tool.base import Tool, ToolMeta, ToolSpec |
| 9 | +from usethis._tool.base import Tool |
19 | 10 | from usethis._tool.config import ConfigEntry, ConfigItem, ConfigSpec |
20 | | -from usethis._tool.pre_commit import PreCommitConfig |
21 | | -from usethis._types.deps import Dependency |
22 | | - |
23 | | -if TYPE_CHECKING: |
24 | | - from usethis._io import KeyValueFileManager |
25 | | - |
26 | | -_CODESPELL_VERSION = "v2.4.1" # Manually bump this version when necessary |
27 | | - |
28 | | - |
29 | | -class CodespellToolSpec(ToolSpec): |
30 | | - @property |
31 | | - def meta(self) -> ToolMeta: |
32 | | - return ToolMeta( |
33 | | - name="Codespell", |
34 | | - url="https://github.com/codespell-project/codespell", |
35 | | - managed_files=[Path(".codespellrc")], |
36 | | - ) |
37 | | - |
38 | | - def preferred_file_manager(self) -> KeyValueFileManager: |
39 | | - if (usethis_config.cpd() / "pyproject.toml").exists(): |
40 | | - return PyprojectTOMLManager() |
41 | | - return DotCodespellRCManager() |
42 | | - |
43 | | - def raw_cmd(self) -> str: |
44 | | - return "codespell" |
45 | | - |
46 | | - def dev_deps(self, *, unconditional: bool = False) -> list[Dependency]: |
47 | | - deps = [Dependency(name="codespell")] |
48 | | - |
49 | | - # Python < 3.11 needs tomli (instead of the stdlib tomllib) to read |
50 | | - # pyproject.toml files |
51 | | - if unconditional: |
52 | | - needs_tomli = True |
53 | | - else: |
54 | | - try: |
55 | | - versions = get_required_minor_python_versions() |
56 | | - except (MissingRequiresPythonError, PyprojectTOMLNotFoundError): |
57 | | - versions = [PythonVersion.from_interpreter()] |
58 | | - |
59 | | - needs_tomli = any(v.to_short_tuple() < (3, 11) for v in versions) |
60 | | - if needs_tomli: |
61 | | - deps.append(Dependency(name="tomli")) |
62 | | - |
63 | | - return deps |
64 | | - |
65 | | - def pre_commit_config(self) -> PreCommitConfig: |
66 | | - return PreCommitConfig.from_single_repo( |
67 | | - pre_commit_schema.UriRepo( |
68 | | - repo="https://github.com/codespell-project/codespell", |
69 | | - rev=_CODESPELL_VERSION, |
70 | | - hooks=[ |
71 | | - pre_commit_schema.HookDefinition( |
72 | | - id="codespell", additional_dependencies=["tomli"] |
73 | | - ) |
74 | | - ], |
75 | | - ), |
76 | | - requires_venv=False, |
77 | | - ) |
| 11 | +from usethis._tool.impl.spec.codespell import CodespellToolSpec |
78 | 12 |
|
79 | 13 |
|
80 | 14 | class CodespellTool(CodespellToolSpec, Tool): |
|
0 commit comments