Skip to content

Commit

Permalink
Merge pull request #17 from stevepiercy/sphinx-40-compat
Browse files Browse the repository at this point in the history
Add Sphinx 4.0 compatibility, drop EOLed Pythons
  • Loading branch information
dataflake committed May 25, 2022
2 parents 228bb3b + 8e0176c commit f8b36bb
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 84 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/ci-tests.yml
@@ -0,0 +1,70 @@
name: Build and test

on:
# Build on pushes to master
push:
branches:
- master
# Temporarily add for CI on stevepiercy's fork
- sphinx-40-compat
tags:
# Build pull requests
pull_request:

jobs:
test:
strategy:
# We want to see all failures:
fail-fast: false
matrix:
py:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "pypy-3.7"
os:
- "ubuntu-latest"
- "windows-latest"
- "macos-latest"
architecture:
- x64
- x86

exclude:
# Linux and macOS don't have x86 python
- os: "ubuntu-latest"
architecture: x86
- os: "macos-latest"
architecture: x86
# PyPy3 on Windows doesn't seem to work
- os: "windows-latest"
py: "pypy-3.7"

name: "Python: ${{ matrix.py }}-${{ matrix.architecture }} on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.py }}
architecture: ${{ matrix.architecture }}
- run: pip install tox
- name: Running tox
run: tox -e py -- ${{ matrix.pytest-args }}
# This block is temporarily commented out to speed up testing and until I add
# a lint tox env.
# lint:
# runs-on: ubuntu-latest
# name: Lint the package
# steps:
# - uses: actions/checkout@v2
# - name: Setup python
# uses: actions/setup-python@v2
# with:
# python-version: 3.10
# architecture: x64
# - run: pip install tox
# - run: tox -e lint
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@
*.pyc
*$py.class
.coverage
build/
dist/
*~
.tox
Expand Down
10 changes: 6 additions & 4 deletions .travis.yml
@@ -1,10 +1,12 @@
language: python
sudo: false
python:
- 2.7
- 3.4
- 3.5
- pypy
- 3.6
- 3.7
- 3.8
- 3.9
- 3.10
- pypy3
script:
- zope-testrunner --test-path=. --auto-color --auto-progress

Expand Down
11 changes: 10 additions & 1 deletion CHANGES.rst
@@ -1,9 +1,18 @@
repoze.sphinx.autointerface Changelog
=====================================

0.8.1 (unreleased)
1.0.0 (unreleased)
------------------

- Remove sphinx.util.force_decode. Previously we hacked it in to support Python
2 and Sphinx 3.x, but Sphinx 4.0 deprecated it and dropped Python 2 support.

- Replace Travis-CI with GitHub Actions

- Add support for Python 3.6, 3.7, 3.8, 3.9, 3.10, and PyPy3.

- Drop support for Python 2.7, 3.3, 3.4, 3.5, and PyPy.

- Update to work with newer Sphinx versions:
* Sphinx.domains -> Sphinx.registry.domains
* Sphinx.override_domain(D) -> Sphinx.add_domain(D, override=True)
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Expand Up @@ -105,3 +105,5 @@ Contributors

- Tres Seaver, 2011/03/22
- Jason Madden, 2013/01/10
- Steve Piercy, 2021/05/11

12 changes: 12 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,12 @@
graft repoze

include README.rst
include CHANGES.rst
include CONTRIBUTORS.txt LICENSE.txt COPYRIGHT.txt

include tox.ini .travis.yml
include TODO.txt
graft .github

global-exclude __pycache__ *.py[cod]
global-exclude .DS_Store
48 changes: 26 additions & 22 deletions README.rst
@@ -1,64 +1,68 @@
repoze.sphinx.autointerface README
==================================

.. image:: https://travis-ci.org/repoze/repoze.sphinx.autointerface.png?branch=master
:target: https://travis-ci.org/repoze/repoze.sphinx.autointerface
.. image:: https://github.com/repoze/repoze.sphinx.autointerface/actions/workflows/ci-tests.yml/badge.svg
:target: https://github.com/repoze/repoze.sphinx.autointerface/actions/workflows/ci-tests.yml

.. image:: https://img.shields.io/pypi/v/repoze.sphinx.autointerface.svg
:target: https://pypi.python.org/pypi/repoze.sphinx.autointerface
:target: https://pypi.python.org/pypi/repoze.sphinx.autointerface

.. image:: https://img.shields.io/pypi/pyversions/repoze.sphinx.autointerface.svg
:target: https://pypi.python.org/pypi/repoze.sphinx.autointerface
:target: https://pypi.python.org/pypi/repoze.sphinx.autointerface


Overview
--------

Thie package defines an extension for the
`Sphinx <http://sphinx.pocool.org>`_ documentation system. The extension
allows generation of API documentation by introspection of
`zope.interface <http://pypi.python.org/pypi/zope.interface>`_ instances in
`Sphinx <https://www.sphinx-doc.org/en/master/>`_ documentation system.
The extension allows generation of API documentation by introspection of
`zope.interface <https://pypi.org/project/zope.interface/>`_ instances in
code.


