Skip to content

Commit 804c73f

Browse files
authored
Add copy button to code blocks in PPT. (#408)
1 parent 9a3a14d commit 804c73f

17 files changed

Lines changed: 66 additions & 52 deletions

docs/conf.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@
2727
html_static_path = ["static"]
2828
html_css_files = ["custom.css"]
2929

30+
extensions = ["sphinx_copybutton"]
31+
32+
# -- sphinx-copybutton configuration ----------------------------------------
33+
## sets up the expected prompt text from console blocks, and excludes it from
34+
## the text that goes into the clipboard.
35+
copybutton_exclude = '.linenos, .gp'
36+
copybutton_prompt_text = ">> "
37+
38+
## lets us suppress the copy button on select code blocks.
39+
copybutton_selector = "div:not(.no-copybutton) > div.highlight > pre"
40+
3041
# -- Options for HTML output -------------------------------------------------
3142
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
3243

docs/practices/ci_benchmarking.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ airspeed velocity. You may need to perform minor changes to this file. For examp
3333
to install dependencies declared on a ``requirements.txt`` file, you may want to set the
3434
``install_command`` as follows:
3535

36-
.. code:: bash
36+
.. code:: console
3737
38-
python -m pip install -r requirements.txt {wheel_file}
38+
>> python -m pip install -r requirements.txt {wheel_file}
3939
4040
For more information about this configuration file, visit the
4141
`asv.conf.json reference <https://asv.readthedocs.io/en/stable/asv.conf.json.html>`_.
@@ -66,7 +66,7 @@ This workflow is triggered on pushes to the main branch.
6666
the first run will take a while because it will process every commit on the repository to the present day,
6767
but subsequent runs will be faster.
6868

69-
.. code:: bash
69+
.. code:: console
7070
7171
>> asv run ALL --skip-existing
7272
@@ -127,15 +127,15 @@ are several questions you'll be asked the first time, and you may need to instal
127127
a new python venv. When your local environment is properly configured, it runs
128128
the benchmarking suite for your most recent commit
129129

130-
.. code:: bash
130+
.. code:: console
131131
132132
>> cd benchmarks
133133
>> asv run
134134
135135
You will need to commit changes locally for the new code to be picked up by ASV.
136136
Having benchmarks for several revisions, you can find them and compare them with ease.
137137

138-
.. code:: bash
138+
.. code:: console
139139
140140
>> asv show
141141
Commits with results:
@@ -153,7 +153,7 @@ of commits and even tags. For more information visit ASV's
153153

154154
If your benchmark fails, you can re-run and find more information with the following:
155155

156-
.. code:: bash
156+
.. code:: console
157157
158158
>> asv run --show-stderr
159159

docs/practices/code_coverage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ install the GitHub app, Codecov.
2222
* Select your repository and follow the instructions
2323

2424
On your Codecov repository click "Settings" and under "Tokens" copy the value of
25-
`CODECOV_TOKEN`. Add it as a secret on your GitHub repository and you're all set!
25+
``CODECOV_TOKEN``. Add it as a secret on your GitHub repository and you're all set!
2626

2727
Future pull requests and commits will now include code coverage information. Neato!

docs/practices/git-lfs.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ After cloning a repository and connecting to the resulting working tree confirm
88
that you have ``git-lfs`` and then issue ``git lfs install`` to install
99
configuration and hooks and then ``git lfs track`` to designate targets for git-lfs.
1010

11-
.. code-block:: bash
11+
.. code-block:: console
1212
1313
git-lfs --version
1414
git lfs install --local
@@ -53,7 +53,7 @@ That site will show you instructions most appropriate for your platform.
5353

5454
You may also use conda as it has a ``git-lfs`` package appropriately named.
5555

56-
.. code-block:: bash
56+
.. code-block:: console
5757
5858
conda install git-lfs
5959
@@ -65,7 +65,7 @@ Install git-lfs in the local repository
6565
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6666
Once you have git-lfs use it to install support into the repository with the command
6767

68-
.. code-block:: bash
68+
.. code-block:: console
6969
7070
git lfs install --local
7171
@@ -85,13 +85,13 @@ the needed changes and create the file if necessary.
8585
For example, if you want to specify that ``FITS`` files are handled by git-lfs
8686
then you might use these commands
8787

88-
.. code-block:: bash
88+
.. code-block:: console
8989
9090
git lfs track '*.fits' '*.fits.fz'
9191
9292
You can see a list of currently tracked names
9393

94-
.. code-block:: bash
94+
.. code-block:: console
9595
9696
git lfs track
9797
@@ -109,7 +109,7 @@ specified the ``--local`` option you should also specify it here.
109109
Probably it is safer to always include the ``--local`` option so you restrict
110110
impact to the current repository.
111111

112-
.. code-block:: bash
112+
.. code-block:: console
113113
114114
git lfs uninstall --local
115115
@@ -120,7 +120,7 @@ Note that we recommend against uninstalling git-lfs as it causes confusion.
120120

121121
You can see what files are controlled by git-lfs using the ``git lfs ls-files`` command
122122

123-
.. code-block:: bash
123+
.. code-block:: console
124124
125125
git lfs ls-files
126126

docs/practices/linting.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ linting tool, that can also perform auto-formatting.
6262

6363
This tool can be run on its own in *linting* (warning) mode with command like:
6464

65-
.. code:: bash
65+
.. code:: console
6666
6767
>> ruff check
6868
6969
This tool can be run on its own in *auto-formatting* mode with command like:
7070

71-
.. code:: bash
71+
.. code:: console
7272
7373
>> ruff format
7474
@@ -121,7 +121,7 @@ formatting (e.g. spacing, quote styles, line breaks).
121121

122122
This tool can be run on its own with command like:
123123

124-
.. code:: bash
124+
.. code:: console
125125
126126
>> black .
127127
@@ -141,7 +141,7 @@ the `.py` and `.pyi` files in your project.
141141

142142
This tool can be run on its own with command like:
143143

144-
.. code:: bash
144+
.. code:: console
145145
146146
>> isort .
147147

docs/practices/namespace_project.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Example
3636
Follow the instructions at :doc:`New Project <../source/new_project>` to create a new
3737
project named **acme-supernovae** with a package named **supernovae**.
3838

39-
.. code-block:: bash
39+
.. code-block:: console
4040
4141
copier copy gh:lincc-frameworks/python-project-template acme-supernovae
4242
cd acme-supernovae
@@ -51,7 +51,7 @@ might break over time as code changes and other uses of **src** are confused by
5151
Define bash functions to find the files containing **src** and to perform the change using
5252
sed so first add the shell functions.
5353

54-
.. code-block:: bash
54+
.. code-block:: console
5555
5656
organization=acme
5757
subpackage=supernovae
@@ -65,21 +65,21 @@ sed so first add the shell functions.
6565
6666
It is wise to review the changes before committing them.
6767

68-
.. code-block:: bash
68+
.. code-block:: console
6969
7070
git diff
7171
7272
Assuming all is good
7373

74-
.. code-block:: bash
74+
.. code-block:: console
7575
7676
git add .
7777
git commit -m "finished move from src to ${organization}"
7878
7979
Add a clause to pyproject.toml to declare this as a namespace package. Again, you might want to
8080
review the results before committing. At least take a look so you see what it added.
8181

82-
.. code-block:: bash
82+
.. code-block:: console
8383
8484
tr '|' '\n' <<<'|[tool.setuptools.packages.find]|where = ["."]|include = ["'"${organization}"'"]|namespaces = true' >>pyproject.toml
8585
git add .
@@ -90,7 +90,7 @@ the package is now a namespace package. This is done by adding a clause to the i
9090

9191
This might be the trickiest bit although for a brand new project it does very little.
9292

93-
.. code-block:: bash
93+
.. code-block:: console
9494
9595
myfiles2() { find . -name .git -prune -o -type f \( -name '*.py' -o -name '*.ipynb' \) -print; }
9696
mysed2() { sed -e "/import/s%${subpackage}%${organization}.${subpackage}%g;" "${1}" >.tmpfile && mv "${1}" .oldfile && mv .tmpfile "${1}" && rm .oldfile; }
@@ -104,15 +104,15 @@ This might be the trickiest bit although for a brand new project it does very li
104104
Build the project and install. We recommend that you do this in a virtual environment.
105105
In this example we build for '.[dev]' and also run the pre-commit hooks as a verification step.
106106

107-
.. code-block:: bash
107+
.. code-block:: console
108108
109109
pip install -e '.[dev]'
110110
pre-commit run --all-files
111111
112112
Create a new project named **acme-utilities** with a package named **utilities** and convert it to a namespace package
113113
using exactly the same process as above but with different names. Then install and check with pre-commit hooks.
114114

115-
.. code-block:: bash
115+
.. code-block:: console
116116
117117
cd ..
118118
copier copy gh:lincc-frameworks/python-project-template acme-utilities
@@ -153,7 +153,7 @@ using exactly the same process as above but with different names. Then install
153153
154154
Try it out. In this example we use the python interpreter to import the subpackages and run the examples.
155155

156-
.. code-block:: bash
156+
.. code-block:: console
157157
158158
$ python
159159
>>> from acme import supernovae, utilities
@@ -167,6 +167,6 @@ Try it out. In this example we use the python interpreter to import the subpack
167167
168168
You might want to uninstall the packages to avoid python environment bloat!
169169

170-
.. code-block:: bash
170+
.. code-block:: console
171171
172172
pip uninstall acme-supernovae acme-utilities

docs/practices/pipx.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ installation process that is most straightforward for you system.
4141

4242
An example installation of ``pipx`` might look like this.
4343

44-
.. code-block:: bash
44+
.. code-block:: console
4545
4646
>> conda install -c conda-forge pipx
4747
>> pipx ensurepath

docs/practices/precommit.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ development. Additional documentation can be found
1414
To configure pre-commit for your project, run the following command to register
1515
pre-commit hooks with ``.git/hooks/pre-commit``.
1616

17-
.. code-block:: bash
17+
.. code-block:: console
1818
1919
pre-commit install
2020

docs/practices/pytest_timeout.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Other fun things you can do
7676
Even if you're not using this package, you can find slow-running tests in your
7777
suite with the ``--durations`` flag.
7878

79-
.. code-block:: bash
79+
.. code-block:: console
8080
8181
pytest --durations=10
8282

docs/practices/sphinx.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ How to manage
4242
To build the documentation in your local development environment, it's best to
4343
follow the same steps as readthedocs will perform when building your documentation.
4444

45-
.. code-block:: bash
45+
.. code-block:: console
4646
4747
cd $project_directory
4848
pip install -e .
@@ -74,7 +74,7 @@ Alternatively, you can make Sphinx ignore all of the notebooks in your documenta
7474
while still building everything else. To do so, you will need to run sphinx in make
7575
mode, which allows the use of the -D flag to override excluded files.
7676

77-
.. code-block:: bash
77+
.. code-block:: console
7878
7979
cd $project_directory
8080
pip install -e .
@@ -83,7 +83,7 @@ mode, which allows the use of the -D flag to override excluded files.
8383
8484
Or, using the command in the included Makefile,
8585

86-
.. code-block:: bash
86+
.. code-block:: console
8787
8888
cd $project_directory
8989
pip install -e .

0 commit comments

Comments
 (0)