Skip to content

Commit 9440232

Browse files
modernizing (#9)
* Added ruff * Updated tests, adding pdf latex engine
1 parent 3cc7298 commit 9440232

File tree

7 files changed

+60
-19
lines changed

7 files changed

+60
-19
lines changed

.github/workflows/ci.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
- name: Install dependencies
4040
run: uv sync --all-extras
4141
if: steps.cached-uv-dependencies.outputs.cache-hit != 'true'
42+
- name: Run ruff
43+
run: uv run ruff check
4244
- name: run tests
4345
run: uv run pytest -vv tests/*
4446

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ dependencies = []
3737
[tool.uv]
3838
dev-dependencies = [
3939
"pytest>=8.3.4",
40+
"ruff>=0.9.7",
4041
]

pytinytex/__init__.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import sys
22
import subprocess
3-
import glob
43
import os
4+
import platform
5+
from pathlib import Path
56

6-
from .tinytex_download import download_tinytex
7+
from .tinytex_download import download_tinytex # noqa
78

89
# Global cache
910
__tinytex_path = getattr(os.environ, "PYTINYTEX_TINYTEX", None)
@@ -28,6 +29,13 @@ def get_tinytex_path(base="."):
2829
raise RuntimeError("TinyTeX doesn't seem to be installed. You can install TinyTeX with pytinytex.download_tinytex().")
2930
return __tinytex_path
3031

32+
def get_pdf_latex_engine():
33+
if platform.system() == "Windows":
34+
return os.path.join(get_tinytex_path(), "pdflatex.exe")
35+
else:
36+
return os.path.join(get_tinytex_path(), "pdflatex")
37+
38+
3139
def ensure_tinytex_installed(path="."):
3240
global __tinytex_path
3341
error_path = None
@@ -39,15 +47,15 @@ def ensure_tinytex_installed(path="."):
3947
error_path = path
4048
__tinytex_path = _resolve_path(path)
4149
return True
42-
except RuntimeError as e:
50+
except RuntimeError:
4351
__tinytex_path = None
4452
raise RuntimeError("Unable to resolve TinyTeX path. Got as far as {}".format(error_path))
4553
return False
4654

4755
def _resolve_path(path="."):
4856
while True:
4957
if _check_file(path, "tlmgr"):
50-
return path
58+
return str(Path(path).resolve())
5159
new_path = ""
5260
list_dir = os.listdir(path)
5361
if "bin" in list_dir:
@@ -107,7 +115,7 @@ def _run_tlmgr_command(args, path, machine_readable=True):
107115
env=new_env,
108116
creationflags=creation_flag)
109117
# something else than 'None' indicates that the process already terminated
110-
if not (p.returncode is None):
118+
if p.returncode is not None:
111119
raise RuntimeError(
112120
'TLMGR died with exitcode "%s" before receiving input: %s' % (p.returncode,
113121
p.stderr.read())

pytinytex/tinytex_download.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _get_tinytex_urls(version, variation):
7474
response = urlopen(url)
7575
version_url_frags = response.url.split("/")
7676
version = version_url_frags[-1]
77-
except urllib.error.HTTPError as e:
77+
except urllib.error.HTTPError:
7878
raise RuntimeError("Invalid TinyTeX version {}.".format(version))
7979
return
8080
# read the HTML content

tests/test_tinytex_download.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import shutil
21
import os
32

4-
import pytest
3+
from .utils import download_tinytex # noqa
54

6-
from .utils import download_tinytex
7-
8-
def test_successful_download(download_tinytex):
5+
def test_successful_download(download_tinytex): # noqa
96
assert os.path.isdir(os.path.join("tests", "tinytex_distribution"))
107

11-
def test_bin_is_in_distribution(download_tinytex):
8+
def test_bin_is_in_distribution(download_tinytex): # noqa
129
assert os.path.isdir(os.path.join("tests", "tinytex_distribution", "bin"))

tests/test_tinytex_path_resolver.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import os
22
import pytest
33

4-
from .utils import download_tinytex
5-
64
import pytinytex
5+
from .utils import download_tinytex # noqa
76

8-
def test_empty_cache(download_tinytex):
7+
def test_empty_cache(download_tinytex): # noqa
98
assert pytinytex.__tinytex_path is None
109

11-
def test_failing_resolver(download_tinytex):
10+
def test_failing_resolver(download_tinytex): # noqa
1211
assert pytinytex.__tinytex_path is None
1312
with pytest.raises(RuntimeError):
1413
pytinytex._resolve_path("failing")
@@ -17,13 +16,18 @@ def test_failing_resolver(download_tinytex):
1716
pytinytex.ensure_tinytex_installed("failing")
1817
assert pytinytex.__tinytex_path is None
1918

20-
def test_successful_resolver(download_tinytex):
19+
def test_successful_resolver(download_tinytex): # noqa
2120
assert pytinytex.__tinytex_path is None
2221
pytinytex.ensure_tinytex_installed("tests")
2322
assert isinstance(pytinytex.__tinytex_path, str)
2423
assert os.path.isdir(pytinytex.__tinytex_path)
2524

26-
def test_get_tinytex_path(download_tinytex):
25+
def test_get_tinytex_path(download_tinytex): # noqa
2726
pytinytex.ensure_tinytex_installed("tests")
2827
assert isinstance(pytinytex.get_tinytex_path(), str)
2928
assert pytinytex.__tinytex_path == pytinytex.get_tinytex_path("tests")
29+
30+
def get_pdf_latex_engine(download_tinytex): # noqa
31+
pytinytex.ensure_tinytex_installed("tests")
32+
assert isinstance(pytinytex.get_pdf_latex_engine(), str)
33+
assert os.path.isfile(pytinytex.get_pdf_latex_engine())

uv.lock

+30-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)