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.
This commit is contained in:
Jon Dufresne 2018-12-15 08:58:09 -08:00
parent 6113261948
commit 49d3a3c0c1
7 changed files with 25 additions and 23 deletions

View File

@ -66,6 +66,8 @@ Deprecated
* ``sphinx.util.force_decode()`` * ``sphinx.util.force_decode()``
* ``sphinx.util.get_matching_docs()`` * ``sphinx.util.get_matching_docs()``
* ``sphinx.util.inspect.Parameter`` * ``sphinx.util.inspect.Parameter``
* ``sphinx.util.osutil.EEXIST``
* ``sphinx.util.osutil.ENOENT``
* ``sphinx.util.osutil.walk()`` * ``sphinx.util.osutil.walk()``
* ``sphinx.util.PeekableIterator`` * ``sphinx.util.PeekableIterator``
* ``sphinx.util.pycompat.u`` * ``sphinx.util.pycompat.u``

View File

@ -207,6 +207,16 @@ The following is a list of deprecated interfaces.
- 3.0 - 3.0
- N/A - N/A
* - ``sphinx.util.osutil.EEXIST``
- 2.0
- 4.0
- ``errno.EEXIST`` or ``FileExistsError``
* - ``sphinx.util.osutil.ENOENT``
- 2.0
- 4.0
- ``errno.ENOENT`` or ``FileNotFoundError``
* - ``sphinx.util.osutil.walk()`` * - ``sphinx.util.osutil.walk()``
- 2.0 - 2.0
- 4.0 - 4.0

View File

@ -28,7 +28,7 @@ from sphinx.util.docutils import SphinxDirective
from sphinx.util.fileutil import copy_asset from sphinx.util.fileutil import copy_asset
from sphinx.util.i18n import search_image_for_language from sphinx.util.i18n import search_image_for_language
from sphinx.util.nodes import set_source_info from sphinx.util.nodes import set_source_info
from sphinx.util.osutil import ensuredir, ENOENT, EPIPE, EINVAL from sphinx.util.osutil import ensuredir, EPIPE, EINVAL
if False: if False:
# For type annotation # For type annotation
@ -247,9 +247,7 @@ def render_dot(self, code, options, format, prefix='graphviz'):
dot_args.extend(['-Tcmapx', '-o%s.map' % outfn]) dot_args.extend(['-Tcmapx', '-o%s.map' % outfn])
try: try:
p = Popen(dot_args, stdout=PIPE, stdin=PIPE, stderr=PIPE, cwd=cwd) p = Popen(dot_args, stdout=PIPE, stdin=PIPE, stderr=PIPE, cwd=cwd)
except OSError as err: except FileNotFoundError:
if err.errno != ENOENT: # No such file or directory
raise
logger.warning(__('dot command %r cannot be run (needed for graphviz ' logger.warning(__('dot command %r cannot be run (needed for graphviz '
'output), check the graphviz_dot setting'), graphviz_dot) 'output), check the graphviz_dot setting'), graphviz_dot)
if not hasattr(self.builder, '_graphviz_warned_dot'): if not hasattr(self.builder, '_graphviz_warned_dot'):

View File

@ -15,7 +15,7 @@ from sphinx.errors import ExtensionError
from sphinx.locale import __ from sphinx.locale import __
from sphinx.transforms.post_transforms.images import ImageConverter from sphinx.transforms.post_transforms.images import ImageConverter
from sphinx.util import logging from sphinx.util import logging
from sphinx.util.osutil import ENOENT, EPIPE, EINVAL from sphinx.util.osutil import EPIPE, EINVAL
if False: if False:
# For type annotation # For type annotation
@ -75,9 +75,7 @@ class ImagemagickConverter(ImageConverter):
[_from, _to]) [_from, _to])
logger.debug('Invoking %r ...', args) logger.debug('Invoking %r ...', args)
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError as err: except FileNotFoundError:
if err.errno != ENOENT: # No such file or directory
raise
logger.warning(__('convert command %r cannot be run.' logger.warning(__('convert command %r cannot be run.'
'check the image_converter setting'), 'check the image_converter setting'),
self.config.image_converter) self.config.image_converter)

View File

@ -25,7 +25,7 @@ from sphinx.errors import SphinxError
from sphinx.locale import _, __ from sphinx.locale import _, __
from sphinx.util import logging from sphinx.util import logging
from sphinx.util.math import get_node_equation_number, wrap_displaymath from sphinx.util.math import get_node_equation_number, wrap_displaymath
from sphinx.util.osutil import ensuredir, ENOENT, cd from sphinx.util.osutil import ensuredir, cd
from sphinx.util.png import read_png_depth, write_png_depth from sphinx.util.png import read_png_depth, write_png_depth
from sphinx.util.pycompat import sys_encoding from sphinx.util.pycompat import sys_encoding
@ -137,9 +137,7 @@ def compile_math(latex, builder):
with cd(tempdir): with cd(tempdir):
try: try:
p = Popen(command, stdout=PIPE, stderr=PIPE) p = Popen(command, stdout=PIPE, stderr=PIPE)
except OSError as err: except FileNotFoundError:
if err.errno != ENOENT: # No such file or directory
raise
logger.warning(__('LaTeX command %r cannot be run (needed for math ' logger.warning(__('LaTeX command %r cannot be run (needed for math '
'display), check the imgmath_latex setting'), 'display), check the imgmath_latex setting'),
builder.config.imgmath_latex) builder.config.imgmath_latex)
@ -157,9 +155,7 @@ def convert_dvi_to_image(command, name):
"""Convert DVI file to specific image format.""" """Convert DVI file to specific image format."""
try: try:
p = Popen(command, stdout=PIPE, stderr=PIPE) p = Popen(command, stdout=PIPE, stderr=PIPE)
except OSError as err: except FileNotFoundError:
if err.errno != ENOENT: # No such file or directory
raise
logger.warning(__('%s command %r cannot be run (needed for math ' logger.warning(__('%s command %r cannot be run (needed for math '
'display), check the imgmath_%s setting'), 'display), check the imgmath_%s setting'),
name, command[0], name) name, command[0], name)

View File

@ -30,8 +30,8 @@ if False:
from typing import Any, Iterator, List, Tuple, Union # NOQA from typing import Any, Iterator, List, Tuple, Union # NOQA
# Errnos that we need. # Errnos that we need.
EEXIST = getattr(errno, 'EEXIST', 0) EEXIST = getattr(errno, 'EEXIST', 0) # RemovedInSphinx40Warning
ENOENT = getattr(errno, 'ENOENT', 0) ENOENT = getattr(errno, 'ENOENT', 0) # RemovedInSphinx40Warning
EPIPE = getattr(errno, 'EPIPE', 0) EPIPE = getattr(errno, 'EPIPE', 0)
EINVAL = getattr(errno, 'EINVAL', 0) EINVAL = getattr(errno, 'EINVAL', 0)

View File

@ -23,12 +23,10 @@ from sphinx.testing.util import assert_node
def has_binary(binary): def has_binary(binary):
try: try:
subprocess.check_output([binary]) subprocess.check_output([binary])
except OSError as e: except FileNotFoundError:
if e.errno == errno.ENOENT:
# handle file not found error.
return False return False
else: except OSError:
return True pass
return True return True