Commit Graph
93 Commits
Author SHA1 Message Date
Jon Dufresne ee23a29b3c Deprecate EpubBuilder.esc() in favor of stdlib html.escape()
Available since Python 3.2.

https://docs.python.org/3/library/html.html#html.escape
2019-04-23 19:34:55 -07:00
Jon Dufresne 22afc77c48 Python-3-only clean ups discovered by pyupgrade
https://github.com/asottile/pyupgrade

> A tool to automatically upgrade syntax for newer versions of the
> language.

- Drop u str prefix
- Drop base object inheritance
- Drop args to super()
- Use set literals
- Use dict comprehension
- Use set comprehension
2019-03-19 01:09:48 +09:00
Jon Dufresne f210475489 Python-3-only clean ups discovered by pyupgrade
https://github.com/asottile/pyupgrade

> A tool to automatically upgrade syntax for newer versions of the
> language.

- Drop u str prefix
- Drop base object inheritance
- Drop args to super()
- Use set literals
- Use dict comprehension
- Use set comprehension
2019-03-17 12:58:03 -07:00
Jon Dufresne d8b34cedf0 Add TODO comment to help future developer to refactor guess_mimetype 2019-01-07 06:58:33 -08:00
Jon Dufresne f1e41a616c Remove outdated fallback to 'import Image'
The fallback 'import Image' was added in commit
99621d7a01 for the PIL package. However,
the PIL package is no longer maintained and does not support Python 3.
Development has moved to the Pillow package which always installs to the
PIL namespace.

Pillow repo: https://github.com/python-pillow/Pillow
Old PIL website: http://www.pythonware.com/products/pil/
2019-01-07 06:44:35 -08:00
Jon Dufresne 5d497d0083 Remove redundant mypy config 'incremental'
The mypy config 'incremental` has defaulted as true since version 0.590.
Can drop the local override. For details, see:

