Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Mar 18, 2017
2 parents 0df0a11 + 2dae11a commit aa6dfb8
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 59 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Bugs fixed
rendered as code
* #2665, #2607: Link names in C++ docfields, and make it possible for other domains.
* #3542: C++, fix parsing error of non-type template argument with template.
* #3065, #3520: python domain fails to recognize nested class

Testing
--------
Expand Down Expand Up @@ -200,6 +201,7 @@ Bugs fixed
* #3450: &nbsp is appeared in EPUB docs
* #3418: Search button is misaligned in nature and pyramid theme
* #3421: Could not translate a caption of tables
* #3552: linkcheck raises UnboundLocalError

Release 1.5.2 (released Jan 22, 2017)
=====================================
Expand Down
12 changes: 6 additions & 6 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. highlight:: console

Sphinx Developer's Guide
========================

Expand Down Expand Up @@ -129,8 +131,8 @@ These are the basic steps needed to start developing on Sphinx.

* Run code style checks and type checks (type checks require mypy)::

make style-check
make type-check
make style-check
make type-check

* Run the unit tests under different Python environments using
:program:`tox`::
Expand Down Expand Up @@ -274,14 +276,12 @@ Debugging Tips
* Set the debugging options in the `Docutils configuration file
<http:https://docutils.sourceforge.net/docs/user/config.html>`_.

