diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2022-08-10 09:41:48 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2022-08-10 09:41:48 -0400 |
| commit | 1d36597f52bd2d0093964c55520f4ddf5774fe53 (patch) | |
| tree | 321e6f0e12ce1b2eced7f4f8cec3da7e08c10d83 /setuptools/_distutils/command | |
| parent | 71c44d9606f85d80ab5a45530e40552237a1ba1f (diff) | |
| parent | b65aa401e5f533bce966012ca392521e2f939d32 (diff) | |
| download | python-setuptools-git-1d36597f52bd2d0093964c55520f4ddf5774fe53.tar.gz | |
Merge https://github.com/pypa/distutils into distutils-b65aa40
Diffstat (limited to 'setuptools/_distutils/command')
| -rw-r--r-- | setuptools/_distutils/command/check.py | 38 | ||||
| -rw-r--r-- | setuptools/_distutils/command/register.py | 6 |
2 files changed, 22 insertions, 22 deletions
diff --git a/setuptools/_distutils/command/check.py b/setuptools/_distutils/command/check.py index aaf30713..539481c9 100644 --- a/setuptools/_distutils/command/check.py +++ b/setuptools/_distutils/command/check.py @@ -2,17 +2,18 @@ Implements the Distutils 'check' command. """ +import contextlib + from distutils.core import Command from distutils.errors import DistutilsSetupError -try: - # docutils is installed - from docutils.utils import Reporter - from docutils.parsers.rst import Parser - from docutils import frontend - from docutils import nodes +with contextlib.suppress(ImportError): + import docutils.utils + import docutils.parsers.rst + import docutils.frontend + import docutils.nodes - class SilentReporter(Reporter): + class SilentReporter(docutils.utils.Reporter): def __init__( self, source, @@ -30,16 +31,10 @@ try: def system_message(self, level, message, *children, **kwargs): self.messages.append((level, message, children, kwargs)) - return nodes.system_message( + return docutils.nodes.system_message( message, level=level, type=self.levels[level], *children, **kwargs ) - HAS_DOCUTILS = True -except Exception: - # Catch all exceptions because exceptions besides ImportError probably - # indicate that docutils is not ported to Py3k. - HAS_DOCUTILS = False - class check(Command): """This command checks the meta-data of the package.""" @@ -81,8 +76,11 @@ class check(Command): if self.metadata: self.check_metadata() if self.restructuredtext: - if HAS_DOCUTILS: - self.check_restructuredtext() + if 'docutils' in globals(): + try: + self.check_restructuredtext() + except TypeError as exc: + raise DistutilsSetupError(str(exc)) elif self.strict: raise DistutilsSetupError('The docutils package is needed.') @@ -124,8 +122,10 @@ class check(Command): """Returns warnings when the provided data doesn't compile.""" # the include and csv_table directives need this to be a path source_path = self.distribution.script_name or 'setup.py' - parser = Parser() - settings = frontend.OptionParser(components=(Parser,)).get_default_values() + parser = docutils.parsers.rst.Parser() + settings = docutils.frontend.OptionParser( + components=(docutils.parsers.rst.Parser,) + ).get_default_values() settings.tab_width = 4 settings.pep_references = None settings.rfc_references = None @@ -139,7 +139,7 @@ class check(Command): error_handler=settings.error_encoding_error_handler, ) - document = nodes.document(settings, reporter, source=source_path) + document = docutils.nodes.document(settings, reporter, source=source_path) document.note_source(source_path, -1) try: parser.parse(data, document) diff --git a/setuptools/_distutils/command/register.py b/setuptools/_distutils/command/register.py index 2c642472..c1402650 100644 --- a/setuptools/_distutils/command/register.py +++ b/setuptools/_distutils/command/register.py @@ -66,9 +66,9 @@ class register(PyPIRCCommand): def check_metadata(self): """Deprecated API.""" warn( - "distutils.command.register.check_metadata is deprecated, \ - use the check command instead", - PendingDeprecationWarning, + "distutils.command.register.check_metadata is deprecated; " + "use the check command instead", + DeprecationWarning, ) check = self.distribution.get_command_obj('check') check.ensure_finalized() |
