Skip to content

Commit 468be5c

Browse files
authored
Merge pull request #82 from executablebooks/prefix-regexes
2 parents 0984e74 + d9cd423 commit 468be5c

16 files changed

+2912
-101
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 88
3+
ignore=E203,W503

.github/workflows/integration.yml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,45 @@ on: [push, pull_request]
44

55
jobs:
66

7+
pre-commit:
8+
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Set up Python 3.7
14+
uses: actions/setup-python@v1
15+
with:
16+
python-version: 3.7
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
git submodule update --init
21+
pip install -e .[code_style]
22+
- name: Run pre-commit
23+
run: |
24+
pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )
25+
26+
27+
test_js:
28+
29+
runs-on: ubuntu-latest
30+
31+
strategy:
32+
matrix:
33+
node-version: [12.x]
34+
35+
steps:
36+
- uses: actions/checkout@v2
37+
- name: Use Node.js ${{ matrix.node-version }}
38+
uses: actions/setup-node@v1
39+
with:
40+
node-version: ${{ matrix.node-version }}
41+
- run: npm ci
42+
- run: npm test
43+
env:
44+
CI: true
45+
746
docs:
847

948
runs-on: ubuntu-latest
@@ -32,7 +71,7 @@ jobs:
3271
publish:
3372

3473
name: Publish to PyPi
35-
needs: [docs]
74+
needs: [pre-commit, docs]
3675
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
3776
runs-on: ubuntu-latest
3877
steps:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,5 @@ _build/
108108

109109
# VS code config
110110
.vscode
111+
112+
node_modules/

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Install pre-commit hooks via
2+
# pre-commit install
3+
4+
exclude: >
5+
(?x)^(
6+
\.vscode/settings\.json
7+
)$
8+
9+
repos:
10+
11+
- repo: git://github.com/pre-commit/pre-commit-hooks
12+
rev: v2.2.3
13+
hooks:
14+
- id: check-json
15+
- id: check-yaml
16+
- id: end-of-file-fixer
17+
- id: trailing-whitespace
18+
- id: flake8
19+
20+
- repo: https://github.com/psf/black
21+
rev: stable
22+
hooks:
23+
- id: black

doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ help:
1717
# Catch-all target: route all unknown targets to Sphinx using the new
1818
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1919
%: Makefile
20-
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

doc/conf.py

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
# -- Project information -----------------------------------------------------
2121

22-
project = 'Sphinx Copybutton'
23-
copyright = '2018, Chris Holdgraf'
24-
author = 'Chris Holdgraf'
22+
project = "Sphinx Copybutton"
23+
copyright = "2018, Executable Books Project"
24+
author = "Executable Books Project"
2525

2626
# The short X.Y version
27-
version = ''
27+
version = ""
2828
# The full version, including alpha/beta/rc tags
29-
release = ''
29+
release = ""
3030

3131

3232
# -- General configuration ---------------------------------------------------
@@ -38,19 +38,19 @@
3838
# Add any Sphinx extension module names here, as strings. They can be
3939
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4040
# ones.
41-
extensions = ['sphinx_copybutton']
41+
extensions = ["sphinx_copybutton", "IPython.sphinxext.ipython_directive"]
4242

4343
# Add any paths that contain templates here, relative to this directory.
44-
templates_path = ['_templates']
44+
templates_path = ["_templates"]
4545

4646
# The suffix(es) of source filenames.
4747
# You can specify multiple suffix as a list of string:
4848
#
4949
# source_suffix = ['.rst', '.md']
50-
source_suffix = '.rst'
50+
source_suffix = ".rst"
5151

5252
# The master toctree document.
53-
master_doc = 'index'
53+
master_doc = "index"
5454

5555
# The language for content autogenerated by Sphinx. Refer to documentation
5656
# for a list of supported languages.
@@ -62,18 +62,18 @@
6262
# List of patterns, relative to source directory, that match files and
6363
# directories to ignore when looking for source files.
6464
# This pattern also affects html_static_path and html_extra_path .
65-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
65+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
6666

6767
# The name of the Pygments (syntax highlighting) style to use.
68-
pygments_style = 'sphinx'
68+
pygments_style = "sphinx"
6969

7070

7171
# -- Options for HTML output -------------------------------------------------
7272

7373
# The theme to use for HTML and HTML Help pages. See the documentation for
7474
# a list of builtin themes.
7575
#
76-
html_theme = 'alabaster'
76+
html_theme = "alabaster"
7777
# html_theme = 'sphinx_rtd_theme'
7878

7979
# Theme options are theme-specific and customize the look and feel of a theme
@@ -85,7 +85,7 @@
8585
# Add any paths that contain custom static files (such as style sheets) here,
8686
# relative to this directory. They are copied after the builtin static files,
8787
# so a file named "default.css" will overwrite the builtin "default.css".
88-
html_static_path = ['_static']
88+
html_static_path = ["_static"]
8989

9090
# Custom sidebar templates, must be a dictionary that maps document names
9191
# to template names.
@@ -98,7 +98,8 @@
9898
# html_sidebars = {}
9999

