From 530aa3958867803864e8eec82d384c3a34a0bcba Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Mon, 13 Nov 2023 14:12:32 -0800 Subject: [PATCH] A few small updates as per the changelog --- .pre-commit-config.yaml | 6 +++--- CHANGELOG.md | 8 ++++++++ pyproject.toml | 16 +++++++++++----- src/gotenberg_client/_base.py | 11 +++++++---- src/gotenberg_client/_client.py | 3 ++- src/gotenberg_client/_health.py | 4 ++-- tests/test_merge.py | 6 +++--- 7 files changed, 36 insertions(+), 18 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a50d88d..6a4c9c1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,7 +27,7 @@ repos: - id: check-case-conflict - id: detect-private-key - repo: https://github.com/pre-commit/mirrors-prettier - rev: 'v3.0.3' + rev: 'v3.1.0' hooks: - id: prettier types_or: @@ -37,10 +37,10 @@ repos: exclude: "(^Pipfile\\.lock$)" # Python hooks - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.1.0' + rev: 'v0.1.5' hooks: - id: ruff - repo: https://github.com/psf/black - rev: 23.10.0 + rev: 23.11.0 hooks: - id: black diff --git a/CHANGELOG.md b/CHANGELOG.md index 016a814..f6bdb38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Changed + +- Removed some certain special cases from coverage +- Updated `pre-commit` hook versions +- Updated how pytest is configured, so it will apply to any invocation + ## [0.3.0] - 2023-10-17 ### Added diff --git a/pyproject.toml b/pyproject.toml index 5434bf7..db81536 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,9 +28,10 @@ classifiers = [ "Programming Language :: Python :: Implementation :: PyPy", ] dependencies = [ - "httpx[http2] ~= 0.24", + "httpx[http2] ~= 0.25; python_version >= '3.9'", + "httpx[http2] ~= 0.24; python_version < '3.9'", "typing-extensions; python_version < '3.11'" - ] +] [project.urls] Documentation = "https://github.com/stumpylog/gotenberg-client/#readme" @@ -64,8 +65,8 @@ dependencies = [ [tool.hatch.envs.default.scripts] version = "python3 --version" pip-list = "pip list" -test = "pytest --pythonwarnings=all {args:tests}" -test-cov = "coverage run -m pytest --pythonwarnings=all {args:tests}" +test = "pytest {args:tests}" +test-cov = "coverage run -m pytest {args:tests}" cov-clear = "coverage erase" cov-report = [ "- coverage combine", @@ -207,6 +208,11 @@ ban-relative-imports = "all" # Tests can use magic values, assertions, and relative imports "tests/**/*" = ["PLR2004", "S101", "TID252"] +[tool.pytest.ini_options] +minversion = "7.0" +testpaths = ["tests"] +addopts = "--pythonwarnings=all" + [tool.coverage.run] source_pkgs = ["gotenberg_client", "tests"] branch = true @@ -235,7 +241,7 @@ exclude = [ "tests/test_convert_chromium_url.py", "tests/test_convert_chromium_markdown.py", "tests/conftest.py", - ] +] disallow_any_expr = true disallow_untyped_defs = true disallow_incomplete_defs = true diff --git a/src/gotenberg_client/_base.py b/src/gotenberg_client/_base.py index 1701039..42aa930 100644 --- a/src/gotenberg_client/_base.py +++ b/src/gotenberg_client/_base.py @@ -30,8 +30,11 @@ def __init__(self, client: Client, api_route: str) -> None: self._client = client self._route = api_route self._stack = ExitStack() + # These are the options that will be set to Gotenberg. Things like PDF/A self._form_data: Dict[str, str] = {} + # These are the names of files, mapping to their Path self._file_map: Dict[str, Path] = {} + # Any header that will also be sent self._headers: Dict[str, str] = {} def __enter__(self) -> Self: @@ -44,7 +47,7 @@ def __exit__( exc_val: Optional[BaseException], exc_tb: Optional[TracebackType], ) -> None: - self.reset() + self.close() def reset(self) -> None: """ @@ -103,7 +106,7 @@ def _add_file_map(self, filepath: Path, name: Optional[str] = None) -> None: logger.warning(f"{name} has already been provided, overwriting anyway") self._file_map[name] = filepath - def pdf_format(self, pdf_format: PdfAFormat) -> "BaseRoute": + def pdf_format(self, pdf_format: PdfAFormat) -> Self: """ All routes provide the option to configure the output PDF as a PDF/A format @@ -111,11 +114,11 @@ def pdf_format(self, pdf_format: PdfAFormat) -> "BaseRoute": self._form_data.update(pdf_format.to_form()) return self - def trace(self, trace_id: str) -> "BaseRoute": + def trace(self, trace_id: str) -> Self: self._headers["Gotenberg-Trace"] = trace_id return self - def output_name(self, filename: str) -> "BaseRoute": + def output_name(self, filename: str) -> Self: self._headers["Gotenberg-Output-Filename"] = filename return self diff --git a/src/gotenberg_client/_client.py b/src/gotenberg_client/_client.py index fc54e2e..9068dad 100644 --- a/src/gotenberg_client/_client.py +++ b/src/gotenberg_client/_client.py @@ -14,6 +14,7 @@ from gotenberg_client._convert.pdfa import PdfAApi from gotenberg_client._health import HealthCheckApi from gotenberg_client._merge import MergeApi +from gotenberg_client._types_compat import Self class GotenbergClient: @@ -49,7 +50,7 @@ def add_headers(self, header: Dict[str, str]) -> None: # pragma: no cover """ self._client.headers.update(header) - def __enter__(self) -> "GotenbergClient": + def __enter__(self) -> Self: return self def close(self) -> None: diff --git a/src/gotenberg_client/_health.py b/src/gotenberg_client/_health.py index 479ee74..3fd87ec 100644 --- a/src/gotenberg_client/_health.py +++ b/src/gotenberg_client/_health.py @@ -86,7 +86,7 @@ def _extract_status(self, module: ModuleOptions) -> ModuleStatus: @no_type_check def _extract_datetime(timestamp: str) -> datetime.datetime: m = _TIME_RE.match(timestamp) - if not m: + if not m: # pragma: no cover msg = f"Unable to parse {timestamp}" raise ValueError(msg) @@ -97,7 +97,7 @@ def _extract_datetime(timestamp: str) -> datetime.datetime: if timezone_str is not None: if timezone_str.lower() == "z": tzinfo = datetime.timezone.utc - else: + else: # pragma: no cover multi = -1 if timezone_str[0:1] == "-" else 1 hours = int(timezone_str[1:3]) minutes = int(timezone_str[4:]) diff --git a/tests/test_merge.py b/tests/test_merge.py index 49be37a..7b3187d 100644 --- a/tests/test_merge.py +++ b/tests/test_merge.py @@ -51,11 +51,11 @@ def test_merge_multiple_file( self, client: GotenbergClient, ): - if shutil.which("pdftotext") is None: + if shutil.which("pdftotext") is None: # pragma: no cover pytest.skip("No pdftotext executable found") else: with client.merge.merge() as route: - # By default, these would not merge correctly + # By default, these would not merge correctly, as it happens alphabetically route.merge([SAMPLE_DIR / "z_first_merge.pdf", SAMPLE_DIR / "a_merge_second.pdf"]) resp = call_run_with_server_error_handling(route) @@ -66,7 +66,7 @@ def test_merge_multiple_file( with tempfile.NamedTemporaryFile(mode="wb") as tmp: tmp.write(resp.content) - text = extract_text(tmp.name) + text = extract_text(Path(tmp.name)) lines = text.split("\n") # Extra is empty line assert len(lines) == 3