Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type package. #16

Merged
merged 2 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,21 @@ repos:
rev: v2.1.0
hooks:
- id: codespell
args: [-L bringin, -L unparseable]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.931'
hooks:
- id: mypy
args: [
--no-strict-optional,
--ignore-missing-imports,
]
additional_dependencies: [
types-attrs,
types-click,
types-setuptools
]
pass_filenames: false
language_version: "3.9"
- repo: https://github.com/mgedmin/check-manifest
rev: "0.47"
hooks:
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ in reverse chronological order. Releases follow `semantic versioning

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


0.0.4 - 2021-08-08
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
prune .conda
prune tests

recursive-include src py.typed

exclude *.rst
exclude *.yml
exclude *.yaml
Expand Down
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,20 @@ requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"]

[tool.setuptools_scm]
write_to = "src/latex_dependency_scanner/_version.py"


[tool.mypy]
files = ["src", "tests"]
check_untyped_defs = true
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true


[[tool.mypy.overrides]]
module = "tests.*"
disallow_untyped_defs = false
ignore_errors = true
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ zip_safe = False

[options.packages.find]
where = src

[check-manifest]
ignore =
src/latex_dependency_scanner/_version.py
5 changes: 3 additions & 2 deletions src/latex_dependency_scanner/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import shutil
import subprocess
from pathlib import Path
from subprocess import CompletedProcess


DEFAULT_OPTIONS = ["--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd"]
Expand All @@ -19,7 +20,7 @@ def compile_pdf(
latex_document: Path,
compiled_document: Path | None = None,
args: list[str] | None = None,
):
) -> CompletedProcess[bytes]:
"""Generate a PDF from LaTeX document."""
if shutil.which("latexmk") is None:
raise RuntimeError("'latexmk' must be on PATH to compile a LaTeX document.")
Expand All @@ -32,7 +33,7 @@ def _prepare_cmd_options(
latex_document: Path,
compiled_document: Path | None = None,
args: list[str] | None = None,
):
) -> list[str]:
"""Prepare the command line arguments to compile the LaTeX document.

The output folder needs to be declared as a relative path to the directory where the
Expand Down
Empty file.
11 changes: 6 additions & 5 deletions src/latex_dependency_scanner/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
from os.path import splitext
from pathlib import Path
from typing import Generator


COMMON_TEX_EXTENSIONS = [".ltx", ".tex"]
Expand Down Expand Up @@ -47,7 +48,7 @@
document."""


def scan(paths: Path | list[Path]):
def scan(paths: Path | list[Path]) -> list[Path]:
"""Scan the documents provided as paths for included files.
Parameters
Expand All @@ -60,7 +61,7 @@ def scan(paths: Path | list[Path]):
paths = [paths]
paths = [Path(p) for p in paths]

nodes = []
nodes: list[Path] = []
for node in paths:
for node_ in yield_nodes_from_node(node, nodes):
nodes.append(node_)
Expand All @@ -72,7 +73,7 @@ def yield_nodes_from_node(
node: Path,
nodes: list[Path],
relative_to: Path | None = None,
):
) -> Generator[Path, None, None]:
r"""Yield nodes from node.
Nodes are references to other files inside a LaTeX document.
Expand Down Expand Up @@ -164,10 +165,10 @@ def yield_nodes_from_node(
break

if not found_some_file:
possible_paths = [
possible_paths = (
(relative_to / path).resolve().with_suffix(suffix)
if suffix
else (relative_to / path).resolve()
for suffix in common_extensions
]
)
yield from possible_paths
Empty file added tests/__init__.py
Empty file.
5 changes: 3 additions & 2 deletions tests/test_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import textwrap

import pytest
from conftest import needs_latexmk
from conftest import TEST_RESOURCES
from latex_dependency_scanner.compile import compile_pdf
from latex_dependency_scanner.scanner import COMMON_GRAPHICS_EXTENSIONS
from latex_dependency_scanner.scanner import scan

from tests.conftest import needs_latexmk
from tests.conftest import TEST_RESOURCES


@needs_latexmk
@pytest.mark.end_to_end
Expand Down