* JavaScript stemming algorithms in `sphinx/search/*.py` (except `en.py`) are
* JavaScript stemming algorithms in ``sphinx/search/*.py`` (except ``en.py``) are
generated by this
`modified snowballcode generator <https://github.com/shibukawa/snowball>`_.
Generated `JSX <http:https://jsx.github.io/>`_ files are
in `this repository <https://github.com/shibukawa/snowball-stemmer.jsx>`_.
You can get the resulting JavaScript files using the following command:

.. code-block:: bash
You can get the resulting JavaScript files using the following command::

$ npm install
$ node_modules/.bin/grunt build # -> dest/*.global.js
Expand Down
8 changes: 0 additions & 8 deletions doc/latex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,6 @@ Let us now list some macros from the package file
the new macros are wrappers of the formerly hard-coded ``\texttt``,
``\emph``, ... The default definitions can be found in
:file:`sphinx.sty`.
- macros for directional double quotes: pairs of straight double quote ``"``
in reST source are converted into LaTeX mark-up
``\sphinxquotedblleft{}`` and ``\sphinxquotedblright{}`` which default to
`````\ ````` and ``''`` (i.e. the TeX mark-up for directional double
quotes via font ligaturing mechanism.)

.. versionadded:: 1.5.4
Formerly, produced TeX was directly with `````\ ````` and ``''``.
- paragraph level environments: for each admonition type ``<foo>``, the
used environment is named ``sphinx<foo>``. They may be ``\renewenvironment``
'd individually, and must then be defined with one argument (it is the heading
Expand Down
4 changes: 3 additions & 1 deletion sphinx/builders/linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ def check_uri():
# history contains any redirects, get last
if response.history:
code = response.history[-1].status_code
return 'redirected', new_url, code
return 'redirected', new_url, code
else:
return 'redirected', new_url, 0

def check():
# type: () -> Tuple[unicode, unicode, int]
Expand Down
71 changes: 52 additions & 19 deletions sphinx/domains/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ class PyTypedField(PyXrefMixin, TypedField):
class PyObject(ObjectDescription):
"""
Description of a general Python object.
:cvar allow_nesting: Class is an object that allows for nested namespaces
:vartype allow_nesting: bool
"""
option_spec = {
'noindex': directives.flag,
Expand All @@ -189,6 +192,8 @@ class PyObject(ObjectDescription):
names=('rtype',), bodyrolename='obj'),
]

allow_nesting = False

def get_signature_prefix(self, sig):
# type: (unicode) -> unicode
"""May return a prefix to put before the object name in the
Expand Down Expand Up @@ -316,13 +321,54 @@ def add_target_and_index(self, name_cls, sig, signode):

def before_content(self):
# type: () -> None
# needed for automatic qualification of members (reset in subclasses)
self.clsname_set = False
"""Handle object nesting before content
:py:class:`PyObject` represents Python language constructs. For
constructs that are nestable, such as a Python classes, this method will
build up a stack of the nesting heirarchy so that it can be later
de-nested correctly, in :py:meth:`after_content`.
For constructs that aren't nestable, the stack is bypassed, and instead
only the most recent object is tracked. This object prefix name will be
removed with :py:meth:`after_content`.
"""
if self.names:
# fullname and name_prefix come from the `handle_signature` method.
# fullname represents the full object name that is constructed using
# object nesting and explicit prefixes. `name_prefix` is the
# explicit prefix given in a signature
(fullname, name_prefix) = self.names[-1]
if self.allow_nesting:
prefix = fullname
elif name_prefix:
prefix = name_prefix.strip('.')
else:
prefix = None
if prefix:
self.env.ref_context['py:class'] = prefix
if self.allow_nesting:
classes = self.env.ref_context.setdefault('py:classes', [])
classes.append(prefix)

def after_content(self):
# type: () -> None
if self.clsname_set:
self.env.ref_context.pop('py:class', None)
"""Handle object de-nesting after content
If this class is a nestable object, removing the last nested class prefix
ends further nesting in the object.
If this class is not a nestable object, the list of classes should not
be altered as we didn't affect the nesting levels in
:py:meth:`before_content`.
"""
classes = self.env.ref_context.setdefault('py:classes', [])
if self.allow_nesting:
try:
classes.pop()
except IndexError:
pass
self.env.ref_context['py:class'] = (classes[-1] if len(classes) > 0
else None)


class PyModulelevel(PyObject):
Expand Down Expand Up @@ -353,6 +399,8 @@ class PyClasslike(PyObject):
Description of a class-like object (classes, interfaces, exceptions).
"""

allow_nesting = True

def get_signature_prefix(self, sig):
# type: (unicode) -> unicode
return self.objtype + ' '
Expand All @@ -368,13 +416,6 @@ def get_index_text(self, modname, name_cls):
else:
return ''

def before_content(self):
# type: () -> None
PyObject.before_content(self)
if self.names:
self.env.ref_context['py:class'] = self.names[0][0]
self.clsname_set = True


class PyClassmember(PyObject):
"""
Expand Down Expand Up @@ -450,14 +491,6 @@ def get_index_text(self, modname, name_cls):
else:
return ''

def before_content(self):
# type: () -> None
PyObject.before_content(self)
lastname = self.names and self.names[-1][1]
if lastname and not self.env.ref_context.get('py:class'):
self.env.ref_context['py:class'] = lastname.strip('.')
self.clsname_set = True


class PyDecoratorMixin(object):
"""
Expand Down
38 changes: 21 additions & 17 deletions sphinx/util/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,34 @@
# for requests < 2.4.0
InsecureRequestWarning = None

# try to load requests[security]
# try to load requests[security] (but only if SSL is available)
try:
pkg_resources.require(['requests[security]'])
except (pkg_resources.DistributionNotFound,
pkg_resources.VersionConflict):
import ssl
if not getattr(ssl, 'HAS_SNI', False):
# don't complain on each url processed about the SSL issue
requests.packages.urllib3.disable_warnings(
requests.packages.urllib3.exceptions.InsecurePlatformWarning)
except ImportError:
pass
else:
try:
pkg_resources.require(['requests[security]'])
except (pkg_resources.DistributionNotFound,
pkg_resources.VersionConflict):
if not getattr(ssl, 'HAS_SNI', False):
# don't complain on each url processed about the SSL issue
requests.packages.urllib3.disable_warnings(
requests.packages.urllib3.exceptions.InsecurePlatformWarning)
warnings.warn(
'Some links may return broken results due to being unable to '
'check the Server Name Indication (SNI) in the returned SSL cert '
'against the hostname in the url requested. Recommended to '
'install "requests[security]" as a dependency or upgrade to '
'a python version with SNI support (Python 3 and Python 2.7.9+).'
)
except pkg_resources.UnknownExtra:
warnings.warn(
'Some links may return broken results due to being unable to '
'check the Server Name Indication (SNI) in the returned SSL cert '
'against the hostname in the url requested. Recommended to '
'install "requests[security]" as a dependency or upgrade to '
'a python version with SNI support (Python 3 and Python 2.7.9+).'
'install requests-2.4.1+.'
)
except pkg_resources.UnknownExtra:
warnings.warn(
'Some links may return broken results due to being unable to '
'check the Server Name Indication (SNI) in the returned SSL cert '
'against the hostname in the url requested. Recommended to '
'install requests-2.4.1+.'
)

if False:
# For type annotation
Expand Down
7 changes: 4 additions & 3 deletions tests/test_domain_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def assert_refnode(node, module_name, class_name, target, reftype=None,
u'subchild_2', u'meth')
assert_refnode(refnodes[8], None, u'NestedParentA.NestedChildA',
u'NestedParentA.child_1', u'meth')
assert_refnode(refnodes[9], None, None, u'NestedChildA.subchild_1',
u'meth')
assert_refnode(refnodes[9], None, u'NestedParentA',
u'NestedChildA.subchild_1', u'meth')
assert_refnode(refnodes[10], None, u'NestedParentB', u'child_1', u'meth')
assert_refnode(refnodes[11], None, u'NestedParentB', u'NestedParentB',
u'class')
Expand Down Expand Up @@ -125,6 +125,7 @@ def test_domain_py_objects(app, status, warning):
assert objects['module_a.submodule.ModTopLevel'] == ('module', 'class')
assert objects['module_a.submodule.ModTopLevel.mod_child_1'] == ('module', 'method')
assert objects['module_a.submodule.ModTopLevel.mod_child_2'] == ('module', 'method')
assert 'ModTopLevel.ModNoModule' not in objects
assert objects['ModNoModule'] == ('module', 'class')
assert objects['module_b.submodule.ModTopLevel'] == ('module', 'class')

Expand All @@ -136,7 +137,7 @@ def test_domain_py_objects(app, status, warning):
assert objects['NestedParentA.NestedChildA'] == ('roles', 'class')
assert objects['NestedParentA.NestedChildA.subchild_1'] == ('roles', 'method')
assert objects['NestedParentA.NestedChildA.subchild_2'] == ('roles', 'method')
assert objects['child_2'] == ('roles', 'method')
assert objects['NestedParentA.child_2'] == ('roles', 'method')
assert objects['NestedParentB'] == ('roles', 'class')
assert objects['NestedParentB.child_1'] == ('roles', 'method')

Expand Down
10 changes: 5 additions & 5 deletions tests/test_markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ def verify(rst, latex_expected):
def verify_re(verify_re_html, verify_re_latex):
def verify_re_(rst, html_expected, latex_expected):
if html_expected:
return verify_re_html(rst, html_expected)
verify_re_html(rst, html_expected)
if latex_expected:
return verify_re_latex(rst, latex_expected)
verify_re_latex(rst, latex_expected)
return verify_re_


@pytest.fixture
def verify(verify_re_html, verify_re_latex):
def verify_(rst, html_expected, latex_expected):
if html_expected:
return verify_re_html(rst, re.escape(html_expected) + '$')
verify_re_html(rst, re.escape(html_expected) + '$')
if latex_expected:
return verify_re_latex(rst, re.escape(latex_expected) + '$')
verify_re_latex(rst, re.escape(latex_expected) + '$')
return verify_


Expand Down Expand Up @@ -179,7 +179,7 @@ def get(name):
'verify',
'"John"',
'<p>&#8220;John&#8221;</p>',
"``John''",
r'\sphinxquotedblleft{}John\sphinxquotedblright{}',
),
(
# ... but not in literal text
Expand Down

0 comments on commit aa6dfb8

Please sign in to comment.