Skip to content

Commit

Permalink
codestyle and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
choldgraf committed Apr 11, 2020
1 parent c5183f8 commit 7442803
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
ignore=E203,W503
75 changes: 75 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: continuous-integration

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
pre-commit:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[code_style]
- name: Run pre-commit
run: |
pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )
tests:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[sphinx]
- name: Build website
run: |
cd docs
make html
- name: Archive website
uses: actions/upload-artifact@v1
with:
name: html
path: _build/html

publish:

name: Publish to PyPi
needs: [pre-commit, tests]
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2
- name: Build package
run: |
pip install wheel
python setup.py sdist bdist_wheel
- name: Publish
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_KEY }}
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Install pre-commit hooks via
# pre-commit install

exclude: >
(?x)^(
\.vscode/settings\.json|
)$
repos:

- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v2.2.3
hooks:
- id: check-json
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: flake8

- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
),
],
extras_require={
"code_style": ["flake8<3.8.0,>=3.7.0", "black", "pre-commit==1.17.0"],
"sphinx": [
"folium",
"numpy",
Expand All @@ -51,14 +52,20 @@
"sphinx-copybutton",
(
"myst_parser @ "
"https://github.com/ExecutableBookProject/myst_parser/archive/master.zip"
"https://github.com/ExecutableBookProject/myst_parser/archive/master.zip" # noqa E501
),
(
"myst_nb @ "
"https://github.com/ExecutableBookProject/myst-nb/archive/master.zip"
),
],
"testing": ["coverage", "pytest>=3.6,<4", "pytest-cov", "beautifulsoup4"],
"testing": [
"coverage",
"pytest>=3.6,<4",
"pytest-cov",
"beautifulsoup4",
"pytest-regressions",
],
},
entry_points={"sphinx.html_themes": ["sphinx_book_theme = sphinx_book_theme"]},
package_data={
Expand Down
9 changes: 6 additions & 3 deletions sphinx_book_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import docutils
from myst_nb.parser import CellNode
from docutils.parsers.rst import directives
from docutils import nodes
from sphinx.util import logging
from sphinx import addnodes
from sphinx.directives.other import TocTree
Expand Down Expand Up @@ -74,6 +73,7 @@ def nav_to_html_list(nav, level=1, include_item_names=False):
return ""
# Lists of pages where we want to trigger extra TOC behavior
extra_toc = app.env.jb_extra_toc_info

# And a function we'll use to parse it
def lookup_extra_toc(pagename, extra_toc_list, kind="parent"):
for first_child_page, parent_page, val in extra_toc_list:
Expand Down Expand Up @@ -112,7 +112,8 @@ def lookup_extra_toc(pagename, extra_toc_list, kind="parent"):
if caption_page == str(page_rel_root):
ul.append('<li class="sidebar-special">')
if caption:
# TODO: whenever pydata-sphinx-theme gets support for captions, we should just use that and remove this
# TODO: whenever pydata-sphinx-theme gets support for captions
# we should just use that and remove this
ul.append(f'<p class="sidebar-caption">{caption_text}</p>')
ul.append("</li>")

Expand Down Expand Up @@ -163,7 +164,9 @@ def compile_scss():


class NewTocTree(TocTree):
"""A monkey-patch of the TocTree so we can intercept extra keywords without raising Sphinx errors."""
"""A monkey-patch of the TocTree so we can intercept extra keywords
without raising Sphinx errors.
"""

newtoctree_spec = TocTree.option_spec.copy()
newtoctree_spec.update(EXTRA_TOC_OPTIONS)
Expand Down
13 changes: 10 additions & 3 deletions sphinx_book_theme/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def add_hub_urls(app, pagename, templatename, context, doctree):
raise ValueError(
(
"Notebook UI for Binder/JupyterHub links must be one"
f"of {tuple(notebook_interface_prefixes.keys())}, not {notebook_interface}"
f"of {tuple(notebook_interface_prefixes.keys())},"
"not {notebook_interface}"
)
)
ui_pre = notebook_interface_prefixes[notebook_interface]
Expand All @@ -139,11 +140,17 @@ def add_hub_urls(app, pagename, templatename, context, doctree):
jupyterhub_url = launch_buttons.get("jupyterhub_url")
binderhub_url = launch_buttons.get("binderhub_url")
if binderhub_url:
url = f"{binderhub_url}/v2/gh/{org}/{repo}/{branch}?urlpath={ui_pre}/{path_rel_repo}"
url = (
f"{binderhub_url}/v2/gh/{org}/{repo}/{branch}?"
"urlpath={ui_pre}/{path_rel_repo}"
)
context["binder_url"] = url

if jupyterhub_url:
url = f"{jupyterhub_url}/hub/user-redirect/git-pull?repo={repo_url}&urlpath={ui_pre}/{repo}/{path_rel_repo}"
url = (
f"{jupyterhub_url}/hub/user-redirect/git-pull?"
f"repo={repo_url}&urlpath={ui_pre}/{repo}/{path_rel_repo}"
)
context["jupyterhub_url"] = url

# Add thebelab flag in context
Expand Down
2 changes: 2 additions & 0 deletions sphinx_book_theme/static/sphinx-book-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ dl.footnote dd p {
@media (max-width: 768px) {
.bd-topbar-whitespace {
display: none; } }

div.dropdown-buttons-trigger span.dropdown-trigger-text {
margin-left: 0.4em; }
@media (max-width: 768px) {
div.dropdown-buttons-trigger span.dropdown-trigger-text {
display: none; } }

div.dropdown-buttons-trigger div.dropdown-buttons {
display: none;
position: absolute;
Expand Down

0 comments on commit 7442803

Please sign in to comment.