Skip to content

Commit 8712593

Browse files
authored
Type package. (#16)
1 parent 87c63ad commit 8712593

File tree

10 files changed

+51
-10
lines changed

10 files changed

+51
-10
lines changed

.pre-commit-config.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,21 @@ repos:
7777
rev: v2.1.0
7878
hooks:
7979
- id: codespell
80-
args: [-L bringin, -L unparseable]
80+
- repo: https://github.com/pre-commit/mirrors-mypy
81+
rev: 'v0.931'
82+
hooks:
83+
- id: mypy
84+
args: [
85+
--no-strict-optional,
86+
--ignore-missing-imports,
87+
]
88+
additional_dependencies: [
89+
types-attrs,
90+
types-click,
91+
types-setuptools
92+
]
93+
pass_filenames: false
94+
language_version: "3.9"
8195
- repo: https://github.com/mgedmin/check-manifest
8296
rev: "0.47"
8397
hooks:

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ in reverse chronological order. Releases follow `semantic versioning
1313

1414
- :gh:`14` skips concurrent CI builds.
1515
- :gh:`15` deprecates Python 3.6 and enables Python 3.10.
16+
- :gh:`16` type package and publish types.
1617

1718

1819
0.0.4 - 2021-08-08

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
prune .conda
22
prune tests
33

4+
recursive-include src py.typed
5+
46
exclude *.rst
57
exclude *.yml
68
exclude *.yaml

pyproject.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,20 @@ requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"]
44

55
[tool.setuptools_scm]
66
write_to = "src/latex_dependency_scanner/_version.py"
7+
8+
9+
[tool.mypy]
10+
files = ["src", "tests"]
11+
check_untyped_defs = true
12+
disallow_any_generics = true
13+
disallow_incomplete_defs = true
14+
disallow_untyped_defs = true
15+
no_implicit_optional = true
16+
warn_redundant_casts = true
17+
warn_unused_ignores = true
18+
19+
20+
[[tool.mypy.overrides]]
21+
module = "tests.*"
22+
disallow_untyped_defs = false
23+
ignore_errors = true

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ zip_safe = False
3434

3535
[options.packages.find]
3636
where = src
37+
38+
[check-manifest]
39+
ignore =
40+
src/latex_dependency_scanner/_version.py

src/latex_dependency_scanner/compile.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import shutil
1111
import subprocess
1212
from pathlib import Path
13+
from subprocess import CompletedProcess
1314

1415

1516
DEFAULT_OPTIONS = ["--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd"]
@@ -19,7 +20,7 @@ def compile_pdf(
1920
latex_document: Path,
2021
compiled_document: Path | None = None,
2122
args: list[str] | None = None,
22-
):
23+
) -> CompletedProcess[bytes]:
2324
"""Generate a PDF from LaTeX document."""
2425
if shutil.which("latexmk") is None:
2526
raise RuntimeError("'latexmk' must be on PATH to compile a LaTeX document.")
@@ -32,7 +33,7 @@ def _prepare_cmd_options(
3233
latex_document: Path,
3334
compiled_document: Path | None = None,
3435
args: list[str] | None = None,
35-
):
36+
) -> list[str]:
3637
"""Prepare the command line arguments to compile the LaTeX document.
3738
3839
The output folder needs to be declared as a relative path to the directory where the

src/latex_dependency_scanner/py.typed

Whitespace-only changes.

src/latex_dependency_scanner/scanner.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
from os.path import splitext
66
from pathlib import Path
7+
from typing import Generator
78

89

910
COMMON_TEX_EXTENSIONS = [".ltx", ".tex"]
@@ -47,7 +48,7 @@
4748
document."""
4849

4950

50-
def scan(paths: Path | list[Path]):
51+
def scan(paths: Path | list[Path]) -> list[Path]:
5152
"""Scan the documents provided as paths for included files.
5253
5354
Parameters
@@ -60,7 +61,7 @@ def scan(paths: Path | list[Path]):
6061
paths = [paths]
6162
paths = [Path(p) for p in paths]
6263

63-
nodes = []
64+
nodes: list[Path] = []
6465
for node in paths:
6566
for node_ in yield_nodes_from_node(node, nodes):
6667
nodes.append(node_)
@@ -72,7 +73,7 @@ def yield_nodes_from_node(
7273
node: Path,
7374
nodes: list[Path],
7475
relative_to: Path | None = None,
75-
):
76+
) -> Generator[Path, None, None]:
7677
r"""Yield nodes from node.
7778
7879
Nodes are references to other files inside a LaTeX document.
@@ -164,10 +165,10 @@ def yield_nodes_from_node(
164165
break
165166

166167
if not found_some_file:
167-
possible_paths = [
168+
possible_paths = (
168169
(relative_to / path).resolve().with_suffix(suffix)
169170
if suffix
170171
else (relative_to / path).resolve()
171172
for suffix in common_extensions
172-
]
173+
)
173174
yield from possible_paths

tests/__init__.py

Whitespace-only changes.

tests/test_scan.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
import textwrap
55

66
import pytest
7-
from conftest import needs_latexmk
8-
from conftest import TEST_RESOURCES
97
from latex_dependency_scanner.compile import compile_pdf
108
from latex_dependency_scanner.scanner import COMMON_GRAPHICS_EXTENSIONS
119
from latex_dependency_scanner.scanner import scan
1210

11+
from tests.conftest import needs_latexmk
12+
from tests.conftest import TEST_RESOURCES
13+
1314

1415
@needs_latexmk
1516
@pytest.mark.end_to_end

0 commit comments

Comments
 (0)