100100
# CopyButton configuration
101-
copybutton_prompt_text = ">>> "
101+
copybutton_prompt_text = ">>> |\\\\$ |\\[\\d*\\]: |\\.\\.\\.: "
102+
copybutton_prompt_is_regexp = True
102103
# Switches for testing but shouldn't be activated in the live docs
103104
# copybutton_only_copy_prompt_lines = False
104105
# copybutton_remove_prompts = False
@@ -109,7 +110,7 @@
109110
# -- Options for HTMLHelp output ---------------------------------------------
110111

111112
# Output file base name for HTML help builder.
112-
htmlhelp_basename = 'SphinxCopybuttondoc'
113+
htmlhelp_basename = "SphinxCopybuttondoc"
113114

114115

115116
# -- Options for LaTeX output ------------------------------------------------
@@ -118,15 +119,12 @@
118119
# The paper size ('letterpaper' or 'a4paper').
119120
#
120121
# 'papersize': 'letterpaper',
121-
122122
# The font size ('10pt', '11pt' or '12pt').
123123
#
124124
# 'pointsize': '10pt',
125-
126125
# Additional stuff for the LaTeX preamble.
127126
#
128127
# 'preamble': '',
129-
130128
# Latex figure (float) alignment
131129
#
132130
# 'figure_align': 'htbp',
@@ -136,8 +134,13 @@
136134
# (source start file, target name, title,
137135
# author, documentclass [howto, manual, or own class]).
138136
latex_documents = [
139-
(master_doc, 'SphinxCopybutton.tex', 'Sphinx Copybutton Documentation',
140-
'Chris Holdgraf', 'manual'),
137+
(
138+
master_doc,
139+
"SphinxCopybutton.tex",
140+
"Sphinx Copybutton Documentation",
141+
"Executable Books Project",
142+
"manual",
143+
)
141144
]
142145

143146

@@ -146,8 +149,7 @@
146149
# One entry per manual page. List of tuples
147150
# (source start file, name, description, authors, manual section).
148151
man_pages = [
149-
(master_doc, 'sphinxcopybutton', 'Sphinx Copybutton Documentation',
150-
[author], 1)
152+
(master_doc, "sphinxcopybutton", "Sphinx Copybutton Documentation", [author], 1)
151153
]
152154

153155

@@ -157,7 +159,13 @@
157159
# (source start file, target name, title, author,
158160
# dir menu entry, description, category)
159161
texinfo_documents = [
160-
(master_doc, 'SphinxCopybutton', 'Sphinx Copybutton Documentation',
161-
author, 'SphinxCopybutton', 'One line description of project.',
162-
'Miscellaneous'),
162+
(
163+
master_doc,
164+
"SphinxCopybutton",
165+
"Sphinx Copybutton Documentation",
166+
author,
167+
"SphinxCopybutton",
168+
"One line description of project.",
169+
"Miscellaneous",
170+
)
163171
]

doc/index.rst

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,34 @@ use the following configuration:
135135
136136
copybutton_prompt_text = ">>> "
137137
138+
Using regexp prompt identifiers
139+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140+
141+
If your prompts are more complex than a single string, then you can use a regexp to match with.
142+
143+
.. code-block:: python
144+
145+
copybutton_prompt_text = "\\[\\d*\\]: |\\.\\.\\.: "
146+
copybutton_prompt_is_regexp = True
147+
148+
For example when using ipython prompts with continuations:
149+
150+
.. code-block:: restructuredtext
151+
152+
.. code-block:: ipython
153+
154+
[1]: first
155+
...: continuation
156+
output
157+
[2]: second
158+
159+
.. code-block:: ipython
160+
161+
[1]: first
162+
...: continuation
163+
output
164+
[2]: second
165+
138166
Configure whether *only* lines with prompts are copied
139167
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140168

@@ -210,6 +238,64 @@ pull to your computer and install locally with ``pip``::
210238
211239
**Pull requests** and **Issues** are absolutely welcome!
212240
241+
The package is tested for three things (see ``.github/workflows/integration.yml``):
242+
243+
code style
244+
----------
245+
246+
To adhere to this code style install the package with `pre-commit <https://pre-commit.com/>`__:
247+
248+
.. code-block:: console
249+
250+
$ pip install .[code_style]
251+
252+
Then you can run:
253+
254+
.. code-block:: console
255+
256+
$ pre-commit run --all
257+
258+
Or setup pre-commit to run on code commits:
259+
260+
.. code-block:: console
261+
262+
$ pre-commit install
263+
264+
JavaScript unit testing
265+
-----------------------
266+
267+
Install the test dependencies with `npm <https://www.npmjs.com/>`__:
268+
269+
.. code-block:: console
270+
271+
$ npm install ci
272+
273+
Then run the tests:
274+
275+
.. code-block:: console
276+
277+
$ npm test
278+
279+
.. note::
280+
281+
NodeJS >= 12 is required
282+
283+
Documentation builds
284+
--------------------
285+
286+
Install the package:
287+
288+
.. code-block:: console
289+
290+
$ pip install .
291+
292+
Then run the docs build:
293+
294+
.. code-block:: console
295+
296+
$ cd doc
297+
$ make html
298+
213299
.. toctree::
214300
:maxdepth: 1
215301

doc/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sphinx
2+
ipython
23

34
# Install ourselves
4-
.
5+
.

0 commit comments

Comments
 (0)