Skip to content

Commit

Permalink
hashes and diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
AakashGfude committed Apr 30, 2021
1 parent 1e9430d commit b5c34f3
Show file tree
Hide file tree
Showing 18 changed files with 432 additions and 125 deletions.
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@ repos:
rev: "0.39"
hooks:
- id: check-manifest

- repo: https://github.com/executablebooks/web-compile
rev: v0.2.1
hooks:
- id: web-compile
files: >-
(?x)^(
web-compile-config.yml|
src/.*|
quantecon_book_theme/static/.*|
quantecon_book_theme/theme.conf
)$
9 changes: 5 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ exclude docs
recursive-exclude docs *
exclude tests
recursive-exclude tests *
exclude src
recursive-exclude src *

exclude .flake8
exclude .pre-commit-config.yaml
exclude .readthedocs.yml
exclude .boussole.json
exclude noxfile.py
exclude codecov.yml
exclude tox.ini

include LICENSE
include MANIFEST.in
include README.md
include web-compile-config.yml

include quantecon_book_theme/theme.conf
recursive-include quantecon_book_theme *.html
recursive-include quantecon_book_theme *.js
recursive-include quantecon_book_theme *.png
recursive-include quantecon_book_theme *.scss
recursive-include quantecon_book_theme *.svg
recursive-include quantecon_book_theme/static *.js *.png *.css *.svg
87 changes: 1 addition & 86 deletions quantecon_book_theme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
"""A lightweight book theme based on the pydata sphinx theme."""
from pathlib import Path

try:
import importlib.resources as resources
except ImportError:
# python < 3.7
import importlib_resources as resources

from docutils.parsers.rst import directives
from docutils import nodes
from sphinx.util import logging
from sphinx.util.fileutil import copy_asset
from sphinx.util.osutil import ensuredir
from bs4 import BeautifulSoup as bs
from sass import compile as sass_compile
import os

from . import static as theme_static
from .launch import add_hub_urls

__version__ = "0.1.5"
Expand All @@ -32,74 +21,6 @@ def get_html_theme_path():
return theme_path


def add_static_paths(app):
"""Ensure CSS/JS is loaded."""
app.env.book_theme_resources_changed = False

output_static_folder = Path(app.outdir) / "_static"
theme_static_files = resources.contents(theme_static)

if (
app.config.html_theme_options.get("theme_dev_mode", False)
and output_static_folder.exists()
):
# during development, the JS/CSS may change, if this is the case,
# we want to remove the old files and ensure that the new files are loaded
for path in output_static_folder.glob("quantecon-book-theme*"):
if path.name not in theme_static_files:
app.env.book_theme_resources_changed = True
path.unlink()
# note sphinx treats theme css different to regular css
# (it is specified in theme.conf), so we don't directly use app.add_css_file
for fname in resources.contents(theme_static):
if fname.endswith(".css"):
if not (output_static_folder / fname).exists():
(output_static_folder / fname).write_bytes(
resources.read_binary(theme_static, fname)
)
app.env.book_theme_resources_changed = True

# add javascript
for fname in resources.contents(theme_static):
if fname.endswith(".js"):
app.add_js_file(fname)


def update_all(app, env):
"""During development, if CSS/JS has changed, all files should be re-written,
to load the correct resources.
"""
if (
app.config.html_theme_options.get("theme_dev_mode", False)
and env.book_theme_resources_changed
):
return list(env.all_docs.keys())


def add_static_path(app):
"""Ensure CSS/JS is loaded."""
app.env.book_theme_resources_changed = False

static_path = Path(__file__).parent.joinpath("static").absolute()
app.config.html_static_path.append(str(static_path))

# Compile the css file if it's not been compiled already
compiled_css_file = static_path / "quantecon-book-theme.css"
if not compiled_css_file.exists():
source_dir = str(static_path.parent / "scss")
output_dir = str(static_path)
sass_compile(dirname=(source_dir, output_dir), output_style="compressed")

# copying plugins
if "plugins_list" in app.config.html_theme_options:
outdir = app.outdir + "/plugins"
ensuredir(outdir)
for i, asset in enumerate(app.config.html_theme_options["plugins_list"]):
assetname = Path(asset).name
copy_asset(app.confdir + "/" + asset, outdir)
app.config.html_theme_options["plugins_list"][i] = "plugins/" + assetname


