Skip to content

Commit

Permalink
Add support for Sphinx 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Apr 8, 2019
1 parent 37e8fc6 commit 1e3bf30
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 25 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
dist: xenial
group: travis_latest
language: python
git:
depth: 1
python:
- 2.7
- 3.5
- 3.6
- 3.7
- pypy
- pypy3
matrix:
include:
- python: "3.7"
dist: xenial


before_install:
- python --version
Expand Down
30 changes: 19 additions & 11 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
=========
Changes
=========

0.14 (unreleased)
=================

- Nothing changed yet.
- Add ``python_requires`` metadata to better allow tools like ``pip``
to install a correct version.

- Add support for Sphinx 2.0 on Python 3.

0.13 (2018-12-22)
=================
Expand Down Expand Up @@ -33,7 +39,7 @@
- Decode output from the program tolerantly, using the 'replace'
handler. Based on a `pull request
<https://github.com/habnabit/sphinxcontrib-programoutput/commit/592078e0386c2a36d50a6528b6e49d91707138bf>`_
by Stefan C. Müller.
by Stefan C. Müller.


0.9 (2017-03-15)
Expand All @@ -45,7 +51,9 @@
- Run the tests on Travis CI. Formatting and style is enforced by pylint.

- The oldest supported and tested Sphinx version is now 1.3.5. See
:issue:`17`.
`issue 17
<https://github.com/NextThought/sphinxcontrib-programoutput/issues/17>`_.


- Remove support for Python 2.6, Python 3.2 and 3.3.

Expand All @@ -63,7 +71,7 @@
0.7 (Apr 17, 2012)
==================

- Added ``cwd`` option to :rst:dir:`program-output`
- Added ``cwd`` option to ``..program-output``
- Working directory of executed programs defaults to documentation root now


Expand All @@ -77,16 +85,16 @@
0.5 (Sep 19, 2011)
==================

- :confval:`programoutput_prompt_template` is interpreted as format string now!
- ``programoutput_prompt_template`` is interpreted as format string now!
- Require Python 2.6 now
- Added ``returncode`` option to :rst:dir:`program-output` (thanks to Jan-Marek
Glogowski)
- Added ``returncode`` option to ``program-output`` (thanks to
Jan-Marek Glogowski)
- Support ``returncode`` formatting key in
:confval:`programoutput_prompt_template`
``programoutput_prompt_template``
- Warn on unexpected return codes instead of raising
:py:exc:`~subprocess.CalledProcessError`
- Turn fatal errors during command into document error messages instead of
crashing the build
``subprocess.CalledProcessError``
- Turn fatal errors during command into document error messages
instead of crashing the build


0.4.1 (Mar 11, 2011)
Expand Down
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
:target: https://coveralls.io/github/NextThought/sphinxcontrib-programoutput



http://sphinxcontrib-programoutput.readthedocs.org
https://sphinxcontrib-programoutput.readthedocs.org

A Sphinx_ extension to literally insert the output of arbitrary commands into
documents, helping you to keep your command examples up to date.
Expand All @@ -23,7 +22,7 @@ Install this extension from PyPI_::

pip install sphinxcontrib-programoutput

The extension requires Sphinx 1.3.5 and Python 2.7 or Python 3 (Python
The extension requires Sphinx 1.7.0 and Python 2.7 or Python 3 (Python
3.5+ is tested) at least.

Usage
Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ but respect these guidelines:
- Squash commits on the topic branch before opening a pull request.
- Respect :pep:`8` (use `pep8`_ to check your coding style compliance)
- Add unit tests.
- Open a `pull request <https://help.github.com/articles/using-pull-requests>`_
- Open a `new pull request <https://help.github.com/articles/using-pull-requests>`_
that relates to but one subject with a clear title and description in
grammatically correct, complete sentences.

Expand Down
10 changes: 8 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@

def read_desc():
with open('README.rst') as stream:
return stream.read()
readme = stream.read()
with open('CHANGES.rst') as stream:
changes = stream.read()

return readme + '\n\n' + changes

def read_version_number():
VERSION_PATTERN = re.compile(r"__version__ = '([^']+)'")
Expand All @@ -48,7 +52,6 @@ def read_version_number():
name='sphinxcontrib-programoutput',
version=read_version_number(),
url='https://sphinxcontrib-programoutput.readthedocs.org/',
download_url='https://pypi.org/project/sphinxcontrib-programoutput/',
license='BSD',
author='Sebastian Wiesner',
author_email='lunaryorn@gmail.com',
Expand All @@ -74,6 +77,8 @@ def read_version_number():
"Programming Language :: Python :: Implementation :: PyPy",
'Topic :: Documentation',
'Topic :: Utilities',
'Framework :: Sphinx',
'Framework :: Sphinx :: Extension',
],
platforms='any',
packages=find_packages('src'),
Expand All @@ -87,5 +92,6 @@ def read_version_number():
extras_require={
'test': tests_require,
},
python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*",
test_suite='sphinxcontrib.programoutput.tests',
)
31 changes: 30 additions & 1 deletion src/sphinxcontrib/programoutput/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import tempfile

from docutils import nodes
from docutils.parsers.rst import directives
from docutils.parsers.rst import roles
from sphinx.application import Sphinx
Expand Down Expand Up @@ -52,20 +53,48 @@ def __get__(self, inst, class_):
html_theme = 'default'
"""

def _find_duplicate_default_nodes():
from sphinx import addnodes

class App(object):

def __init__(self):
self.nodes = set()

def add_node(self, node):
self.nodes.add(node.__name__)


app = App()
try:
addnodes.setup(app)
except AttributeError:
# Sphinx 1 doesn't have this
pass

return app.nodes

class AppMixin(object):

document_content = '=============\ndummy content\n=============\n'

duplicate_nodes_to_remove = _find_duplicate_default_nodes()

def setUp(self):
# Avoid "WARNING: while setting up extension
# sphinxcontrib.programoutput: directive u'program-output' is
# already registered, it will be overridden".
# This may only be needed for Sphinx 1.
self.directives = directives._directives.copy()
# Likewise for 'eq'
self.roles = roles._roles.copy()

# Avoid "node class 'toctree' is already registered, its visitors will be overridden"
# By default this class has *no* `visit_` methods
for node in self.duplicate_nodes_to_remove:
if hasattr(nodes.GenericNodeVisitor, 'visit_' + node):
delattr(nodes.GenericNodeVisitor, 'visit_' + node)

def tearDown(self):
directives._directives = self.directives
roles._roles = self.roles
Expand Down Expand Up @@ -141,7 +170,7 @@ def build_app(self): # pylint:disable=method-hidden

@Lazy
def ignore_warnings(self):
return False
return True

@Lazy
def doctree(self):
Expand Down
6 changes: 4 additions & 2 deletions src/sphinxcontrib/programoutput/tests/test_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ def test_ellipsis_start_and_negative_stop(self):


@with_content("""\
.. program-output:: python -c 'import sys; sys.exit(1)'""")
.. program-output:: python -c 'import sys; sys.exit(1)'""",
ignore_warnings=False)
def test_unexpected_return_code(self):
with self.assertRaises(SphinxWarning) as excinfo:
self.app.build()
Expand All @@ -256,7 +257,8 @@ def test_unexpected_return_code(self):

@with_content("""\
.. program-output:: python -c 'import sys; sys.exit(1)'
:shell:""")
:shell:""",
ignore_warnings=False)
def test_shell_with_unexpected_return_code(self):
with self.assertRaises(SphinxWarning) as excinfo:
self.app.build()
Expand Down

0 comments on commit 1e3bf30

Please sign in to comment.