Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
- name: Install dependencies
run: uv sync --all-extras
if: steps.cached-uv-dependencies.outputs.cache-hit != 'true'
- name: Run ruff
run: uv run ruff check
- name: run tests
run: uv run pytest -vv tests/*

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ dependencies = []
[tool.uv]
dev-dependencies = [
"pytest>=8.3.4",
"ruff>=0.9.7",
]
18 changes: 13 additions & 5 deletions pytinytex/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import sys
import subprocess
import glob
import os
import platform
from pathlib import Path

from .tinytex_download import download_tinytex
from .tinytex_download import download_tinytex # noqa

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

def get_pdf_latex_engine():
if platform.system() == "Windows":
return os.path.join(get_tinytex_path(), "pdflatex.exe")
else:
return os.path.join(get_tinytex_path(), "pdflatex")


def ensure_tinytex_installed(path="."):
global __tinytex_path
error_path = None
Expand All @@ -39,15 +47,15 @@ def ensure_tinytex_installed(path="."):
error_path = path
__tinytex_path = _resolve_path(path)
return True
except RuntimeError as e:
except RuntimeError:
__tinytex_path = None
raise RuntimeError("Unable to resolve TinyTeX path. Got as far as {}".format(error_path))
return False

def _resolve_path(path="."):
while True:
if _check_file(path, "tlmgr"):
return path
return str(Path(path).resolve())
new_path = ""
list_dir = os.listdir(path)
if "bin" in list_dir:
Expand Down Expand Up @@ -107,7 +115,7 @@ def _run_tlmgr_command(args, path, machine_readable=True):
env=new_env,
creationflags=creation_flag)
# something else than 'None' indicates that the process already terminated
if not (p.returncode is None):
if p.returncode is not None:
raise RuntimeError(
'TLMGR died with exitcode "%s" before receiving input: %s' % (p.returncode,
p.stderr.read())
Expand Down
2 changes: 1 addition & 1 deletion pytinytex/tinytex_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _get_tinytex_urls(version, variation):
response = urlopen(url)
version_url_frags = response.url.split("/")
version = version_url_frags[-1]
except urllib.error.HTTPError as e:
except urllib.error.HTTPError:
raise RuntimeError("Invalid TinyTeX version {}.".format(version))
return
# read the HTML content
Expand Down
9 changes: 3 additions & 6 deletions tests/test_tinytex_download.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import shutil
import os

import pytest
from .utils import download_tinytex # noqa

from .utils import download_tinytex

def test_successful_download(download_tinytex):
def test_successful_download(download_tinytex): # noqa
assert os.path.isdir(os.path.join("tests", "tinytex_distribution"))

def test_bin_is_in_distribution(download_tinytex):
def test_bin_is_in_distribution(download_tinytex): # noqa
assert os.path.isdir(os.path.join("tests", "tinytex_distribution", "bin"))
16 changes: 10 additions & 6 deletions tests/test_tinytex_path_resolver.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import os
import pytest

from .utils import download_tinytex

import pytinytex
from .utils import download_tinytex # noqa

def test_empty_cache(download_tinytex):
def test_empty_cache(download_tinytex): # noqa
assert pytinytex.__tinytex_path is None

def test_failing_resolver(download_tinytex):
def test_failing_resolver(download_tinytex): # noqa
assert pytinytex.__tinytex_path is None
with pytest.raises(RuntimeError):
pytinytex._resolve_path("failing")
Expand All @@ -17,13 +16,18 @@ def test_failing_resolver(download_tinytex):
pytinytex.ensure_tinytex_installed("failing")
assert pytinytex.__tinytex_path is None

def test_successful_resolver(download_tinytex):
def test_successful_resolver(download_tinytex): # noqa
assert pytinytex.__tinytex_path is None
pytinytex.ensure_tinytex_installed("tests")
assert isinstance(pytinytex.__tinytex_path, str)
assert os.path.isdir(pytinytex.__tinytex_path)

def test_get_tinytex_path(download_tinytex):
def test_get_tinytex_path(download_tinytex): # noqa
pytinytex.ensure_tinytex_installed("tests")
assert isinstance(pytinytex.get_tinytex_path(), str)
assert pytinytex.__tinytex_path == pytinytex.get_tinytex_path("tests")

def get_pdf_latex_engine(download_tinytex): # noqa
pytinytex.ensure_tinytex_installed("tests")
assert isinstance(pytinytex.get_pdf_latex_engine(), str)
assert os.path.isfile(pytinytex.get_pdf_latex_engine())
31 changes: 30 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading