Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.

Commit 88590f6

Browse files
committed
initialize rendercv-tinytex
0 parents  commit 88590f6

File tree

4,011 files changed

+427290
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,011 files changed

+427290
-0
lines changed

.gitignore

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# UV
98+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
#uv.lock
102+
103+
# poetry
104+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105+
# This is especially recommended for binary packages to ensure reproducibility, and is more
106+
# commonly ignored for libraries.
107+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108+
#poetry.lock
109+
110+
# pdm
111+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112+
#pdm.lock
113+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114+
# in version control.
115+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116+
.pdm.toml
117+
.pdm-python
118+
.pdm-build/
119+
120+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121+
__pypackages__/
122+
123+
# Celery stuff
124+
celerybeat-schedule
125+
celerybeat.pid
126+
127+
# SageMath parsed files
128+
*.sage.py
129+
130+
# Environments
131+
.env
132+
.venv
133+
env/
134+
venv/
135+
ENV/
136+
env.bak/
137+
venv.bak/
138+
139+
# Spyder project settings
140+
.spyderproject
141+
.spyproject
142+
143+
# Rope project settings
144+
.ropeproject
145+
146+
# mkdocs documentation
147+
/site
148+
149+
# mypy
150+
.mypy_cache/
151+
.dmypy.json
152+
dmypy.json
153+
154+
# Pyre type checker
155+
.pyre/
156+
157+
# pytype static type analyzer
158+
.pytype/
159+
160+
# Cython debug symbols
161+
cython_debug/
162+
163+
# PyCharm
164+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166+
# and can be added to the global gitignore or merged into this file. For a more nuclear
167+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
168+
#.idea/
169+
170+
# PyPI configuration file
171+
.pypirc

pyproject.toml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
[build-system]
2+
requires = ["hatchling==1.26.3"]
3+
build-backend = "hatchling.build"
4+
5+
[tool.hatch.build.targets.wheel]
6+
# In wheel, what do we want to include and exclude?
7+
packages = ["rendercv_tinytex"]
8+
9+
[tool.hatch.version]
10+
path = "rendercv_tinytex/__init__.py"
11+
12+
[project]
13+
name = 'rendercv_tinytex'
14+
authors = [{ name = 'Sina Atalay', email = '[email protected]' }]
15+
description = 'A TinyTeX distribution for RenderCV'
16+
license = "MIT"
17+
readme = "README.md"
18+
requires-python = '>=3.10'
19+
classifiers = [
20+
"Intended Audience :: Science/Research",
21+
"Intended Audience :: Education",
22+
]
23+
dynamic = ["version"]
24+
25+
[project.urls]
26+
Source = 'https://github.com/rendercv/rendercv-tinytex'
27+
28+
# ======================================================================================
29+
# Virtual Environments Below ===========================================================
30+
# ======================================================================================
31+
32+
[tool.hatch.envs.default]
33+
installer = "uv"
34+
python = "3.13"
35+
dependencies = [
36+
"ruff", # to lint and format the code
37+
"black", # to format the code
38+
"ipython", # for ipython shell
39+
"pyright", # to check the types
40+
"pytest", # for testing
41+
]
42+
[tool.hatch.envs.default.scripts]
43+
format = "ruff check --fix && ruff format && black rendercv_tinytex" # hatch run format
44+
lint = "ruff check" # hatch run lint
45+
check-types = "pyright rendercv_tinytex" # hatch run check-types
46+
test = "pytest tests" # hatch run test
47+
48+
49+
# ======================================================================================
50+
# Virtual Environments Above ===========================================================
51+
# ======================================================================================
52+
53+
[tool.ruff]
54+
exclude = ["tinytex-release"]
55+
line-length = 88
56+
57+
[tool.ruff.format]
58+
docstring-code-format = true
59+
60+
[tool.ruff.lint]
61+
extend-select = [
62+
"B", # flake8-bugbear
63+
"I", # isort
64+
"ARG", # flake8-unused-arguments
65+
"C4", # flake8-comprehensions
66+
"EM", # flake8-errmsg
67+
"ICN", # flake8-import-conventions
68+
"ISC", # flake8-implicit-str-concat
69+
"G", # flake8-logging-format
70+
"PGH", # pygrep-hooks
71+
"PIE", # flake8-pie
72+
"PL", # pylint
73+
"PT", # flake8-pytest-style
74+
"PTH", # flake8-use-pathlib
75+
"RET", # flake8-return
76+
"RUF", # Ruff-specific
77+
"SIM", # flake8-simplify
78+
"T20", # flake8-print
79+
"UP", # pyupgrade
80+
"YTT", # flake8-2020
81+
"EXE", # flake8-executable
82+
"NPY", # NumPy specific rules
83+
"PD", # pandas-vet
84+
]
85+
ignore = [
86+
"PLR", # Design related pylint codes
87+
"ISC001", # Conflicts with formatter
88+
"UP007", # I like Optional type
89+
"PGH003", # It would be nice to not ignore this
90+
]
91+
flake8-unused-arguments.ignore-variadic-names = true
92+
93+
[tool.black]
94+
line-length = 88 # maximum line length
95+
preview = true # to allow enable-unstable-feature
96+
enable-unstable-feature = [
97+
"string_processing",
98+
] # to break strings into multiple lines
99+
exclude = "tinytex-release" # don't format the files in this folder
100+
101+
[tool.pyright]
102+
ignore = ["**/tinytex-release/"]

