Skip to content

Commit

Permalink
🔀 Merge: Update package #20
Browse files Browse the repository at this point in the history
- 🔧 Move to flit for PEP 621 packaging
- 🔧 Add isort pre-commit hook
- ⬆️ nbconvert-> nbclient, coverage v4 -> v5
- 📚 Use https for intersphinx URLs
- 📚 DOCS: Update documentation packages
- 🧪 TEST: Update codecov-action
  • Loading branch information
chrisjsewell authored Jan 17, 2022
2 parents 40381be + 13815a2 commit 997c04b
Show file tree
Hide file tree
Showing 38 changed files with 1,210 additions and 963 deletions.
6 changes: 0 additions & 6 deletions .flake8

This file was deleted.

38 changes: 19 additions & 19 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.6, 3.7, 3.8]
python-version: [3.7, 3.8, 3.9]

runs-on: ${{ matrix.os }}

Expand All @@ -47,10 +47,10 @@ jobs:
run: coverage xml

- name: Upload to Codecov
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.7 && github.repository == 'chrisjsewell/pytest-notebook'
uses: codecov/codecov-action@v1
if: github.repository == 'chrisjsewell/pytest-notebook'
uses: codecov/codecov-action@v2
with:
name: pytests-py3.7
name: pytests-notebook
flags: pytests
file: ./coverage.xml
fail_ci_if_error: true
Expand All @@ -62,18 +62,18 @@ jobs:
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Build package
run: |
pip install wheel
python setup.py sdist bdist_wheel
- name: Publish
uses: pypa/gh-action-pypi-publish@v1.1.0
with:
user: __token__
password: ${{ secrets.PYPI_KEY }}
- name: Checkout source
uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: install flit
run: |
pip install flit~=3.4
- name: Build and publish
run: |
flit publish
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.PYPI_KEY }}
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@

repos:

- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-json
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 20.8b1
rev: 21.12b0
hooks:
- id: black

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies:
Expand All @@ -26,11 +31,6 @@ repos:
- flake8_builtins
- import-order

- repo: https://github.com/mgedmin/check-manifest
rev: "0.39"
hooks:
- id: check-manifest

# - repo: local
# hooks:

Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2

python:
version: 3.7
version: "3.8"
install:
- method: pip
path: .
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Copyright (c) 2019, Chris Sewell
Copyright (c) 2022, Chris Sewell
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
20 changes: 0 additions & 20 deletions MANIFEST.in

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ To install the development version:
```shell
>> git clone https://github.com/chrisjsewell/pytest-notebook .
>> cd pytest-notebook
>> pip install --upgrade pip
>> pip install -e .
>> # pip install -e .[code_style,testing,docs] # install extras for more features
```
Expand Down
85 changes: 15 additions & 70 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@

intersphinx_mapping = {
"python": ("https://docs.python.org/3.6", None),
"_pytest": ("http://doc.pytest.org/en/latest/", None),
"_pytest": ("https://doc.pytest.org/en/latest/", None),
# "PIL": ("http://pillow.readthedocs.org/en/latest/", None),
"nbconvert": ("http://nbconvert.readthedocs.io/en/latest/", None),
"nbformat": ("http://nbformat.readthedocs.io/en/latest/", None),
"attr": ("http://www.attrs.org/en/stable/", None),
"coverage": ("https://coverage.readthedocs.io/en/v4.5.x/", None),
"nbclient": ("https://nbclient.readthedocs.io/en/latest/", None),
"nbformat": ("https://nbformat.readthedocs.io/en/latest/", None),
"attr": ("https://www.attrs.org/en/stable/", None),
"coverage": ("https://coverage.readthedocs.io/en/6.2/", None),
}

