Skip to content

Commit

Permalink
Merge pull request #172 from TeoZosa/make-jupyter-support-conditional…
Browse files Browse the repository at this point in the history
…ly-included

✨ Make Jupyter Support Conditionally Included
  • Loading branch information
TeoZosa authored May 20, 2021
2 parents ed6b76c + 61302b9 commit 2b9c5f6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"friendly_name": "{{ cookiecutter.project_slug.replace('-', ' ').title() }}",
"author": "Teo Zosa",
"email": "teo@sonosim.com",
"jupyter_notebook_support": ["yes", "no"],
"remote_vcs_host": ["github", "gitlab"],
"remote_vcs_url": "https://{{ cookiecutter.remote_vcs_host }}.com",
"remote_vcs_username": "TeoZosa",
Expand Down
5 changes: 5 additions & 0 deletions {{cookiecutter.project_slug}}/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ docs/_build

# Local log files
.logs/

{% if cookiecutter.jupyter_notebook_support == 'yes' %}
# Jupyter
**/*.ipynb_checkpoints/
{%- endif %}
5 changes: 5 additions & 0 deletions {{cookiecutter.project_slug}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ repos:
hooks:
- id: detect-secrets
exclude: ^(poetry\.lock|\.cruft\.json)$
# {%- if cookiecutter.jupyter_notebook_support == 'yes' %}
exclude_types: [jupyter]
# {%- endif %}

- repo: https://github.com/flakehell/flakehell
rev: v.0.8.0
Expand Down Expand Up @@ -66,6 +69,7 @@ repos:
args: [--cache-dir=/dev/null, --config-file=tox.ini]
types: [python]

# {%- if cookiecutter.jupyter_notebook_support == 'yes' %}
- repo: https://github.com/nbQA-dev/nbQA
rev: 0.8.0
hooks:
Expand Down Expand Up @@ -118,6 +122,7 @@ repos:
entry: .tox/precommit/bin/nbqa pylint
language: system
types: [jupyter]
# {%- endif %}

- repo: local
hooks:
Expand Down
25 changes: 24 additions & 1 deletion {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ structlog-sentry-logger = "^0.7.3"
typeguard = "^2.10.0" # Runtime type checker
typer = {extras = ["all"], version = "^0.3.2"}

{%- if cookiecutter.jupyter_notebook_support == 'yes' %}
# Jupyter Notebook
jupyter = "^1.0.0"
matplotlib = "^3.4.2"
{%- endif %}

# Documentation
myst-parser = { version = "^0.14.0", optional = true}
pygments = { version = "^2.8.1", optional = true}
Expand All @@ -48,7 +54,9 @@ typer-cli = { version = "^0.0.11", optional = true}

[tool.poetry.dev-dependencies]
# Testing
{%- if cookiecutter.jupyter_notebook_support == 'yes' %}
nbqa = "^0.8.0"
{%- endif %}
pytest = "^6.2.1"
pytest-benchmark = {extras = ["histogram"], version = "^3.4.1"}
pytest-cov = "^2.10.1"
Expand Down Expand Up @@ -145,7 +153,13 @@ pyflakes = ["+*", "-F401"]
pycodestyle = ["+*",
"-E203", # Whitespace before ":"
"-E501", # Line too long (82 > 78 characters)
"-W503" # Line break occurred before a binary operator <- this is now considered best practice by PEP 8
"-W503", # Line break occurred before a binary operator <- this is now considered best practice by PEP 8
{%- if cookiecutter.jupyter_notebook_support == 'yes' %}
# Ignore errors resulting from Jupyter notebook to Python module portability formatting
"-E265", # block comment should start with '# '
# Ignore errors resulting from Jupyter notebook-style programming
"-E402", # module level import not at top of file
{%- endif %}
]

[tool.isort]
Expand All @@ -166,6 +180,15 @@ disable = [
"line-too-long",
"bad-continuation",
"c-extension-no-member",
{%- if cookiecutter.jupyter_notebook_support == 'yes' %}
# Ignore errors resulting from Jupyter notebook-style programming
"invalid-name",
"redefined-outer-name",
"reimported",
"ungrouped-imports",
"wrong-import-order",
"wrong-import-position",
{%- endif %}
]

[tool.pylint.similarities]
Expand Down
16 changes: 15 additions & 1 deletion {{cookiecutter.project_slug}}/tox.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
[gh-actions]
python =
{%- if cookiecutter.jupyter_notebook_support == 'yes' %}
3.7: py37, nbqaxdoctest
3.8: py38, nbqaxdoctest
3.9: py39, coverage, nbqaxdoctest
{%- else %}
3.7: py37
3.8: py38
3.9: py39, coverage
{%- endif %}

[tox]
skip_missing_interpreters = true
isolated_build = true
envlist =
py3{7,8,9},
coverage,
{%- if cookiecutter.jupyter_notebook_support == 'yes' %}
nbqaxdoctest,
{%- endif %}
package

[testenv]
Expand Down Expand Up @@ -135,6 +143,7 @@ depends =
py3{7,8,9}
parallel_show_output = {[testenv]parallel_show_output}

{% if cookiecutter.jupyter_notebook_support == 'yes' %}
[testenv:nbqaxdoctest]
description = Run notebook doctests directly via `xdoctest` (more efficient and
less error-prone than using the built-in `doctest` library or
Expand All @@ -145,7 +154,9 @@ deps = -r requirements-dev.txt
allowlist_externals = bash
commands =
bash -c '\
find {toxinidir}/{{cookiecutter.package_name}} -type f -name "*.ipynb" \
find {toxinidir}/{{cookiecutter.package_name}} \
-type d -name .ipynb_checkpoints -prune -false -o \
-type f -name "*.ipynb" \
| parallel --joblog {toxworkdir}/{envname}.log -j 0 -k nbqa xdoctest \{\} --colored true; \
NUM_FAILED_JOBS=$?; \
echo "*****************$NUM_FAILED_JOBS FAILED JOBS*****************"; \
Expand All @@ -156,6 +167,7 @@ commands =
depends =
py3{7,8,9}
parallel_show_output = {[testenv]parallel_show_output}
{%- endif %}

[testenv:precommit]
description = Run `pre-commit` hooks to auto-format and lint the codebase
Expand All @@ -166,7 +178,9 @@ deps =
icontract
icontract_hypothesis
mypy
{%- if cookiecutter.jupyter_notebook_support == 'yes' %}
nbqa
{%- endif %}
pylint
pytest
sphinx
Expand Down

0 comments on commit 2b9c5f6

Please sign in to comment.