rendercv_tinytex/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
A TinyTeX distribution for RenderCV.
3+
"""
4+
5+
__version__ = "0.1.0"
6+
7+
from .run import run_pdftex
8+
9+
__all__ = ["run_pdftex"]

rendercv_tinytex/run.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import pathlib
2+
import subprocess
3+
import sys
4+
5+
6+
def run_pdftex(latex_file_path: pathlib.Path) -> pathlib.Path:
7+
"""Run TinyTeX with the given $\\LaTeX$ file to render the PDF.
8+
9+
Args:
10+
latex_file_path: The path to the $\\LaTeX$ file.
11+
12+
Returns:
13+
The path to the rendered PDF file.
14+
"""
15+
# check if the file exists:
16+
if not latex_file_path.is_file():
17+
message = f"The file {latex_file_path} doesn't exist!"
18+
raise FileNotFoundError(message)
19+
20+
tinytex_binaries_directory = (
21+
pathlib.Path(__file__).parent / "tinytex-release" / "TinyTeX" / "bin"
22+
)
23+
24+
executables = {
25+
"win32": tinytex_binaries_directory / "windows" / "pdflatex.exe",
26+
"linux": tinytex_binaries_directory / "x86_64-linux" / "pdflatex",
27+
"darwin": tinytex_binaries_directory / "universal-darwin" / "pdflatex",
28+
}
29+
30+
if sys.platform not in executables:
31+
message = f"TinyTeX doesn't support the platform {sys.platform}!"
32+
raise OSError(message)
33+
34+
executable = executables[sys.platform]
35+
36+
# Before running LaTeX, make sure the PDF file is not open in another program,
37+
# that wouldn't allow LaTeX to write to it. Remove the PDF file if it exists,
38+
# if it's not removable, then raise an error:
39+
pdf_file_path = latex_file_path.with_suffix(".pdf")
40+
if pdf_file_path.is_file():
41+
try:
42+
pdf_file_path.unlink()
43+
except PermissionError as e:
44+
message = (
45+
f"The PDF file {pdf_file_path} is open in another program and doesn't"
46+
" allow RenderCV to rewrite it. Please close the PDF file."
47+
)
48+
raise RuntimeError(message) from e
49+
50+
# Run LaTeX to render the PDF:
51+
command = [
52+
executable,
53+
str(latex_file_path.absolute()),
54+
]
55+
with subprocess.Popen(
56+
command,
57+
cwd=latex_file_path.parent,
58+
stdout=subprocess.PIPE, # capture the output
59+
stderr=subprocess.DEVNULL, # don't capture the error
60+
stdin=subprocess.DEVNULL, # don't allow LaTeX to ask for user input
61+
) as latex_process:
62+
output = latex_process.communicate() # wait for the process to finish
63+
if latex_process.returncode != 0:
64+
latex_file_path_log = latex_file_path.with_suffix(".log").read_text()
65+
66+
message = (
67+
"Failed to render the PDF file. Check out the details in the log file:"
68+
f" {latex_file_path.with_suffix('.log')} \n\n"
69+
" It is also printed below:\n\n"
70+
)
71+
message = message + latex_file_path_log
72+
raise RuntimeError(message)
73+
74+
try:
75+
output = output[0].decode("utf-8")
76+
except UnicodeDecodeError:
77+
output = output[0].decode("latin-1")
78+
79+
if "Rerun to get" in output:
80+
# Run TinyTeX again to get the references right:
81+
subprocess.run(
82+
command,
83+
cwd=latex_file_path.parent,
84+
stdout=subprocess.DEVNULL, # don't capture the output
85+
stderr=subprocess.DEVNULL, # don't capture the error
86+
stdin=subprocess.DEVNULL, # don't allow TinyTeX to ask for user input
87+
check=True,
88+
)
89+
90+
return pdf_file_path
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TinyTeX/texmf-var/luatex-cache/
2+
recycle_bin/
3+
download_and_minimize_tinytex_for_rendercv.log

0 commit comments

Comments
 (0)