Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the "sphinx-copybutton" extension in documentation #948

Merged
merged 2 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/edmtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def docs(runtime, toolkit, environment):
])
commands = [
"edm install -y -e {environment} " + packages,
"edm run -e {environment} -- python -m pip install sphinx-copybutton",
]
click.echo(
"Installing documentation tools in '{environment}'".format(
Expand Down
7 changes: 7 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"sphinx.ext.napoleon",
# Link to code in sphinx generated API docs
"sphinx.ext.viewcode",
"sphinx_copybutton",
# Include trait definition comments in autogenerated API docs
"traits.util.trait_documenter",
]
Expand Down Expand Up @@ -98,6 +99,12 @@
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# Options for Sphinx copybutton extension
# ---------------------------------------

# Matches prompts - "$ ", ">>>" and "..."
copybutton_prompt_text = r">>> |\.\.\. |\$ "
Comment on lines +105 to +106
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like ellipses might be used in places which aren't code prompts. Or am I misunderstanding how this works?

Copy link
Contributor Author

@rahulporuri rahulporuri Jun 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triple ellipses ...?

The intention here is to support codeblocks that look like

>>> CustomClass(
...    var_a=1,
...    var_b=2,
... )
>>>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh OK. That makes more sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks John! Merging!

copybutton_prompt_is_regexp = True

# Options for HTML output
# -----------------------
Expand Down
2 changes: 2 additions & 0 deletions enable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
]

__extras_require__ = {
# Dependencies for documentation
"docs": ["enthought-sphinx-theme", "sphinx", "sphinx-copybutton"],
# Dependencies for running enable/kiva's examples
"examples": ["chaco", "mayavi", "scipy", "kiwisolver", "pyglet"],
# Dependencies for GL backend support
Expand Down