Skip to content

Commit b3a32a2

Browse files
authored
🚀 Add sphinx and deploy to readthedocs.io (#13)
* 🚀 Add sphinx and deploy to readthedocs.io * ✏️ Add newer python classifiers * 🐛 Amend docs.txt for 3.6+ * 🚨 Run pytest on src and tests only * 🐛 Amend ci.txt for 3.6+ * 🐛 Explicitly point to tests/ * 🐛 Unpin pytest
1 parent 4639d7d commit b3a32a2

File tree

18 files changed

+566
-113
lines changed

18 files changed

+566
-113
lines changed

.github/workflows/main.yml

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,89 @@ name: GH
22

33
on:
44
pull_request:
5-
branches: '*'
65
push:
7-
branches: 'master'
8-
tags: '*'
6+
branches: master
7+
release:
8+
types: [released, prereleased]
9+
workflow_dispatch: # allows running workflow manually from the Actions tab
910

1011
jobs:
1112
CI:
1213
runs-on: ubuntu-latest
1314
strategy:
14-
max-parallel: 8
1515
matrix:
16-
python-version: [2.7, 3.5, 3.6, 3.7, 3.8]
16+
python-version: ['2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11']
1717
steps:
1818
- uses: actions/checkout@v2
19+
with:
20+
fetch-depth: 0
1921

2022
- name: Set up Python ${{ matrix.python-version }}
21-
uses: actions/setup-python@v2
23+
uses: actions/setup-python@v4
2224
with:
2325
python-version: ${{ matrix.python-version }}
2426

2527
- name: Pip cache
2628
uses: actions/cache@v2
2729
with:
2830
path: ~/.cache/pip
29-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements/*.txt') }}
31+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements/*.txt') }}
3032
restore-keys: |
3133
${{ runner.os }}-pip-
3234
33-
- run: pip install -U pip setuptools wheel
35+
- name: Pre-commit cache
36+
uses: actions/cache@v2
37+
with:
38+
path: ~/.cache/pre-commit
39+
key: ${{ runner.os }}-pre-commit-${{ matrix.python-version }}-${{ hashFiles('**/requirements/ci.txt') }}-${{ hashFiles('.pre-commit-config.yaml') }}
40+
restore-keys: |
41+
${{ runner.os }}-pre-commit-
3442
3543
- name: Install dependencies
36-
run: make install
44+
run: |
45+
pip install -U pip setuptools wheel codecov
46+
make install
3747
3848
- name: Lint
39-
if: matrix.python-version == 3.8
49+
if: matrix.python-version == 3.11
4050
run: make lint
4151

4252
- name: Test
4353
run: make test
4454

55+
- name: Docs
56+
if: matrix.python-version == 3.11
57+
run: SPHINXOPTS=-W make builddocs
58+
4559
- name: Codecov
46-
if: matrix.python-version == 3.8
4760
env:
4861
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4962
run: |
50-
pip install codecov
5163
codecov
5264
5365
CD:
5466
needs: CI
55-
if: startsWith(github.ref, 'refs/tags/')
67+
if: github.event_name == 'release'
5668
runs-on: ubuntu-latest
5769
steps:
5870
- uses: actions/checkout@v2
5971

60-
- name: Set up Python 3.8
72+
- name: Set up Python
6173
uses: actions/setup-python@v2
6274
with:
63-
python-version: 3.8
75+
python-version: 3.x
6476

65-
- name: PyPi Deploy preparation
77+
- name: Build
6678
run: |
67-
pip install --upgrade setuptools wheel
79+
pip install -U pip setuptools wheel twine
6880
python setup.py sdist bdist_wheel --universal
6981
70-
- name: PyPi Deploy
71-
uses: pypa/gh-action-pypi-publish@v1.2.1
72-
with:
73-
user: ${{ secrets.PYPI_USER }}
74-
password: ${{ secrets.PYPI_PASSWORD }}
82+
- name: Publish
83+
env:
84+
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
85+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
86+
run: |
87+
twine upload dist/*
7588
7689
- uses: apexskier/github-release-commenter@v1
7790
with:

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
# docs
2+
docs/source/README.md
3+
docs/source/_code_reference/
4+
15
# setuptools_scm
26
_repo_version.py

.pre-commit-config.yaml

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,61 @@
11
repos:
22
- repo: https://github.com/Yelp/detect-secrets
3-
rev: v1.2.0
3+
rev: v1.4.0
44
hooks:
55
- id: detect-secrets
66
args: ['--baseline', '.secrets.baseline']
77
exclude: .*/tests/.*
88

99
- repo: https://github.com/psf/black
10-
rev: 22.3.0
10+
# when updating this version, also update blacken-docs hook below
11+
rev: 22.10.0
1112
hooks:
1213
- id: black
1314

15+
- repo: https://github.com/asottile/blacken-docs
16+
rev: v1.12.1
17+
hooks:
18+
- id: blacken-docs
19+
additional_dependencies: ['black==22.10.0']
20+
1421
- repo: https://github.com/timothycrosley/isort
1522
rev: 5.10.1
1623
hooks:
1724
- id: isort
1825

26+
- repo: local
27+
hooks:
28+
- id: mypy
29+
name: Run mypy
30+
entry: python -m mypy src/
31+
language: system
32+
types: [python]
33+
pass_filenames: false
34+
1935
- repo: https://github.com/PyCQA/flake8
20-
rev: 4.0.1
36+
rev: 5.0.4
2137
hooks:
2238
- id: flake8
2339
additional_dependencies: [
24-
# 'darglint~=1.5.4',
40+
# 'darglint~=1.8.1',
2541
'flake8-absolute-import~=1.0',
2642
'flake8-blind-except~=0.2.1',
27-
'flake8-builtins~=1.5.3',
43+
'flake8-builtins~=2.0.1',
2844
'flake8-cognitive-complexity==0.1.0',
29-
'flake8-comprehensions~=3.8.0',
30-
# 'flake8-docstrings~=1.5.0',
31-
'flake8-logging-format~=0.6.0',
45+
'flake8-comprehensions~=3.10.0',
46+
# 'flake8-docstrings~=1.6.0',
47+
'flake8-logging-format~=0.8.1',
3248
'flake8-mutable~=1.2.0',
33-
'flake8-print~=4.0.0',
34-
'flake8-printf-formatting~=1.1.2',
49+
'flake8-print~=5.0.0',
50+
'flake8-printf-formatting~=1.1.0',
3551
'flake8-pytest-style~=1.6.0',
3652
'flake8-quotes~=3.3.1',
3753
'flake8-tuple~=0.4.1',
38-
'pep8-naming~=0.12.1'
54+
'pep8-naming~=0.13.2'
3955
]
4056

4157
- repo: https://github.com/pre-commit/pre-commit-hooks
42-
rev: v4.1.0
58+
rev: v4.3.0
4359
hooks:
4460
- id: mixed-line-ending
4561
args: ['--fix=lf']
@@ -50,3 +66,11 @@ repos:
5066
- id: check-toml
5167
- id: check-xml
5268
- id: check-yaml
69+
- id: debug-statements
70+
71+
- repo: https://github.com/econchick/interrogate
72+
rev: 1.5.0
73+
hooks:
74+
- id: interrogate
75+
pass_filenames: false
76+
args: [-c, setup.cfg]

.readthedocs.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# .readthedocs.yml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Build documentation in the docs/ directory with Sphinx
9+
sphinx:
10+
configuration: docs/source/conf.py
11+
12+
# Build documentation with MkDocs
13+
#mkdocs:
14+
# configuration: mkdocs.yml
15+
16+
# Optionally build your docs in additional formats such as PDF and ePub
17+
formats: all
18+
19+
# Optionally set the version of Python and requirements required to build your docs
20+
python:
21+
version: 3.8
22+
install:
23+
- method: pip
24+
path: .
25+
- requirements: requirements/docs.txt

Makefile

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,27 @@ lint:
88
test:
99
python -m pytest tests/
1010

11+
.PHONY: showcov
12+
## Open the test coverage overview using the default HTML viewer
13+
showcov:
14+
xdg-open htmlcov/index.html || open htmlcov/index.html
15+
1116
.PHONY: install
12-
## Install for development
17+
## Install this repo, plus dev requirements, in editable mode
1318
install:
14-
pip install -r requirements/ci.txt
15-
pip install -e .
19+
pip install -r requirements/ci.txt -r requirements/docs.txt -e .
1620
pre-commit install || true # not installed on older python versions
1721

22+
.PHONY: builddocs
23+
## Build documentation using Sphinx
24+
builddocs:
25+
cd docs && make docs
26+
27+
.PHONY: showdocs
28+
## Open the docs using the default HTML viewer
29+
showdocs:
30+
xdg-open docs/_build/html/index.html || open docs/_build/html/index.html
31+
1832
.PHONY: help
1933
## Print Makefile documentation
2034
help:

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ $ pip install retrie
4545

4646
## Usage
4747

48-
The following objects are all subclasses of [`retrie.retrie.Retrie`](src/retrie/retrie.py), which handles filling the Trie and compiling the corresponding regex pattern.
48+
[![readthedocs](https://readthedocs.org/projects/retrie/badge/?version=latest)](https://retrie.readthedocs.io)
49+
50+
For documentation, see [retrie.readthedocs.io](https://retrie.readthedocs.io/en/stable/_code_reference/retrie.html).
51+
52+
The following objects are all subclasses of `retrie.retrie.Retrie`, which handles filling the Trie and compiling the corresponding regex pattern.
4953

5054

5155
#### Blacklist

docs/Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
# Minimal makefile for Sphinx documentation
3+
#
4+
5+
# You can set these variables from the command line, and also
6+
# from the environment for the first two.
7+
SPHINXOPTS ?=
8+
SPHINXBUILD ?= sphinx-build
9+
SOURCEDIR = source
10+
BUILDDIR = _build
11+
12+
# Put it first so that "make" without argument is like "make help".
13+
help:
14+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
15+
16+
.PHONY: help Makefile
17+
18+
# Catch-all target: route all unknown targets to Sphinx using the new
19+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
20+
%: Makefile
21+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
22+
23+
show:
24+
xdg-open docs/_build/html/index.html || open docs/_build/html/index.html
25+
26+
docs:
27+
rm -rf source/_code_reference
28+
make clean
29+
make html

0 commit comments

Comments
 (0)