Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
keewenaw
GitHub Repository: keewenaw/ethereum-wallet-cracker
Path: blob/main/test/lib/python3.9/site-packages/setuptools/_distutils/command/check.py
4804 views
1
"""distutils.command.check
2
3
Implements the Distutils 'check' command.
4
"""
5
from email.utils import getaddresses
6
7
from distutils.core import Command
8
from distutils.errors import DistutilsSetupError
9
10
try:
11
# docutils is installed
12
from docutils.utils import Reporter
13
from docutils.parsers.rst import Parser
14
from docutils import frontend
15
from docutils import nodes
16
17
class SilentReporter(Reporter):
18
19
def __init__(self, source, report_level, halt_level, stream=None,
20
debug=0, encoding='ascii', error_handler='replace'):
21
self.messages = []
22
super().__init__(source, report_level, halt_level, stream,
23
debug, encoding, error_handler)
24
25
def system_message(self, level, message, *children, **kwargs):
26
self.messages.append((level, message, children, kwargs))
27
return nodes.system_message(message, level=level,
28
type=self.levels[level],
29
*children, **kwargs)
30
31
HAS_DOCUTILS = True
32
except Exception:
33
# Catch all exceptions because exceptions besides ImportError probably
34
# indicate that docutils is not ported to Py3k.
35
HAS_DOCUTILS = False
36
37
class check(Command):
38
"""This command checks the meta-data of the package.
39
"""
40
description = ("perform some checks on the package")
41
user_options = [('metadata', 'm', 'Verify meta-data'),
42
('restructuredtext', 'r',
43
('Checks if long string meta-data syntax '
44
'are reStructuredText-compliant')),
45
('strict', 's',
46
'Will exit with an error if a check fails')]
47
48
boolean_options = ['metadata', 'restructuredtext', 'strict']
49
50
def initialize_options(self):
51
"""Sets default values for options."""
52
self.restructuredtext = 0
53
self.metadata = 1
54
self.strict = 0
55
self._warnings = 0
56
57
def finalize_options(self):
58
pass
59
60
def warn(self, msg):
61
"""Counts the number of warnings that occurs."""
62
self._warnings += 1
63
return Command.warn(self, msg)
64
65
def run(self):
66
"""Runs the command."""
67
# perform the various tests
68
if self.metadata:
69
self.check_metadata()
70
if self.restructuredtext:
71
if HAS_DOCUTILS:
72
self.check_restructuredtext()
73
elif self.strict:
74
raise DistutilsSetupError('The docutils package is needed.')
75
76
# let's raise an error in strict mode, if we have at least
77
# one warning
78
if self.strict and self._warnings > 0:
79
raise DistutilsSetupError('Please correct your package.')
80
81
def check_metadata(self):
82
"""Ensures that all required elements of meta-data are supplied.
83
84
Required fields:
85
name, version
86
87
Warns if any are missing.
88
"""
89
metadata = self.distribution.metadata
90
91
missing = []
92
for attr in 'name', 'version':
93
if not getattr(metadata, attr, None):
94
missing.append(attr)
95
96
if missing:
97
self.warn("missing required meta-data: %s" % ', '.join(missing))
98
99
def check_restructuredtext(self):
100
"""Checks if the long string fields are reST-compliant."""
101
data = self.distribution.get_long_description()
102
for warning in self._check_rst_data(data):
103
line = warning[-1].get('line')
104
if line is None:
105
warning = warning[1]
106
else:
107
warning = '%s (line %s)' % (warning[1], line)
108
self.warn(warning)
109
110
def _check_rst_data(self, data):
111
"""Returns warnings when the provided data doesn't compile."""
112
# the include and csv_table directives need this to be a path
113
source_path = self.distribution.script_name or 'setup.py'
114
parser = Parser()
115
settings = frontend.OptionParser(components=(Parser,)).get_default_values()
116
settings.tab_width = 4
117
settings.pep_references = None
118
settings.rfc_references = None
119
reporter = SilentReporter(source_path,
120
settings.report_level,
121
settings.halt_level,
122
stream=settings.warning_stream,
123
debug=settings.debug,
124
encoding=settings.error_encoding,
125
error_handler=settings.error_encoding_error_handler)
126
127
document = nodes.document(settings, reporter, source=source_path)
128
document.note_source(source_path, -1)
129
try:
130
parser.parse(data, document)
131
except AttributeError as e:
132
reporter.messages.append(
133
(-1, 'Could not finish the parsing: %s.' % e, '', {}))
134
135
return reporter.messages
136
137