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

core.py (4241B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\stdlib\distutils\core.py
      2 __revision__ = '$Id: core.py 87602 2011-01-01 04:24:26Z richard.tew $'
      3 import sys
      4 import os
      5 from distutils.debug import DEBUG
      6 from distutils.errors import DistutilsSetupError, DistutilsArgError, DistutilsError, CCompilerError
      7 from distutils.util import grok_environment_error
      8 from distutils.dist import Distribution
      9 from distutils.cmd import Command
     10 from distutils.config import PyPIRCCommand
     11 from distutils.extension import Extension
     12 USAGE = 'usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]\n   or: %(script)s --help [cmd1 cmd2 ...]\n   or: %(script)s --help-commands\n   or: %(script)s cmd --help\n'
     13 
     14 def gen_usage(script_name):
     15     script = os.path.basename(script_name)
     16     return USAGE % {'script': script}
     17 
     18 
     19 _setup_stop_after = None
     20 _setup_distribution = None
     21 setup_keywords = ('distclass', 'script_name', 'script_args', 'options', 'name', 'version', 'author', 'author_email', 'maintainer', 'maintainer_email', 'url', 'license', 'description', 'long_description', 'keywords', 'platforms', 'classifiers', 'download_url', 'requires', 'provides', 'obsoletes')
     22 extension_keywords = ('name', 'sources', 'include_dirs', 'define_macros', 'undef_macros', 'library_dirs', 'libraries', 'runtime_library_dirs', 'extra_objects', 'extra_compile_args', 'extra_link_args', 'swig_opts', 'export_symbols', 'depends', 'language')
     23 
     24 def setup(**attrs):
     25     global _setup_stop_after
     26     global _setup_distribution
     27     klass = attrs.get('distclass')
     28     if klass:
     29         del attrs['distclass']
     30     else:
     31         klass = Distribution
     32     if 'script_name' not in attrs:
     33         attrs['script_name'] = os.path.basename(sys.argv[0])
     34     if 'script_args' not in attrs:
     35         attrs['script_args'] = sys.argv[1:]
     36     try:
     37         _setup_distribution = dist = klass(attrs)
     38     except DistutilsSetupError as msg:
     39         if 'name' in attrs:
     40             raise SystemExit, 'error in %s setup command: %s' % (attrs['name'], msg)
     41         else:
     42             raise SystemExit, 'error in setup command: %s' % msg
     43 
     44     if _setup_stop_after == 'init':
     45         return dist
     46     dist.parse_config_files()
     47     if DEBUG:
     48         print 'options (after parsing config files):'
     49         dist.dump_option_dicts()
     50     if _setup_stop_after == 'config':
     51         return dist
     52     try:
     53         ok = dist.parse_command_line()
     54     except DistutilsArgError as msg:
     55         raise SystemExit, gen_usage(dist.script_name) + '\nerror: %s' % msg
     56 
     57     if DEBUG:
     58         print 'options (after parsing command line):'
     59         dist.dump_option_dicts()
     60     if _setup_stop_after == 'commandline':
     61         return dist
     62     if ok:
     63         try:
     64             dist.run_commands()
     65         except KeyboardInterrupt:
     66             raise SystemExit, 'interrupted'
     67         except (IOError, os.error) as exc:
     68             error = grok_environment_error(exc)
     69             if DEBUG:
     70                 sys.stderr.write(error + '\n')
     71                 raise
     72             else:
     73                 raise SystemExit, error
     74         except (DistutilsError, CCompilerError) as msg:
     75             if DEBUG:
     76                 raise
     77             else:
     78                 raise SystemExit, 'error: ' + str(msg)
     79 
     80     return dist
     81 
     82 
     83 def run_setup(script_name, script_args = None, stop_after = 'run'):
     84     global _setup_stop_after
     85     if stop_after not in ('init', 'config', 'commandline', 'run'):
     86         raise ValueError, "invalid value for 'stop_after': %r" % (stop_after,)
     87     _setup_stop_after = stop_after
     88     save_argv = sys.argv
     89     g = {'__file__': script_name}
     90     l = {}
     91     try:
     92         try:
     93             sys.argv[0] = script_name
     94             if script_args is not None:
     95                 sys.argv[1:] = script_args
     96             f = open(script_name)
     97             try:
     98                 exec f.read() in g, l
     99             finally:
    100                 f.close()
    101 
    102         finally:
    103             sys.argv = save_argv
    104             _setup_stop_after = None
    105 
    106     except SystemExit:
    107         pass
    108     except:
    109         raise
    110 
    111     if _setup_distribution is None:
    112         raise RuntimeError, "'distutils.core.setup()' was never called -- perhaps '%s' is not a Distutils setup script?" % script_name
    113     return _setup_distribution