NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

check.py (4218B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\stdlib\distutils\command\check.py
      2 __revision__ = '$Id: check.py 75266 2009-10-05 22:32:48Z andrew.kuchling $'
      3 from distutils.core import Command
      4 from distutils.errors import DistutilsSetupError
      5 try:
      6     from docutils.utils import Reporter
      7     from docutils.parsers.rst import Parser
      8     from docutils import frontend
      9     from docutils import nodes
     10     from StringIO import StringIO
     11 
     12     class SilentReporter(Reporter):
     13 
     14         def __init__(self, source, report_level, halt_level, stream = None, debug = 0, encoding = 'ascii', error_handler = 'replace'):
     15             self.messages = []
     16             Reporter.__init__(self, source, report_level, halt_level, stream, debug, encoding, error_handler)
     17 
     18         def system_message(self, level, message, *children, **kwargs):
     19             self.messages.append((level,
     20              message,
     21              children,
     22              kwargs))
     23 
     24 
     25     HAS_DOCUTILS = True
     26 except ImportError:
     27     HAS_DOCUTILS = False
     28 
     29 class check(Command):
     30     description = 'perform some checks on the package'
     31     user_options = [('metadata', 'm', 'Verify meta-data'), ('restructuredtext', 'r', 'Checks if long string meta-data syntax are reStructuredText-compliant'), ('strict', 's', 'Will exit with an error if a check fails')]
     32     boolean_options = ['metadata', 'restructuredtext', 'strict']
     33 
     34     def initialize_options(self):
     35         self.restructuredtext = 0
     36         self.metadata = 1
     37         self.strict = 0
     38         self._warnings = 0
     39 
     40     def finalize_options(self):
     41         pass
     42 
     43     def warn(self, msg):
     44         self._warnings += 1
     45         return Command.warn(self, msg)
     46 
     47     def run(self):
     48         if self.metadata:
     49             self.check_metadata()
     50         if self.restructuredtext:
     51             if HAS_DOCUTILS:
     52                 self.check_restructuredtext()
     53             elif self.strict:
     54                 raise DistutilsSetupError('The docutils package is needed.')
     55         if self.strict and self._warnings > 0:
     56             raise DistutilsSetupError('Please correct your package.')
     57 
     58     def check_metadata(self):
     59         metadata = self.distribution.metadata
     60         missing = []
     61         for attr in ('name', 'version', 'url'):
     62             if not (hasattr(metadata, attr) and getattr(metadata, attr)):
     63                 missing.append(attr)
     64 
     65         if missing:
     66             self.warn('missing required meta-data: %s' % ', '.join(missing))
     67         if metadata.author:
     68             if not metadata.author_email:
     69                 self.warn("missing meta-data: if 'author' supplied, " + "'author_email' must be supplied too")
     70         elif metadata.maintainer:
     71             if not metadata.maintainer_email:
     72                 self.warn("missing meta-data: if 'maintainer' supplied, " + "'maintainer_email' must be supplied too")
     73         else:
     74             self.warn('missing meta-data: either (author and author_email) ' + 'or (maintainer and maintainer_email) ' + 'must be supplied')
     75 
     76     def check_restructuredtext(self):
     77         data = self.distribution.get_long_description()
     78         for warning in self._check_rst_data(data):
     79             line = warning[-1].get('line')
     80             if line is None:
     81                 warning = warning[1]
     82             else:
     83                 warning = '%s (line %s)' % (warning[1], line)
     84             self.warn(warning)
     85 
     86     def _check_rst_data(self, data):
     87         source_path = StringIO()
     88         parser = Parser()
     89         settings = frontend.OptionParser().get_default_values()
     90         settings.tab_width = 4
     91         settings.pep_references = None
     92         settings.rfc_references = None
     93         reporter = SilentReporter(source_path, settings.report_level, settings.halt_level, stream=settings.warning_stream, debug=settings.debug, encoding=settings.error_encoding, error_handler=settings.error_encoding_error_handler)
     94         document = nodes.document(settings, reporter, source=source_path)
     95         document.note_source(source_path, -1)
     96         try:
     97             parser.parse(data, document)
     98         except AttributeError:
     99             reporter.messages.append((-1,
    100              'Could not finish the parsing.',
    101              '',
    102              {}))
    103 
    104         return reporter.messages