Skip to content

Commit

Permalink
A few small updates as per the changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
stumpylog committed Nov 13, 2023
1 parent 9d17d5e commit 530aa39
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/gotenberg_client/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -44,7 +47,7 @@ def __exit__(
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
) -> None:
self.reset()
self.close()

def reset(self) -> None:
"""
Expand Down Expand Up @@ -103,19 +106,19 @@ 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
"""
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

Expand Down
3 changes: 2 additions & 1 deletion src/gotenberg_client/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/gotenberg_client/_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:])
Expand Down
6 changes: 3 additions & 3 deletions tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit 530aa39

Please sign in to comment.