https://github.com/python/mypy/commit/6b13652a466ccb102987a2ab1fa93d4b52fd8e3f
2019-01-06 06:58:26 -08:00
Jon Dufresne 17067ed6dc Remove unused except UnicodeDecodeError block
Both `self.srcdir` and `rel_fn` are defined as type str. Calling
os.path.join() on two str values will always return a str value without
the need to decode it. Therefore, the except block is never executed.
2018-12-29 07:34:21 -05:00
Jon Dufresne 6356a622fc Remove unnecessary enum existence guard (#5858)
The enum module is always available since Python 3.4.
2018-12-23 22:44:01 +09:00
Jon Dufresne 4e184754c9 Remove instructions to install Python 2 on Windows
As only Python 3 is supported, should not advise users to install Python
2.
2018-12-23 04:00:26 -08:00
Jon Dufresne c89047635c Improve introductory wording in the conf.py template 2018-12-23 03:52:26 -08:00
Jon Dufresne b61c32a37f Move immediate append operation to list literal
Was previously separate for Python 2 support, but this is no longer
necessary. Can simply include the item in the literal.

https://github.com/sphinx-doc/sphinx/blob/v1.8.2/sphinx/util/__init__.py#L680-L681
2018-12-23 03:46:03 -08:00
Jon Dufresne 1f6ce4cd44 Replace escape sequence '\u00B6' with literal '¶'
More obvious to the reader.
2018-12-20 18:39:51 -08:00
Jon Dufresne e9eaf41a58 Deprecate unused Exception attributes
The attributes were used only for the string representation, but that is
also the default behavior of the Exception class. Observe:

>>> str(Exception('foo'))
'foo'
>>> print(Exception('foo'))
foo
2018-12-18 18:32:16 -08:00
Jon Dufresne 6978918ffc Replace use of six.text_type with str
This removes the last use of the six package allowing Sphinx to remove
it as a dependency.
2018-12-18 16:23:10 -08:00
Jon Dufresne 43ff640b58 Deprecate quickstart.term_decode() and remove internal uses
Per the Python 3 docs, input() always returns a string:

https://docs.python.org/3/library/functions.html#input

> The function then reads a line from input, converts it to a
> string (stripping a trailing newline), and returns that.

The stubs from typeshed say the same:

https://github.com/python/typeshed/blob/5c69373890dfaf4f07f0638766fb0a4903352892/stdlib/3/builtins.pyi#L835

Here is the implementation from CPython with also shows a call to
PyUnicode_Decode on the result:

https://github.com/python/cpython/blob/3.7/Python/bltinmodule.c#L1960-L2143

As the value is always a string, there is nothing to decode. Therefore
the call to term_decode() unnecessary and can safely be removed.

With this in mind, must adjust quickstart tests to be more
representative.
2018-12-17 06:44:17 -08:00
Jon Dufresne e9c87b3d13 Fix invalid escape sequence in test_directive_code.py
Fixes error when running tests:

tests/test_directive_code.py:359
  sphinx/tests/test_directive_code.py:359: DeprecationWarning: invalid escape sequence \s
    includes = '\\end{sphinxVerbatim}\n\sphinxresetverbatimhllines\n'
2018-12-17 11:11:41 +01:00
Jon Dufresne 90b44f4d86 Remove Python 2 monkey patch for Unicode ugettext
In Python 3, gettext always returns a Unicode text string.
2018-12-16 15:01:43 -08:00
Jon Dufresne c4baa7234e Deprecate the old IndexBuilder.feed() method signature
The method signature changed in commit
d27386cc95 (Jun 8, 2016).
2018-12-16 13:52:56 -08:00
Jon Dufresne d210da96f6 Fix invalid escape sequence in test_directive_code.py
Fixes error when running tests:

tests/test_directive_code.py:359
  sphinx/tests/test_directive_code.py:359: DeprecationWarning: invalid escape sequence \s
    includes = '\\end{sphinxVerbatim}\n\sphinxresetverbatimhllines\n'
2018-12-16 13:37:47 -08:00
Jon Dufresne bade33c7e4 Remove unnecessary encoding cookie from Python source files
In Python 3, the default encoding of source files is utf-8. The encoding
cookie is now unnecessary and redundant so remove it. For more details,
see the docs:

https://docs.python.org/3/howto/unicode.html#the-string-type

> The default encoding for Python source code is UTF-8, so you can
> simply include a Unicode character in a string literal ...

Includes a fix for the flake8 header checks to stop expecting an
encoding cookie.
2018-12-16 12:22:12 -08:00
Jon Dufresne 80861d105b Deprecate sphinx.config.string_classes; remove all internal uses
With only a single text type across supported Python versions, the
string_classes is no longer necessary.

Internally, all uses were converted to the value `[str]`. For
.add_config_value() uses that also supply a default string, the type is
inferred.
2018-12-16 11:35:06 -08:00
Jon Dufresne e72391d995 Define a common Inventory type for reuse across modules 2018-12-16 11:03:28 -08:00
Jon Dufresne 150abce5a6 Define Documenter.analyzer as type ModuleAnalyzer 2018-12-16 10:21:11 -08:00
Jon Dufresne 2b0096fba9 Remove redundant coerce to str in string formatting
When an object is passed to a string format placeholder '%s', Python
will implicitly call str() on the object. This applies to print() and
logging as well.
2018-12-16 10:03:45 -08:00
Jon Dufresne d414471eed Pass exceptions directly to docutils reporter
The docutils reporter supports an exception as an argument. It is
converted to a string internally.
2018-12-16 09:21:55 -08:00
Jon Dufresne 7f229582e7 Remove unnecessary bytes/str type check from doctree_read()
ModuleAnalyzer.code is always type str. Decoding is unnecessary.
2018-12-16 08:29:24 -08:00
Jon Dufresne e5bf235ba0 Remove unnecessary bytes/str type check in FileAvoidWrite.write()
All calls to FileAvoidWrite.write() always pass a text string.
Additionally, the type signature only allows type str.
2018-12-16 08:17:19 -08:00
Jon Dufresne 5bf25eb445 Avoid respecifying default encoding for .encode()/.decode() calls
In Python 3, both .encode() and .decode() default the encoding to
'utf-8'. See the docs:

https://docs.python.org/3/library/stdtypes.html#str.encode
https://docs.python.org/3/library/stdtypes.html#bytes.decode

Simplify and shorten the code by using the default instead of
respecifying it.
2018-12-15 17:19:56 -08:00
Jon Dufresne 5b2bf19685 Remove unnecessary bytes type check from path.write_text()
All code passes type str to the method. Per the type signature, only str
is allowed.
2018-12-15 11:47:08 -08:00
Jon Dufresne ee8b403142 Remove unnecessary bytes type check in ModuleAnalyzer.for_string()
All uses always pass a str, never a bytes. Per the type signature, only
str types are allowed.
2018-12-15 11:39:14 -08:00
Jon Dufresne 2646a88b1b Use os.devnull; replace hard coded value
https://docs.python.org/3/library/os.html#os.devnull
2018-12-15 11:11:43 -08:00
Jon Dufresne cc86f57f7f Remove unnecessary check for type bytes
On Python 3, the __file__ attribute is always a string. See docs:

https://docs.python.org/3/reference/import.html#__file__

> __file__ is optional. If set, this attribute’s value must be a string.
2018-12-15 11:05:23 -08:00
Jon Dufresne 49d3a3c0c1 Replace ENOENT errno checks with Python 3 FileNotFoundError
The error is more specific and self documenting.

This removes the last use of sphinx.util.osutil.ENOENT, so it is now
deprecated for removal. sphinx.util.osutil.EEXIST was already unused so
that is deprecated as well.
2018-12-15 09:02:55 -08:00
Jon Dufresne ade973f4e3 Use Python 3 super() argument-less syntax
The form is less verbose and more idiomatic for Python 3 only code.

https://docs.python.org/3/library/functions.html#super
2018-12-15 08:35:55 -08:00
Jon Dufresne 1f4fcd656b Remove use of six.unichr()
Use Python 3 chr() instead.
2018-12-15 08:15:56 -08:00
Jon Dufresne 8bb73c9fd3 Simplify open() call by removing default mode
The open() function opens files in read-only text mode by default. Drop
the mode argument to be slightly simpler and more idiomatic.

https://docs.python.org/3/library/functions.html#open

> The default mode is 'r' (open for reading text, synonym of 'rt').
2018-12-11 06:50:20 -08:00
Jon Dufresne a359013e57 Remove Python2 exception type in inheritance_diagram.py 2018-12-09 16:29:31 -08:00
Jon Dufresne 3a96ce6591 Deprecate unused and untested sphinx.util functions
sphinx.util.attrdict: Last use removed in
b09e628b0f.

sphinx.util.PeekableIterator: Last use removed in
85b8a451a6.
2018-12-09 14:54:50 -08:00
Jon Dufresne d194fe8f7f Correct type signature of set_role_source_info() 2018-12-09 12:51:10 -08:00
Jon Dufresne c994f30b25 Define _MockImporter as a MetaPathFinder
The instance is added to sys.meta_path. Per the documentation, this
should be a MetaPathFinder:

https://docs.python.org/3/library/sys.html#sys.meta_path

Correct the _MockImporter.find_module() type signature per typeshed.

https://github.com/python/typeshed/blob/0b49ce75b478fdf283dda5dd1368759ac342dfe2/stdlib/3/importlib/abc.pyi#L56-L57
2018-12-09 12:30:56 -08:00
Jon Dufresne d41b14f20e Remove _TranslationProxy methods that duplicate UserString
The warning in the comment:

> replace function from UserString; it instantiates a self.__class__ for
> the encoding result

Doesn't apply to these methods as they return non text types. Mostly
bool. By removing these methods, there is less to maintain, annotate,
etc.
2018-12-09 12:07:48 -08:00
Jon Dufresne 96f6c950dd Use 'dist: xenial' in Travis to simplify configuration
Allows using Python version 3.7 without sudo declarations.

Travis officially added support for Xenial on 2018-11-08.

https://blog.travis-ci.com/2018-11-08-xenial-release
2018-12-09 09:36:02 -08:00
Jon Dufresne d99e2cae19 Deprecate evaluating Python 2 syntax in configuration files 2018-11-22 19:05:14 -08:00
Jon Dufresne b8631079bf Replace six.string_types with native str 2018-11-21 06:47:15 -08:00
Jon Dufresne d7c781375f Replace six.exec_() with Python 3 built-in exec() 2018-11-20 21:31:51 -08:00
Jon Dufresne 77849f0ef6 Simplify ensuredir() with Python3 stdlib features
- Simplify ensuredir() to equivalent os.makedir(name, exist_ok=True)
- Do not check if a directory exists before calling
  ensuredir() (ensuredir() already handles it)
- Add exist_ok argument to path.makedirs() to follow same pattern
- Drop unnecessary .exists() check immediately before .isdir()
- Add tests for ensuredir
2018-11-20 18:37:05 -08:00
Jon Dufresne 3bc938ceba Drop explicit dependency: typed_ast
typed-ast has been a required dependency of mypy since v0.470. Can rely
on it being installed as a transient dependency and not list it
explicitly. For the change in mypy, see:

https://github.com/python/mypy/commit/a207754a7e426359812c7ae490ea13c979762b51
2018-11-16 05:23:56 -08:00
Jon Dufresne 4cda774566 Improve JS handling in test_search.py
- Reuse jsload() in all tests to reduce duplication.
- Fix -2 index to -1, to include the entire JSON string. Was previously
  chopping off the final '}'.
- Assert the serialized string ends with a closing parenthesis
2018-11-13 21:25:46 -08:00
Jon Dufresne 8c46a94bca Use super() in SphinxJSONEncoder
This case was missed as part of
710ca3d7c3.
2018-11-13 21:22:30 -08:00
Jon Dufresne 1ae049b2ee Always prefer dict literals over calls to dict()
Dict literals are always slightly faster and are idiomatic modern
Python.
2018-11-13 18:44:16 -08:00
Jon Dufresne 41ad0d5347 Fix all BytesWarning identified through tests
Code should not arbitrarily mix bytes & str values. The values should be
understood and deliberate. When Python is run with the -b option, this
change fixes warnings of the form:

  BytesWarning: str() on a bytes instance
2018-11-13 18:08:49 -08:00
Jon Dufresne 555960d668 Deprecate and drop internal use of force_decode()
In the Python 3 only code base, this function is no longer necessary.
The type of values is well understood and deliberate. Code should avoid
arbitrary mixing of bytes & str.

By removing force_decode() calls from docstring values, can deprecate
the now unused 'encoding' arguments to various autodoc methods.
2018-11-13 07:16:39 -08:00
Jon Dufresne 444a7212b6 Fix "invalid escape sequence" warnings emitted during tests
sphinx/tests/test_quickstart.py:221: DeprecationWarning: invalid escape sequence '\*'
    content = filename.bytes().decode('unicode-escape')
  sphinx/tests/test_quickstart.py:221: DeprecationWarning: invalid escape sequence '\`'
    content = filename.bytes().decode('unicode-escape')
2018-11-13 07:14:24 -08:00
Jon Dufresne 6fbf4a2f99 Deprecate sphinx.util.pycompat.u
It is now simply a constant equal to the empty string. Provides no
further utility.
2018-11-12 16:31:27 -08:00
Jon Dufresne 0137b0287a Remove dead code or '.'
The expression `os.path.dirname(__file__)` always evaluates as a truthy
value. The `or '.'` is never evaluated.
2018-11-12 14:31:29 -08:00
Jon Dufresne 1c9c9df68d Correct type annotation to remove 'type: ignore' comment 2018-11-12 13:26:21 -08:00
Jon Dufresne 88de460c43 Remove commented out dead code in sphinx/testing/util.py
Commented since d47a7587f9 (Sep 21, 2014).
2018-11-12 12:45:24 -08:00
Jon Dufresne fc5aedd378 Simplify tox configuration with 'extras' option
https://tox.readthedocs.io/en/latest/config.html#conf-extras

> extras(MULTI-LINE-LIST)
>
> New in version 2.4.
>
> A list of “extras” to be installed with the sdist or develop install.
> For example, extras = testing is equivalent to [testing] in a pip
> install command.
2018-11-12 08:17:22 -08:00
Jon Dufresne 27a6787d63 Remove use of six.binary_type
Remove type checks for cases that don't apply to Python 3.

For remaining uses, use bytes instead
2018-11-11 19:09:47 -08:00
Jon Dufresne 710ca3d7c3 Use super() to call parent class's method 2018-11-11 13:07:12 -08:00
Jon Dufresne 6ada18b9a8 Remove use of six.u 2018-11-11 12:24:44 -08:00
Jon Dufresne 1b5cf5ca7f Remove reference to deprecated easy_install
easy_install is deprecated and its use is discouraged by PyPA:

https://setuptools.readthedocs.io/en/latest/easy_install.html

> Warning: Easy Install is deprecated. Do not use it. Instead use pip.

Follow upstream advice and only recommended supported tools.
2018-11-01 18:42:48 -07:00
Jon Dufresne 05ac246eff Deprecate Python2 compat shim sphinx.util.osutil.walk()
Code should use os.walk() instead, which works with either str or bytes.
All internal calls use str.
2018-10-05 12:39:50 -07:00
Jon Dufresne 2d0b5969a0 Correct intro.rst with regards to prerequisites 2018-09-24 17:17:54 -07:00
Jon Dufresne 24cd979a1f Remove use of six.next
Use Python builtin next() instead.
2018-09-23 20:51:37 -07:00
Jon Dufresne 65da8a08ac Remove plistlib workaround for unsupported Pythons 2018-09-23 20:25:36 -07:00
Jon Dufresne 4264b6ca0c Remove Python2.7 workaround for enum module 2018-09-23 19:59:27 -07:00
Jon Dufresne cfd5ac06c0 Remove unnecessary __ne__ definitions
In Python 3, __ne__ defaults to the inverse of __eq__.

From https://docs.python.org/3/reference/datamodel.html#object.__ne__

> By default, __ne__() delegates to __eq__() and inverts the result
> unless it is NotImplemented.
2018-09-23 19:45:38 -07:00
Jon Dufresne 4f4e225775 Replace all six.BytesIO with io.BytesIO 2018-09-23 18:38:06 -07:00
Jon Dufresne ce8227c6cf Replace all six.itervalues()/.iteritems() with .values()/.items() 2018-09-23 18:26:31 -07:00
Jon Dufresne dd383ec472 Prefer https:// links where available 2018-09-23 11:50:42 -07:00
Jon Dufresne 02d06bdaf0 Remove uses of six.moves that did not cause any type errors
Removal of the remaining imports may require passing "--python-version
3.5" to the mypy command.
2018-09-23 09:22:06 -07:00
Jon Dufresne d9283a40d8 Correct installation docs about supported Python versions
Since commit 9412bd76b7, older Python
versions have been dropped.
2018-09-23 08:44:29 -07:00
Jon Dufresne a3bc49dd64 Remove Python 2.6 compat shim for ElementTree.itertext 2018-09-22 10:32:28 -07:00
Jon Dufresne 5fd45a0f6f Correct capitalization of PyPI
As spelled on https://pypi.org/.
2018-09-17 08:26:49 +09:00
Jon Dufresne 9fb75a9af8 Correct capitalization of PyPI
As spelled on https://pypi.org/.
2018-09-16 13:41:09 -07:00
Jon Dufresne 490e4aed41 Remove unnecessary object from class definitions
In Python 3, all classes are new-style classes. The object in the
definition is redundant and unnecessary.
2018-09-11 07:07:01 -07:00
Jon Dufresne 2f14c36a8e Remove use of six.class_types
In Python 3, type is the only class type.
2018-09-11 06:22:34 -07:00
Jon Dufresne 0d6be504ea Remove use of six.iteritems()
In Python 3, dict.items() is always an iterator.
2018-09-11 06:03:34 -07:00
Jon Dufresne 02fea029bf Prefer builtin open() over io.open() and codecs.open()
In Python3, the functions io.open() is an alias of the builtin open()
and codecs.open() is functionally equivalent. To reduce indirection,
number of imports, and number of patterns, always prefer the builtin.

https://docs.python.org/3/library/io.html#high-level-module-interface

> io.open()
>
> This is an alias for the builtin open() function.
2018-09-11 05:45:36 -07:00
Jon Dufresne 38709af87b Correct some unicode/str types to bytes
More explicit and more forward compatible with Python 3.
2018-09-09 15:08:44 -07:00
Jon Dufresne e6e6d91d55 Deprecate unused argument, content, from guess_mimetype
Unused since its introduction in
be261ed71e.
2018-09-09 12:23:36 -07:00
Jon Dufresne 9d6deec4ca Fix AttributeError in ExtensionError
In Python 3, the attribute BaseException.message doesn't exist.

$ python3
>>> from sphinx.errors import ExtensionError
>>> e = ExtensionError('foo')
>>> repr(e)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sphinx/sphinx/errors.py", line 65, in __repr__
    return '%s(%r)' % (self.__class__.__name__, self.message)
AttributeError: 'ExtensionError' object has no attribute 'message'
2018-09-09 11:50:56 -07:00
Jon Dufresne 1d11a297a3 Remove use of Python 2 os.getcwdu()
os.getcwdu() is Python 2 only. It was removed from Python 3. As Sphinx
is now Python 3 only, can remove the workaround.

$ python2 -c 'import os; print(os.getcwdu)'
<built-in function getcwdu>
$ python3 -c 'import os; print(os.getcwdu)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'os' has no attribute 'getcwdu'

sphinx.util.osutil.getcwd() is now deprecated for removal.
2018-09-09 11:36:34 -07:00
Jon Dufresne b36cc52c7d Remove pypy from tox.ini
The pypy executable is Python 2 and Python 2 support was dropped in
commit 9412bd76b7.
2018-09-07 16:15:20 -07:00
Jon Dufresne 2f17a0e8c8 Update Python 2 doc links to Python 3
Python 3 docs are more actively maintained and are the future.
2018-06-09 20:59:43 -07:00
Jon Dufresne eb0c57ad79 Fix typo: remove space before full stop 2018-04-28 15:52:55 -07:00
Jon Dufresne 365c93f227 Update all pypi.python.org URLs to pypi.org
For details on the new PyPI, see the blog post:

https://pythoninsider.blogspot.ca/2018/04/new-pypi-launched-legacy-pypi-shutting.html
2018-04-18 19:51:48 -07:00
Jon Dufresne 78c1fde692 Pass python_requires argument to setuptools
Helps pip decide what version of the library to install.

https://packaging.python.org/tutorials/distributing-packages/#python-requires

> If your project only runs on certain Python versions, setting the
> python_requires argument to the appropriate PEP 440 version specifier
> string will prevent pip from installing the project on other Python
> versions.

https://setuptools.readthedocs.io/en/latest/setuptools.html#new-and-changed-setup-keywords

> python_requires
>
> A string corresponding to a version specifier (as defined in PEP 440)
> for the Python version, used to specify the Requires-Python defined in
> PEP 345.
2018-03-13 08:44:22 -07:00
Jon Dufresne cc3abba171 Prefer https & readthedocs.io instead of readthedocs.org for links
Read the Docs moved hosting to readthedocs.io instead of
readthedocs.org. Fix all links in the project.

For additional details, see:

https://blog.readthedocs.com/securing-subdomains/

> Starting today, Read the Docs will start hosting projects from subdomains on
> the domain readthedocs.io, instead of on readthedocs.org. This change
> addresses some security concerns around site cookies while hosting user
> generated data on the same domain as our dashboard.
2018-01-07 09:10:27 -08:00
Jon Dufresne 90279d4cf9 Enable pip cache in Travis CI
Can speed up builds and reduce load on PyPI servers.

For more information, see:

https://docs.travis-ci.com/user/caching/#pip-cache
2017-10-17 20:26:17 -07:00
Jon Dufresne c53dc54a30 Include license file in the generated wheel package
The wheel package format supports including the license file. This is
done using the [metadata] section in the setup.cfg file. For additional
information on this feature, see:

https://wheel.readthedocs.io/en/stable/index.html#including-the-license-in-the-generated-wheel-file
2017-10-15 19:40:10 -07:00
Jon Dufresne 327e6f27fb Rename [wheel] section to [bdist_wheel] as the former is legacy
For additional details, see:

https://bitbucket.org/pypa/wheel/src/54ddbcc9cec25e1f4d111a142b8bfaa163130a61/wheel/bdist_wheel.py?fileviewer=file-view-default#bdist_wheel.py-119:125

http://pythonwheels.com/
2017-10-15 19:33:10 -07:00