Skip to content

Commit

Permalink
initialize rendercv-tinytex
Browse files Browse the repository at this point in the history
  • Loading branch information
sinaatalay committed Dec 25, 2024
0 parents commit 88590f6
Show file tree
Hide file tree
Showing 4,011 changed files with 427,290 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
171 changes: 171 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# PyPI configuration file
.pypirc
102 changes: 102 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[build-system]
requires = ["hatchling==1.26.3"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
# In wheel, what do we want to include and exclude?
packages = ["rendercv_tinytex"]

[tool.hatch.version]
path = "rendercv_tinytex/__init__.py"

[project]
name = 'rendercv_tinytex'
authors = [{ name = 'Sina Atalay', email = '[email protected]' }]
description = 'A TinyTeX distribution for RenderCV'
license = "MIT"
readme = "README.md"
requires-python = '>=3.10'
classifiers = [
"Intended Audience :: Science/Research",
"Intended Audience :: Education",
]
dynamic = ["version"]

[project.urls]
Source = 'https://github.com/rendercv/rendercv-tinytex'

# ======================================================================================
# Virtual Environments Below ===========================================================
# ======================================================================================

[tool.hatch.envs.default]
installer = "uv"
python = "3.13"
dependencies = [
"ruff", # to lint and format the code
"black", # to format the code
"ipython", # for ipython shell
"pyright", # to check the types
"pytest", # for testing
]
[tool.hatch.envs.default.scripts]
format = "ruff check --fix && ruff format && black rendercv_tinytex" # hatch run format
lint = "ruff check" # hatch run lint
check-types = "pyright rendercv_tinytex" # hatch run check-types
test = "pytest tests" # hatch run test


# ======================================================================================
# Virtual Environments Above ===========================================================
# ======================================================================================

[tool.ruff]
exclude = ["tinytex-release"]
line-length = 88

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
"EM", # flake8-errmsg
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"G", # flake8-logging-format
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"T20", # flake8-print
"UP", # pyupgrade
"YTT", # flake8-2020
"EXE", # flake8-executable
"NPY", # NumPy specific rules
"PD", # pandas-vet
]
ignore = [
"PLR", # Design related pylint codes
"ISC001", # Conflicts with formatter
"UP007", # I like Optional type
"PGH003", # It would be nice to not ignore this
]
flake8-unused-arguments.ignore-variadic-names = true

[tool.black]
line-length = 88 # maximum line length
preview = true # to allow enable-unstable-feature
enable-unstable-feature = [
"string_processing",
] # to break strings into multiple lines
exclude = "tinytex-release" # don't format the files in this folder

[tool.pyright]
ignore = ["**/tinytex-release/"]
9 changes: 9 additions & 0 deletions rendercv_tinytex/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
A TinyTeX distribution for RenderCV.
"""

__version__ = "0.1.0"

from .run import run_pdftex

__all__ = ["run_pdftex"]
90 changes: 90 additions & 0 deletions rendercv_tinytex/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import pathlib
import subprocess
import sys


def run_pdftex(latex_file_path: pathlib.Path) -> pathlib.Path:
"""Run TinyTeX with the given $\\LaTeX$ file to render the PDF.
Args:
latex_file_path: The path to the $\\LaTeX$ file.
Returns:
The path to the rendered PDF file.
"""
# check if the file exists:
if not latex_file_path.is_file():
message = f"The file {latex_file_path} doesn't exist!"
raise FileNotFoundError(message)

tinytex_binaries_directory = (
pathlib.Path(__file__).parent / "tinytex-release" / "TinyTeX" / "bin"
)

executables = {
"win32": tinytex_binaries_directory / "windows" / "pdflatex.exe",
"linux": tinytex_binaries_directory / "x86_64-linux" / "pdflatex",
"darwin": tinytex_binaries_directory / "universal-darwin" / "pdflatex",
}

if sys.platform not in executables:
message = f"TinyTeX doesn't support the platform {sys.platform}!"
raise OSError(message)

executable = executables[sys.platform]

# Before running LaTeX, make sure the PDF file is not open in another program,
# that wouldn't allow LaTeX to write to it. Remove the PDF file if it exists,
# if it's not removable, then raise an error:
pdf_file_path = latex_file_path.with_suffix(".pdf")
if pdf_file_path.is_file():
try:
pdf_file_path.unlink()
except PermissionError as e:
message = (
f"The PDF file {pdf_file_path} is open in another program and doesn't"
" allow RenderCV to rewrite it. Please close the PDF file."
)
raise RuntimeError(message) from e

# Run LaTeX to render the PDF:
command = [
executable,
str(latex_file_path.absolute()),
]
with subprocess.Popen(
command,
cwd=latex_file_path.parent,
stdout=subprocess.PIPE, # capture the output
stderr=subprocess.DEVNULL, # don't capture the error
stdin=subprocess.DEVNULL, # don't allow LaTeX to ask for user input
) as latex_process:
output = latex_process.communicate() # wait for the process to finish
if latex_process.returncode != 0:
latex_file_path_log = latex_file_path.with_suffix(".log").read_text()

message = (
"Failed to render the PDF file. Check out the details in the log file:"
f" {latex_file_path.with_suffix('.log')} \n\n"
" It is also printed below:\n\n"
)
message = message + latex_file_path_log
raise RuntimeError(message)

try:
output = output[0].decode("utf-8")
except UnicodeDecodeError:
output = output[0].decode("latin-1")

if "Rerun to get" in output:
# Run TinyTeX again to get the references right:
subprocess.run(
command,
cwd=latex_file_path.parent,
stdout=subprocess.DEVNULL, # don't capture the output
stderr=subprocess.DEVNULL, # don't capture the error
stdin=subprocess.DEVNULL, # don't allow TinyTeX to ask for user input
check=True,
)

return pdf_file_path
3 changes: 3 additions & 0 deletions rendercv_tinytex/tinytex-release/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TinyTeX/texmf-var/luatex-cache/
recycle_bin/
download_and_minimize_tinytex_for_rendercv.log
Loading

0 comments on commit 88590f6

Please sign in to comment.