-
Notifications
You must be signed in to change notification settings - Fork 13
♻️ REFACTOR: package code #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c0094a0
♻️ REFACTOR: package code
chrisjsewell b4020b8
Add pytest ignore for known deprecation
chrisjsewell 53a2be9
rename variable
chrisjsewell 7541a05
Move `sphinxEncode` to `nodes.sphinx_encode`
chrisjsewell 953544a
Rewrite transforms, merge post-transforms, fix pep-naming
chrisjsewell bcc6b15
add more code documentation
chrisjsewell 4a2d3ea
refactor parts read
chrisjsewell a254155
Remove enforcement of myst-parser `amsmath` extension
chrisjsewell e6a1c7f
Add reference tests for sphinx builds
chrisjsewell c815b3d
Update test_sphinx.py
chrisjsewell 3905cad
Move AST restructuring to post-transform
chrisjsewell 307a1e2
remove reliance on `_toc.yml`
chrisjsewell e04e1c7
Move add_node to classmethods
chrisjsewell a736e5d
auto-infer `jblatex_captions_to_parts`, if it is set to `None`
chrisjsewell f042f08
Update version to 0.3.0a1
chrisjsewell 4577f8c
fix testing extras pinning
chrisjsewell 913c8e9
change version to 0.2.1a1 (to be compatible with jupyter-book)
chrisjsewell 175efc0
update sphinx-external-toc
chrisjsewell 1e3485c
Set `latex_toplevel_sectioning` based on toc
chrisjsewell 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
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.pyc | ||
|
||
build/ | ||
dist/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import sys | ||
from typing import cast | ||
|
||
from sphinx.application import Sphinx | ||
from sphinx.builders.latex import LaTeXBuilder | ||
from sphinx.config import Config | ||
from sphinx.util import logging | ||
from sphinx.util.fileutil import copy_asset_file | ||
|
||
from . import __version__, theme | ||
from .transforms import LatexRootDocPostTransforms, MystNbPostTransform | ||
|
||
if sys.version_info < (3, 9): | ||
import importlib_resources as resources | ||
else: | ||
import importlib.resources as resources | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def override_latex_config(app: Sphinx, config: Config) -> None: | ||
"""This ``config-inited`` event overrides aspects of the sphinx latex config. | ||
|
||
- ``latex_engine`` -> ``xelatex`` | ||
- ``latex_theme`` -> ``jupyterBook`` | ||
- appends necessary LaTeX commands to the preamble | ||
|
||
""" | ||
# only allow latex builder to access rest of the features | ||
config["latex_engine"] = "xelatex" | ||
config["latex_theme"] = "jupyterBook" | ||
|
||
if app.config["jblatex_captions_to_parts"]: | ||
app.config["latex_toplevel_sectioning"] = "part" | ||
|
||
latex_elements = cast(dict, config["latex_elements"]) | ||
|
||
# preamble to overwrite things from sphinx latex writer | ||
config_preamble = ( | ||
latex_elements["preamble"] if "preamble" in config["latex_elements"] else "" | ||
) | ||
|
||
latex_elements["preamble"] = ( | ||
config_preamble | ||
+ r""" | ||
\usepackage[Latin,Greek]{ucharclasses} | ||
\usepackage{unicode-math} | ||
% fixing title of the toc | ||
\addto\captionsenglish{\renewcommand{\contentsname}{Contents}} | ||
""" | ||
) | ||
|
||
|
||
def setup_latex_transforms(app: Sphinx) -> None: | ||
"""This ``builder-inited`` event sets up aspects of the extension, | ||
reserved only for when a LaTeX builder is specified. | ||
""" | ||
|
||
if not isinstance(app.builder, LaTeXBuilder): | ||
return | ||
|
||
# note: bold is a dynamically created function | ||
from sphinx.util.console import bold # type: ignore[attr-defined] | ||
|
||
logger.info( | ||
bold("jupyterbook-latex v%s:") + "(latex_engine='%s')", | ||
__version__, | ||
app.config["latex_engine"], | ||
) | ||
|
||
# Copy the class theme to the output directory. | ||
# note: importlib.resources is the formal method to access files within packages | ||
with resources.as_file(resources.files(theme).joinpath("jupyterBook.cls")) as path: | ||
copy_asset_file(str(path), app.outdir) | ||
|
||
# only load when myst-nb is present | ||
if MystNbPostTransform.check_dependency(): | ||
app.add_post_transform(MystNbPostTransform) | ||
|
||
if app.config["jblatex_load_imgconverter"]: | ||
app.setup_extension("sphinx.ext.imgconverter") | ||
app.add_post_transform(LatexRootDocPostTransforms) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.