def find_url_relative_to_root(pagename, relative_page, path_docs_source):
"""Given the current page (pagename), a relative page to it (relative_page),
and a path to the docs source, return the path to `relative_page`, but now relative
Expand Down Expand Up @@ -393,19 +314,13 @@ def run(self):

def setup(app):
# Configuration for Juypter Book
app.setup_extension("sphinx_book_theme")
app.connect("html-page-context", add_hub_urls)
app.connect("env-updated", update_all)

# add translations
package_dir = os.path.abspath(os.path.dirname(__file__))
locale_dir = os.path.join(package_dir, "translations", "locales")
app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir)

app.add_html_theme("quantecon_book_theme", get_html_theme_path())
app.connect("html-page-context", add_to_context)

app.add_js_file("quantecon-book-theme.js")
app.add_directive("margin", Margin, override=True)

return {
"parallel_read_safe": True,
Expand Down
41 changes: 7 additions & 34 deletions quantecon_book_theme/layout.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- extends "pydata_sphinx_theme/layout.html" %}
{%- extends "basic/layout.html" %}

{% block extrahead %}

Expand All @@ -24,7 +24,9 @@
<meta property="og:site_name" content="{{ docstitle | e }}" />

<meta name="theme-color" content="#ffffff" />

<script type="text/javascript" id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
</script>
{% endblock %}

{# Silence the sidebar's, relbar's #}
Expand Down Expand Up @@ -202,38 +204,9 @@
</div> <!-- .toolbar -->

</div> <!-- .wrapper-->

<script src="_static/plugins.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

<script src="https://unpkg.com/@popperjs/core@2"></script>
<script src="https://unpkg.com/tippy.js@6"></script>

{% for item in theme_plugins_list %}
<script src={{item}}></script>
{% endfor %}
<script src="_static/scripts.js"></script>
<script>
feather.replace()
tippy('[data-tippy-content]');
</script>
<script type="text/javascript" id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
</script>
{% if theme_google_analytics_id %}
<script>
window.ga = function () {
ga.q.push(arguments);
};
ga.q = [];
ga.l = +new Date();
ga("create", "{{ theme_google_analytics_id }}", "auto");
ga("set", "anonymizeIp", true);
ga("set", "transport", "beacon");
ga("send", "pageview");
</script>
<script src="https://www.google-analytics.com/analytics.js" async></script>
{% endif %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script src="https://unpkg.com/@popperjs/core@2/dist/umd/popper.min.js"></script>
<script src="https://unpkg.com/tippy.js@6/dist/tippy-bundle.umd.js"></script>
{%- endblock %}

{% block docs_toc %}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Empty file.
3 changes: 2 additions & 1 deletion quantecon_book_theme/theme.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Note: this should only be changed in src/jinja/theme.conf.j2
[theme]
inherit = pydata_sphinx_theme
stylesheet = quantecon-book-theme.css
stylesheet = quantecon-book-theme.3ea8671341652364f3bf176c87181cd0.css

[options]
single_page = False
Expand Down
29 changes: 29 additions & 0 deletions src/jinja/theme.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[theme]
inherit = pydata_sphinx_theme
stylesheet = quantecon-book-theme.css

[options]
single_page = False
expand_toc_sections = []
path_to_docs =
repository_url =
nb_repository_url =
nb_branch =
binderhub_url =
repository_branch =
launch_buttons = {}
home_page_in_toc = False
expand_sections = []
navbar_footer_text =
extra_navbar = Theme by the <a href="https://quantecon.org/">QuantEcon</a>
extra_footer =
use_issues_button = False
use_repository_button = False
plugins_list = []
header_organisation_url =
header_organisation =
description =
keywords =
twitter =
twitter_logo_url =
og_logo_url =
30 changes: 30 additions & 0 deletions src/jinja/theme.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Note: this should only be changed in src/jinja/theme.conf.j2
[theme]
inherit = pydata_sphinx_theme
stylesheet = {{ "src/scss/quantecon-book-theme.scss" | compiled_name }}

[options]
single_page = False
expand_toc_sections = []
path_to_docs =
repository_url =
nb_repository_url =
nb_branch =
binderhub_url =
repository_branch =
launch_buttons = {}
home_page_in_toc = False
expand_sections = []
navbar_footer_text =
extra_navbar = Theme by the <a href="https://quantecon.org/">QuantEcon</a>
extra_footer =
use_issues_button = False
use_repository_button = False
plugins_list = []
header_organisation_url =
header_organisation =
description =
keywords =
twitter =
twitter_logo_url =
og_logo_url =
263 changes: 263 additions & 0 deletions src/js/quantecon-book-theme.js

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
59 changes: 59 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# To use tox, see https://tox.readthedocs.io
# Simply pip or conda install tox
# If you use conda, you may also want to install tox-conda
# then run `tox` or `tox -- {pytest args}`
# To run in parallel using `tox -p` (this does not appear to work for this repo)

# To rebuild the tox environment, for example when dependencies change, use
# `tox -r`

# Note: if the following error is encountered: `ImportError while loading conftest`
# then then deleting compiled files has been found to fix it: `find . -name \*.pyc -delete`

[tox]
envlist = py37-sphinx3

[testenv]
usedevelop=true

[testenv:py{36,37,38}-sphinx{2,3}]
extras = testing
deps =
sphinx2: sphinx>=2,<3
sphinx3: sphinx>=3,<4
commands = pytest {posargs}

[testenv:py{36,37,38}-pre-commit]
extras = code_style
commands = pre-commit run {posargs}

[testenv:docs-{update,clean}]
extras =
sphinx
live-dev
whitelist_externals = rm
commands =
clean: rm -rf docs/_build
web-compile --no-git-add
sphinx-build -nW --keep-going -b {posargs:html} docs/ docs/_build/{posargs:html}

[testenv:docs-live]
extras =
sphinx
live-dev
usedevelop = true
commands =
sphinx-autobuild \
--watch quantecon_book_theme \
--watch src \
--pre-build "web-compile --no-git-add" \
--re-ignore quantecon_book_theme/static/.* \
--re-ignore quantecon_book_theme/static/theme.conf \
--re-ignore _build/.* \
--delay 2 \
--port 0 --open-browser \
-n -b {posargs:html} docs/ docs/_build/{posargs:html}

[check-manifest]
ignore-bad-ideas =
*.mo
13 changes: 13 additions & 0 deletions web-compile-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
web-compile:
sass:
files:
src/scss/quantecon-book-theme.scss: quantecon_book_theme/static/quantecon-book-theme.[hash].css
precision: 5
sourcemap: false
format: compressed
js:
files:
src/js/quantecon-book-theme.js: quantecon_book_theme/static/quantecon-book-theme.[hash].js
jinja:
files:
src/jinja/theme.conf.j2: quantecon_book_theme/theme.conf

1 comment on commit b5c34f3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.