intersphinx_aliases = {
Expand All @@ -68,6 +68,7 @@

nitpick_ignore = [
("py:class", "NoneType"),
("py:class", "Config"),
("py:class", "TextIO"),
("py:class", "attr.ib"),
("py:class", "attr.s"),
Expand All @@ -77,84 +78,28 @@
("py:class", "_pytest.nodes.Item"),
]

# The reST default role (used for this markup: `text`) to use for all
# documents.
# default_role = None

# If true, '()' will be appended to :func: etc. cross-reference text.
# add_function_parentheses = True

# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
# add_module_names = True

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []

# If true, keep warnings as "system message" paragraphs in the built documents.
# keep_warnings = False

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False


# -- Options for HTML output ----------------------------------------------

html_theme = "sphinx_book_theme"
html_theme_options = {
"repository_url": "https://github.com/chrisjsewell/pytest-notebook",
"repository_branch": "master",
"path_to_docs": "docs/source",
"use_edit_page_button": True,
"use_issues_button": True,
"use_repository_button": True,
}
jupyter_execute_notebooks = "cache"
execution_show_tb = "READTHEDOCS" in os.environ
execution_timeout = 60 # Note: 30 was timing out on RTD
myst_admonition_enable = True

# Output file base name for HTML help builder.
htmlhelp_basename = "pytest-notebookdoc"


# -- Options for other outputs ---------------------------------------

latex_documents = [
(
master_doc,
"pytest-notebook.tex",
"pytest-notebook Documentation",
"Chris Sewell",
"manual",
)
]
# latex_logo = None
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
# Latex figure (float) alignment
# 'figure_align': 'htbp',
}

man_pages = [
(master_doc, "pytest-notebook", u"pytest-notebook Documentation", [author], 1)
]

texinfo_documents = [
(
master_doc,
"pytest-notebook",
u"pytest-notebook Documentation",
author,
"pytest-notebook",
"A pytest plugin for testing Jupyter Notebooks.",
"Miscellaneous",
)
]
myst_enable_extensions = ["colon_fence"]

# -- Sphinx setup for other outputs ---------------------------------------

Expand Down
29 changes: 18 additions & 11 deletions docs/source/user_guide/tutorial_coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,34 @@ This notebook was rendered with [myst-nb](https://myst-nb.readthedocs.io): {nb-d

+++

The core component of the notebook execution API is the {py:class}`~pytest_notebook.execution.ExecuteCoveragePreprocessor` class,
which is a subclass of {py:class}`nbconvert.preprocessors.ExecutePreprocessor`,
The core component of the notebook execution API is the {py:class}`~pytest_notebook.execution.CoverageNotebookClient` class,
which is a subclass of {py:class}`nbclient.client.NotebookClient`,
that can additionally create code [coverage](https://coverage.readthedocs.io) analytics.

This class is called by {py:func}`~pytest_notebook.execution.execute_notebook`,
which returns an {py:class}`~pytest_notebook.execution.ExecuteResult` object.

```{code-cell} ipython3
import yaml
from pytest_notebook.execution import execute_notebook
from pytest_notebook.notebook import create_notebook, create_cell, dump_notebook
```

```{code-cell} ipython3
notebook = create_notebook()
notebook.cells = [
create_cell("""
notebook = create_notebook(
metadata={
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
}
},
cells=[
create_cell("""
from pytest_notebook import __version__
from pytest_notebook.notebook import create_notebook
print(__version__)
"""
)
]
)]
)
```

```{code-cell} ipython3
Expand All @@ -56,15 +61,17 @@ result.coverage_data()
```

```{code-cell} ipython3
print(yaml.dump(result.coverage_dict))
:tags: [hide-output]
result.coverage_dict
```

The coverage can be limited to particular files or modules, by setting `cov_source`.

```{code-cell} ipython3
result = execute_notebook(
notebook, with_coverage=True, cov_source=['pytest_notebook.notebook'])
print(yaml.dump(result.coverage_dict))
result.coverage_dict
```

## Integration with pytest-cov
Expand All @@ -87,7 +94,7 @@ and merge the data back into the main {py:class}`~coverage.Coverage` object.
%%pytest --disable-warnings --color=yes --cov=pytest_notebook --nb-coverage --log-cli-level=info
import logging
import importlib_resources
from importlib import resources as importlib_resources
from pytest_notebook import example_nbs
def test_notebook(nb_regression):
Expand Down
4 changes: 2 additions & 2 deletions docs/source/user_guide/tutorial_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ This notebook was rendered with [myst-nb](https://myst-nb.readthedocs.io): {nb-d

The principal component of `pytest-notebook` is the
{py:class}`~pytest_notebook.nb_regression.NBRegressionFixture` class,
which is an [attrs](http://www.attrs.org) class, whose parameters can be instatiated or set via attibutes.
which is an [attrs](http://www.attrs.org) class, whose parameters can be instantiated or set via attributes.

```{code-cell} ipython3
import importlib_resources
from importlib import resources as importlib_resources
from pytest_notebook import example_nbs
from pytest_notebook.nb_regression import NBRegressionFixture
```
Expand Down
Loading

0 comments on commit 997c04b

Please sign in to comment.