Installation
------------

Install via `easy_install
<http://peak.telecommunity.com/DevCenter/EasyInstall>`_::
Install via ``pip``:

$ bin/easy_install repoze.sphinx.autointerface
.. code-block:: bash
or any other means which gets the package on your ``PYTHONPATH``.
pip install repoze.sphinx.autointerface
Registering the Extension
-------------------------

Add ``repoze.sphinx.autointerface`` to the ``extensions`` list in the
``conf.py`` of the Sphinx documentation for your product. E.g.::
``conf.py`` of the Sphinx documentation for your product.

.. code-block:: python
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.doctest',
'repoze.sphinx.autointerface',
]
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"repoze.sphinx.autointerface",
]
Using the Extension
-------------------

At appropriate points in your document, call out the interface
autodocs via::
At appropriate points in your document, call out the autodoc interface.

.. code-block:: rst
.. autointerface:: yourpackage.interfaces.IFoo
.. autointerface:: yourpackage.interfaces.IFoo
Output from the directive includes

- the fully-qualified interface name
- any base interfaces
- the doctstring from the interface, rendered as reSTX.
- the members of the interface (methods and attributes).
- the docstring from the interface, rendered as reStructuredText
- the members of the interface (methods and attributes)

* For each attribute, the output includes the attribute name
and its description.
* For each method, the output includes the method name, its signature,
and its docstring (also rendered as reSTX).
and its docstring (also rendered as reStructuredText).
9 changes: 1 addition & 8 deletions repoze/sphinx/autointerface.py
Expand Up @@ -8,13 +8,6 @@
from zope.interface.interface import InterfaceClass


if sys.version_info < (3,):
from sphinx.util import force_decode
else:
def force_decode(s, encoding):
return s


class InterfaceDesc(PyClasslike):
def get_index_text(self, modname, name_cls):
return '%s (interface in %s)' % (name_cls[0], modname)
Expand Down Expand Up @@ -95,7 +88,7 @@ def keyfunc(entry):
self.add_line(u'', '<autointerface>')
self.indent += self.content_indent
sourcename = u'docstring of %s.%s' % (self.fullname, name)
docstrings = [prepare_docstring(force_decode(doc, None))]
docstrings = [prepare_docstring(doc)]
for i, line in enumerate(self.process_doc(docstrings)):
self.add_line(line, sourcename, i)
self.add_line(u'', '<autointerface>')
Expand Down
28 changes: 25 additions & 3 deletions repoze/sphinx/tests/test_autointerface.py
Expand Up @@ -3,7 +3,7 @@
from .util import TestApp

from .. import autointerface
from sphinx.ext.autodoc import AutoDirective, ALL
from sphinx.ext.autodoc import ALL

from docutils.statemachine import ViewList

Expand All @@ -21,7 +21,7 @@ def smoothTheDinglebop(schleem):
The schleem is then repurposed.
"""

class Options(object):
class Options(dict):
inherited_members = False
undoc_members = False
private_members = False
Expand All @@ -38,18 +38,40 @@ class Options(object):
exclude_members = ()

def __init__(self):
super(Options, self).__init__()
self.exclude_members = set()
self.members = []
self.__dict__ = self

class Settings(object):

tab_width = 4


class Document(object):

def __init__(self, settings):
self.settings = settings


class State(object):

def __init__(self, document):
self.document = document


class Directive(object):
env = None
genopt = None
result = None
record_dependencies = None

def __init__(self):
self._warnings = []
self.filename_set = set()
self.result = ViewList()
self.record_dependencies = set()
self.state = State(Document(Settings()))

def warn(self, msg):
self._warnings.append(msg)
Expand Down Expand Up @@ -77,7 +99,7 @@ def assertResultContains(self, item,
objtype='interface', name='repoze.sphinx.tests.test_autointerface.IPlumbusMaker',
**kw):
directive = self.directive
inst = AutoDirective._registry[objtype](directive, name)
inst = self.app.registry.documenters['interface'](directive, name)
inst.generate(**kw)
# print '\n'.join(directive.result)
self.assertEqual([], directive._warnings)
Expand Down
6 changes: 1 addition & 5 deletions repoze/sphinx/tests/util.py
Expand Up @@ -3,12 +3,10 @@
import tempfile
import shutil

from six import StringIO
from io import StringIO

from sphinx import application
from sphinx.builders.latex import LaTeXBuilder
from sphinx.theming import Theme
from sphinx.ext.autodoc import AutoDirective
from sphinx.pycode import ModuleAnalyzer

from docutils import nodes
Expand Down Expand Up @@ -98,8 +96,6 @@ def __init__(self, buildername='html', testroot=None, srcdir=None,

def cleanup(self, doctrees=False):
shutil.rmtree(self.__tempdir)
Theme.themes.clear()
AutoDirective._registry.clear()
ModuleAnalyzer.cache.clear()
LaTeXBuilder.usepackages = []
sys.path[:] = self._saved_path
Expand Down

0 comments on commit f8b36bb

Please sign in to comment.