desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Add \'dir\' to the list of directories that will be searched for
header files. The compiler is instructed to search directories in
the order in which they are supplied by successive calls to
\'add_include_dir()\'.'
| def add_include_dir(self, dir):
| self.include_dirs.append(dir)
|
'Set the list of directories that will be searched to \'dirs\' (a
list of strings). Overrides any preceding calls to
\'add_include_dir()\'; subsequence calls to \'add_include_dir()\' add
to the list passed to \'set_include_dirs()\'. This does not affect
any list of standard include directories that the compiler may
s... | def set_include_dirs(self, dirs):
| self.include_dirs = dirs[:]
|
'Add \'libname\' to the list of libraries that will be included in
all links driven by this compiler object. Note that \'libname\'
should *not* be the name of a file containing a library, but the
name of the library itself: the actual filename will be inferred by
the linker, the compiler, or the compiler class (depend... | def add_library(self, libname):
| self.libraries.append(libname)
|
'Set the list of libraries to be included in all links driven by
this compiler object to \'libnames\' (a list of strings). This does
not affect any standard system libraries that the linker may
include by default.'
| def set_libraries(self, libnames):
| self.libraries = libnames[:]
|
'Add \'dir\' to the list of directories that will be searched for
libraries specified to \'add_library()\' and \'set_libraries()\'. The
linker will be instructed to search for libraries in the order they
are supplied to \'add_library_dir()\' and/or \'set_library_dirs()\'.'
| def add_library_dir(self, dir):
| self.library_dirs.append(dir)
|
'Set the list of library search directories to \'dirs\' (a list of
strings). This does not affect any standard library search path
that the linker may search by default.'
| def set_library_dirs(self, dirs):
| self.library_dirs = dirs[:]
|
'Add \'dir\' to the list of directories that will be searched for
shared libraries at runtime.'
| def add_runtime_library_dir(self, dir):
| self.runtime_library_dirs.append(dir)
|
'Set the list of directories to search for shared libraries at
runtime to \'dirs\' (a list of strings). This does not affect any
standard search path that the runtime linker may search by
default.'
| def set_runtime_library_dirs(self, dirs):
| self.runtime_library_dirs = dirs[:]
|
'Add \'object\' to the list of object files (or analogues, such as
explicitly named library files or the output of "resource
compilers") to be included in every link driven by this compiler
object.'
| def add_link_object(self, object):
| self.objects.append(object)
|
'Set the list of object files (or analogues) to be included in
every link to \'objects\'. This does not affect any standard object
files that the linker may include by default (such as system
libraries).'
| def set_link_objects(self, objects):
| self.objects = objects[:]
|
'Process arguments and decide which source files to compile.'
| def _setup_compile(self, outdir, macros, incdirs, sources, depends, extra):
| if (outdir is None):
outdir = self.output_dir
elif (not isinstance(outdir, str)):
raise TypeError("'output_dir' must be a string or None")
if (macros is None):
macros = self.macros
elif isinstance(macros, list):
macros = (macros + (self.macros or []))
... |
'Typecheck and fix-up some of the arguments to the \'compile()\'
method, and return fixed-up values. Specifically: if \'output_dir\'
is None, replaces it with \'self.output_dir\'; ensures that \'macros\'
is a list, and augments it with \'self.macros\'; ensures that
\'include_dirs\' is a list, and augments it with \'se... | def _fix_compile_args(self, output_dir, macros, include_dirs):
| if (output_dir is None):
output_dir = self.output_dir
elif (not isinstance(output_dir, str)):
raise TypeError("'output_dir' must be a string or None")
if (macros is None):
macros = self.macros
elif isinstance(macros, list):
macros = (macros + (self.macro... |
'Decide which souce files must be recompiled.
Determine the list of object files corresponding to \'sources\',
and figure out which ones really need to be recompiled.
Return a list of all object files and a dictionary telling
which source files can be skipped.'
| def _prep_compile(self, sources, output_dir, depends=None):
| objects = self.object_filenames(sources, output_dir=output_dir)
assert (len(objects) == len(sources))
return (objects, {})
|
'Typecheck and fix up some arguments supplied to various methods.
Specifically: ensure that \'objects\' is a list; if output_dir is
None, replace with self.output_dir. Return fixed versions of
\'objects\' and \'output_dir\'.'
| def _fix_object_args(self, objects, output_dir):
| if (not isinstance(objects, (list, tuple))):
raise TypeError("'objects' must be a list or tuple of strings")
objects = list(objects)
if (output_dir is None):
output_dir = self.output_dir
elif (not isinstance(output_dir, str)):
raise TypeError("'output_dir'... |
'Typecheck and fix up some of the arguments supplied to the
\'link_*\' methods. Specifically: ensure that all arguments are
lists, and augment them with their permanent versions
(eg. \'self.libraries\' augments \'libraries\'). Return a tuple with
fixed versions of all arguments.'
| def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs):
| if (libraries is None):
libraries = self.libraries
elif isinstance(libraries, (list, tuple)):
libraries = (list(libraries) + (self.libraries or []))
else:
raise TypeError("'libraries' (if supplied) must be a list of strings")
if (library_dirs is None):
... |
'Return true if we need to relink the files listed in \'objects\'
to recreate \'output_file\'.'
| def _need_link(self, objects, output_file):
| if self.force:
return True
else:
if self.dry_run:
newer = newer_group(objects, output_file, missing='newer')
else:
newer = newer_group(objects, output_file)
return newer
|
'Detect the language of a given file, or list of files. Uses
language_map, and language_order to do the job.'
| def detect_language(self, sources):
| if (not isinstance(sources, list)):
sources = [sources]
lang = None
index = len(self.language_order)
for source in sources:
(base, ext) = os.path.splitext(source)
extlang = self.language_map.get(ext)
try:
extindex = self.language_order.index(extlang)
... |
'Preprocess a single C/C++ source file, named in \'source\'.
Output will be written to file named \'output_file\', or stdout if
\'output_file\' not supplied. \'macros\' is a list of macro
definitions as for \'compile()\', which will augment the macros set
with \'define_macro()\' and \'undefine_macro()\'. \'include_di... | def preprocess(self, source, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None):
| pass
|
'Compile one or more source files.
\'sources\' must be a list of filenames, most likely C/C++
files, but in reality anything that can be handled by a
particular compiler and compiler class (eg. MSVCCompiler can
handle resource files in \'sources\'). Return a list of object
filenames, one per source filename in \'sourc... | def compile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, depends=None):
| (macros, objects, extra_postargs, pp_opts, build) = self._setup_compile(output_dir, macros, include_dirs, sources, depends, extra_postargs)
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
for obj in objects:
try:
(src, ext) = build[obj]
except KeyError:
con... |
'Compile \'src\' to product \'obj\'.'
| def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
| pass
|
'Link a bunch of stuff together to create a static library file.
The "bunch of stuff" consists of the list of object files supplied
as \'objects\', the extra object files supplied to
\'add_link_object()\' and/or \'set_link_objects()\', the libraries
supplied to \'add_library()\' and/or \'set_libraries()\', and the
libr... | def create_static_lib(self, objects, output_libname, output_dir=None, debug=0, target_lang=None):
| pass
|
'Link a bunch of stuff together to create an executable or
shared library file.
The "bunch of stuff" consists of the list of object files supplied
as \'objects\'. \'output_filename\' should be a filename. If
\'output_dir\' is supplied, \'output_filename\' is relative to it
(i.e. \'output_filename\' can provide direct... | def link(self, target_desc, objects, output_filename, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None, build_temp=None, target_lang=None):
| raise NotImplementedError
|
'Return the compiler option to add \'dir\' to the list of
directories searched for libraries.'
| def library_dir_option(self, dir):
| raise NotImplementedError
|
'Return the compiler option to add \'dir\' to the list of
directories searched for runtime libraries.'
| def runtime_library_dir_option(self, dir):
| raise NotImplementedError
|
'Return the compiler option to add \'dir\' to the list of libraries
linked into the shared library or executable.'
| def library_option(self, lib):
| raise NotImplementedError
|
'Return a boolean indicating whether funcname is supported on
the current platform. The optional arguments can be used to
augment the compilation environment.'
| def has_function(self, funcname, includes=None, include_dirs=None, libraries=None, library_dirs=None):
| import tempfile
if (includes is None):
includes = []
if (include_dirs is None):
include_dirs = []
if (libraries is None):
libraries = []
if (library_dirs is None):
library_dirs = []
(fd, fname) = tempfile.mkstemp('.c', funcname, text=True)
f = os.fdopen(fd, 'w... |
'Search the specified list of directories for a static or shared
library file \'lib\' and return the full path to that file. If
\'debug\' true, look for a debugging version (if that makes sense on
the current platform). Return None if \'lib\' wasn\'t found in any of
the specified directories.'
| def find_library_file(self, dirs, lib, debug=0):
| raise NotImplementedError
|
'Returns rc file path.'
| def _get_rc_file(self):
| return os.path.join(os.path.expanduser('~'), '.pypirc')
|
'Creates a default .pypirc file.'
| def _store_pypirc(self, username, password):
| rc = self._get_rc_file()
with os.fdopen(os.open(rc, (os.O_CREAT | os.O_WRONLY), 384), 'w') as f:
f.write((DEFAULT_PYPIRC % (username, password)))
|
'Reads the .pypirc file.'
| def _read_pypirc(self):
| rc = self._get_rc_file()
if os.path.exists(rc):
self.announce(('Using PyPI login from %s' % rc))
repository = (self.repository or self.DEFAULT_REPOSITORY)
realm = (self.realm or self.DEFAULT_REALM)
config = ConfigParser()
config.read(rc)
sections = con... |
'Read and decode a PyPI HTTP response.'
| def _read_pypi_response(self, response):
| import cgi
content_type = response.getheader('content-type', 'text/plain')
encoding = cgi.parse_header(content_type)[1].get('charset', 'ascii')
return response.read().decode(encoding)
|
'Initialize options.'
| def initialize_options(self):
| self.repository = None
self.realm = None
self.show_response = 0
|
'Finalizes options.'
| def finalize_options(self):
| if (self.repository is None):
self.repository = self.DEFAULT_REPOSITORY
if (self.realm is None):
self.realm = self.DEFAULT_REALM
|
'Patches the environment.'
| def setUp(self):
| super(PyPIRCCommandTestCase, self).setUp()
self.tmp_dir = self.mkdtemp()
os.environ['HOME'] = self.tmp_dir
self.rc = os.path.join(self.tmp_dir, '.pypirc')
self.dist = Distribution()
class command(PyPIRCCommand, ):
def __init__(self, dist):
PyPIRCCommand.__init__(self, dist)
... |
'Removes the patch.'
| def tearDown(self):
| set_threshold(self.old_threshold)
super(PyPIRCCommandTestCase, self).tearDown()
|
'A directory in package_data should not be added to the filelist.'
| def test_dir_in_package_data(self):
| sources = self.mkdtemp()
pkg_dir = os.path.join(sources, 'pkg')
os.mkdir(pkg_dir)
open(os.path.join(pkg_dir, '__init__.py'), 'w').close()
docdir = os.path.join(pkg_dir, 'doc')
os.mkdir(docdir)
open(os.path.join(docdir, 'testfile'), 'w').close()
os.mkdir(os.path.join(docdir, 'otherdir'))
... |
'An exception in listdir should raise a DistutilsFileError'
| def test_copy_tree_exception_in_listdir(self):
| with patch('os.listdir', side_effect=OSError()):
with self.assertRaises(errors.DistutilsFileError):
src = self.tempdirs[(-1)]
dir_util.copy_tree(src, None)
|
'Create a temporary directory that will be cleaned up.
Returns the path of the directory.'
| def mkdtemp(self):
| d = tempfile.mkdtemp()
self.tempdirs.append(d)
return d
|
'Writes a file in the given path.
path can be a string or a sequence.'
| def write_file(self, path, content='xxx'):
| if isinstance(path, (list, tuple)):
path = os.path.join(*path)
f = open(path, 'w')
try:
f.write(content)
finally:
f.close()
|
'Will generate a test environment.
This function creates:
- a Distribution instance using keywords
- a temporary directory with a package structure
It returns the package directory and the distribution
instance.'
| def create_dist(self, pkg_name='foo', **kw):
| tmp_dir = self.mkdtemp()
pkg_dir = os.path.join(tmp_dir, pkg_name)
os.mkdir(pkg_dir)
dist = Distribution(attrs=kw)
return (pkg_dir, dist)
|
'Mirror test_make_tarball, except filename contains latin characters.'
| @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
@unittest.skipUnless(can_fs_encode('\xc3\xa5rchiv'), 'File system cannot handle this filename')
def test_make_tarball_latin1(self):
| self._make_tarball('\xc3\xa5rchiv')
|
'Mirror test_make_tarball, except filename contains extended
characters outside the latin charset.'
| @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
@unittest.skipUnless(can_fs_encode('\xe3\x81\xae\xe3\x82\xa2\xe3\x83\xbc\xe3\x82\xab\xe3\x82\xa4\xe3\x83\x96'), 'File system cannot handle this filename')
def test_make_tarball_extended(self):
| self._make_tarball('\xe3\x81\xae\xe3\x82\xa2\xe3\x83\xbc\xe3\x82\xab\xe3\x82\xa4\xe3\x83\x96')
|
'Returns a cmd'
| def get_cmd(self, metadata=None):
| if (metadata is None):
metadata = {'name': 'fake', 'version': '1.0', 'url': 'xxx', 'author': 'xxx', 'author_email': 'xxx'}
dist = Distribution(metadata)
dist.script_name = 'setup.py'
dist.packages = ['somecode']
dist.include_package_data = True
cmd = sdist(dist)
cmd.dist_dir = 'dist'... |
'Return true if the option table for this parser has an
option with long name \'long_option\'.'
| def has_option(self, long_option):
| return (long_option in self.option_index)
|
'Translate long option name \'long_option\' to the form it
has as an attribute of some object: ie., translate hyphens
to underscores.'
| def get_attr_name(self, long_option):
| return long_option.translate(longopt_xlate)
|
'Set the aliases for this option parser.'
| def set_aliases(self, alias):
| self._check_alias_dict(alias, 'alias')
self.alias = alias
|
'Set the negative aliases for this option parser.
\'negative_alias\' should be a dictionary mapping option names to
option names, both the key and value must already be defined
in the option table.'
| def set_negative_aliases(self, negative_alias):
| self._check_alias_dict(negative_alias, 'negative alias')
self.negative_alias = negative_alias
|
'Populate the various data structures that keep tabs on the
option table. Called by \'getopt()\' before it can do anything
worthwhile.'
| def _grok_option_table(self):
| self.long_opts = []
self.short_opts = []
self.short2long.clear()
self.repeat = {}
for option in self.option_table:
if (len(option) == 3):
(long, short, help) = option
repeat = 0
elif (len(option) == 4):
(long, short, help, repeat) = option
... |
'Parse command-line options in args. Store as attributes on object.
If \'args\' is None or not supplied, uses \'sys.argv[1:]\'. If
\'object\' is None or not supplied, creates a new OptionDummy
object, stores option values there, and returns a tuple (args,
object). If \'object\' is supplied, it is modified in place an... | def getopt(self, args=None, object=None):
| if (args is None):
args = sys.argv[1:]
if (object is None):
object = OptionDummy()
created_object = True
else:
created_object = False
self._grok_option_table()
short_opts = ' '.join(self.short_opts)
try:
(opts, args) = getopt.getopt(args, short_opts, se... |
'Returns the list of (option, value) tuples processed by the
previous run of \'getopt()\'. Raises RuntimeError if
\'getopt()\' hasn\'t been called yet.'
| def get_option_order(self):
| if (self.option_order is None):
raise RuntimeError("'getopt()' hasn't been called yet")
else:
return self.option_order
|
'Generate help text (a list of strings, one per suggested line of
output) from the option table for this FancyGetopt object.'
| def generate_help(self, header=None):
| max_opt = 0
for option in self.option_table:
long = option[0]
short = option[1]
l = len(long)
if (long[(-1)] == '='):
l = (l - 1)
if (short is not None):
l = (l + 5)
if (l > max_opt):
max_opt = l
opt_width = (((max_opt + 2) ... |
'Create a new OptionDummy instance. The attributes listed in
\'options\' will be initialized to None.'
| def __init__(self, options=[]):
| for opt in options:
setattr(self, opt, None)
|
'Construct a new Distribution instance: initialize all the
attributes of a Distribution, and then use \'attrs\' (a dictionary
mapping attribute names to values) to assign some of those
attributes their "real" values. (Any attributes not mentioned in
\'attrs\' will be assigned to some null value: 0, None, an empty list... | def __init__(self, attrs=None):
| self.verbose = 1
self.dry_run = 0
self.help = 0
for attr in self.display_option_names:
setattr(self, attr, 0)
self.metadata = DistributionMetadata()
for basename in self.metadata._METHOD_BASENAMES:
method_name = ('get_' + basename)
setattr(self, method_name, getattr(self.... |
'Get the option dictionary for a given command. If that
command\'s option dictionary hasn\'t been created yet, then create it
and return the new dictionary; otherwise, return the existing
option dictionary.'
| def get_option_dict(self, command):
| dict = self.command_options.get(command)
if (dict is None):
dict = self.command_options[command] = {}
return dict
|
'Find as many configuration files as should be processed for this
platform, and return a list of filenames in the order in which they
should be parsed. The filenames returned are guaranteed to exist
(modulo nasty race conditions).
There are three possible config files: distutils.cfg in the
Distutils installation direc... | def find_config_files(self):
| files = []
check_environ()
sys_dir = os.path.dirname(sys.modules['distutils'].__file__)
sys_file = os.path.join(sys_dir, 'distutils.cfg')
if os.path.isfile(sys_file):
files.append(sys_file)
if (os.name == 'posix'):
user_filename = '.pydistutils.cfg'
else:
user_filenam... |
'Parse the setup script\'s command line, taken from the
\'script_args\' instance attribute (which defaults to \'sys.argv[1:]\'
-- see \'setup()\' in core.py). This list is first processed for
"global options" -- options that set attributes of the Distribution
instance. Then, it is alternately scanned for Distutils co... | def parse_command_line(self):
| toplevel_options = self._get_toplevel_options()
self.commands = []
parser = FancyGetopt((toplevel_options + self.display_options))
parser.set_negative_aliases(self.negative_opt)
parser.set_aliases({'licence': 'license'})
args = parser.getopt(args=self.script_args, object=self)
option_order =... |
'Return the non-display options recognized at the top level.
This includes options that are recognized *only* at the top
level as well as options recognized for commands.'
| def _get_toplevel_options(self):
| return (self.global_options + [('command-packages=', None, 'list of packages that provide distutils commands')])
|
'Parse the command-line options for a single command.
\'parser\' must be a FancyGetopt instance; \'args\' must be the list
of arguments, starting with the current command (whose options
we are about to parse). Returns a new version of \'args\' with
the next command at the front of the list; will be the empty
list if t... | def _parse_command_opts(self, parser, args):
| from distutils.cmd import Command
command = args[0]
if (not command_re.match(command)):
raise SystemExit(("invalid command name '%s'" % command))
self.commands.append(command)
try:
cmd_class = self.get_command_class(command)
except DistutilsModuleError as msg:
ra... |
'Set final values for all the options on the Distribution
instance, analogous to the .finalize_options() method of Command
objects.'
| def finalize_options(self):
| for attr in ('keywords', 'platforms'):
value = getattr(self.metadata, attr)
if (value is None):
continue
if isinstance(value, str):
value = [elm.strip() for elm in value.split(',')]
setattr(self.metadata, attr, value)
|
'Show help for the setup script command-line in the form of
several lists of command-line options. \'parser\' should be a
FancyGetopt instance; do not expect it to be returned in the
same state, as its option table will be reset to make it
generate the correct help text.
If \'global_options\' is true, lists the global... | def _show_help(self, parser, global_options=1, display_options=1, commands=[]):
| from distutils.core import gen_usage
from distutils.cmd import Command
if global_options:
if display_options:
options = self._get_toplevel_options()
else:
options = self.global_options
parser.set_option_table(options)
parser.print_help((self.common_usa... |
'If there were any non-global "display-only" options
(--help-commands or the metadata display options) on the command
line, display the requested info and return true; else return
false.'
| def handle_display_options(self, option_order):
| from distutils.core import gen_usage
if self.help_commands:
self.print_commands()
print ''
print gen_usage(self.script_name)
return 1
any_display_options = 0
is_display_option = {}
for option in self.display_options:
is_display_option[option[0]] = 1
for (o... |
'Print a subset of the list of all commands -- used by
\'print_commands()\'.'
| def print_command_list(self, commands, header, max_length):
| print (header + ':')
for cmd in commands:
klass = self.cmdclass.get(cmd)
if (not klass):
klass = self.get_command_class(cmd)
try:
description = klass.description
except AttributeError:
description = '(no description available)'
pr... |
'Print out a help message listing all available commands with a
description of each. The list is divided into "standard commands"
(listed in distutils.command.__all__) and "extra commands"
(mentioned in self.cmdclass, but not a standard command). The
descriptions come from the command class attribute
\'description\'.... | def print_commands(self):
| import distutils.command
std_commands = distutils.command.__all__
is_std = {}
for cmd in std_commands:
is_std[cmd] = 1
extra_commands = []
for cmd in self.cmdclass.keys():
if (not is_std.get(cmd)):
extra_commands.append(cmd)
max_length = 0
for cmd in (std_comm... |
'Get a list of (command, description) tuples.
The list is divided into "standard commands" (listed in
distutils.command.__all__) and "extra commands" (mentioned in
self.cmdclass, but not a standard command). The descriptions come
from the command class attribute \'description\'.'
| def get_command_list(self):
| import distutils.command
std_commands = distutils.command.__all__
is_std = {}
for cmd in std_commands:
is_std[cmd] = 1
extra_commands = []
for cmd in self.cmdclass.keys():
if (not is_std.get(cmd)):
extra_commands.append(cmd)
rv = []
for cmd in (std_commands + ... |
'Return a list of packages from which commands are loaded.'
| def get_command_packages(self):
| pkgs = self.command_packages
if (not isinstance(pkgs, list)):
if (pkgs is None):
pkgs = ''
pkgs = [pkg.strip() for pkg in pkgs.split(',') if (pkg != '')]
if ('distutils.command' not in pkgs):
pkgs.insert(0, 'distutils.command')
self.command_packages = pkgs... |
'Return the class that implements the Distutils command named by
\'command\'. First we check the \'cmdclass\' dictionary; if the
command is mentioned there, we fetch the class object from the
dictionary and return it. Otherwise we load the command module
("distutils.command." + command) and fetch the command class fr... | def get_command_class(self, command):
| klass = self.cmdclass.get(command)
if klass:
return klass
for pkgname in self.get_command_packages():
module_name = ('%s.%s' % (pkgname, command))
klass_name = command
try:
__import__(module_name)
module = sys.modules[module_name]
except Import... |
'Return the command object for \'command\'. Normally this object
is cached on a previous call to \'get_command_obj()\'; if no command
object for \'command\' is in the cache, then we either create and
return it (if \'create\' is true) or return None.'
| def get_command_obj(self, command, create=1):
| cmd_obj = self.command_obj.get(command)
if ((not cmd_obj) and create):
if DEBUG:
self.announce(("Distribution.get_command_obj(): creating '%s' command object" % command))
klass = self.get_command_class(command)
cmd_obj = self.command_obj[command] = klass(self)
... |
'Set the options for \'command_obj\' from \'option_dict\'. Basically
this means copying elements of a dictionary (\'option_dict\') to
attributes of an instance (\'command\').
\'command_obj\' must be a Command instance. If \'option_dict\' is not
supplied, uses the standard option dictionary for this command
(from \'se... | def _set_command_options(self, command_obj, option_dict=None):
| command_name = command_obj.get_command_name()
if (option_dict is None):
option_dict = self.get_option_dict(command_name)
if DEBUG:
self.announce((" setting options for '%s' command:" % command_name))
for (option, (source, value)) in option_dict.items():
if DEBU... |
'Reinitializes a command to the state it was in when first
returned by \'get_command_obj()\': ie., initialized but not yet
finalized. This provides the opportunity to sneak option
values in programmatically, overriding or supplementing
user-supplied values from the config files and command line.
You\'ll have to re-fin... | def reinitialize_command(self, command, reinit_subcommands=0):
| from distutils.cmd import Command
if (not isinstance(command, Command)):
command_name = command
command = self.get_command_obj(command_name)
else:
command_name = command.get_command_name()
if (not command.finalized):
return command
command.initialize_options()
com... |
'Run each command that was seen on the setup script command line.
Uses the list of commands found and cache of command objects
created by \'get_command_obj()\'.'
| def run_commands(self):
| for cmd in self.commands:
self.run_command(cmd)
|
'Do whatever it takes to run a command (including nothing at all,
if the command has already been run). Specifically: if we have
already created and run the command named by \'command\', return
silently without doing anything. If the command named by \'command\'
doesn\'t even have a command object yet, create one. T... | def run_command(self, command):
| if self.have_run.get(command):
return
log.info('running %s', command)
cmd_obj = self.get_command_obj(command)
cmd_obj.ensure_finalized()
cmd_obj.run()
self.have_run[command] = 1
|
'Reads the metadata values from a file object.'
| def read_pkg_file(self, file):
| msg = message_from_file(file)
def _read_field(name):
value = msg[name]
if (value == 'UNKNOWN'):
return None
return value
def _read_list(name):
values = msg.get_all(name, None)
if (values == []):
return None
return values
metadata_ve... |
'Write the PKG-INFO file into the release tree.'
| def write_pkg_info(self, base_dir):
| with open(os.path.join(base_dir, 'PKG-INFO'), 'w', encoding='UTF-8') as pkg_info:
self.write_pkg_file(pkg_info)
|
'Write the PKG-INFO format data to a file object.'
| def write_pkg_file(self, file):
| version = '1.0'
if (self.provides or self.requires or self.obsoletes or self.classifiers or self.download_url):
version = '1.1'
file.write(('Metadata-Version: %s\n' % version))
file.write(('Name: %s\n' % self.get_name()))
file.write(('Version: %s\n' % self.get_version()))
file.w... |
'Print \'msg\' to stdout if the global DEBUG (taken from the
DISTUTILS_DEBUG environment variable) flag is true.'
| def debug_print(self, msg):
| from distutils.debug import DEBUG
if DEBUG:
print msg
|
'Select strings (presumably filenames) from \'self.files\' that
match \'pattern\', a Unix-style wildcard (glob) pattern. Patterns
are not quite the same as implemented by the \'fnmatch\' module: \'*\'
and \'?\' match non-special characters, where "special" is platform-
dependent: slash on Unix; colon, slash, and back... | def include_pattern(self, pattern, anchor=1, prefix=None, is_regex=0):
| files_found = False
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
self.debug_print(("include_pattern: applying regex r'%s'" % pattern_re.pattern))
if (self.allfiles is None):
self.findall()
for name in self.allfiles:
if pattern_re.search(name):
... |
'Remove strings (presumably filenames) from \'files\' that match
\'pattern\'. Other parameters are the same as for
\'include_pattern()\', above.
The list \'self.files\' is modified in place.
Return True if files are found, False otherwise.'
| def exclude_pattern(self, pattern, anchor=1, prefix=None, is_regex=0):
| files_found = False
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
self.debug_print(("exclude_pattern: applying regex r'%s'" % pattern_re.pattern))
for i in range((len(self.files) - 1), (-1), (-1)):
if pattern_re.search(self.files[i]):
self.debug_print((' ... |
'Return list of registry keys.'
| def read_keys(cls, base, key):
| try:
handle = RegOpenKeyEx(base, key)
except RegError:
return None
L = []
i = 0
while True:
try:
k = RegEnumKey(handle, i)
except RegError:
break
L.append(k)
i += 1
return L
|
'Return dict of registry keys and values.
All names are converted to lowercase.'
| def read_values(cls, base, key):
| try:
handle = RegOpenKeyEx(base, key)
except RegError:
return None
d = {}
i = 0
while True:
try:
(name, value, type) = RegEnumValue(handle, i)
except RegError:
break
name = name.lower()
d[cls.convert_mbcs(name)] = cls.convert_mb... |
'Return path to an MSVC executable program.
Tries to find the program in several places: first, one of the
MSVC program search paths from the registry; next, the directories
in the PATH environment variable. If any of those work, return an
absolute path that is known to exist. If none of them work, just
return the or... | def find_exe(self, exe):
| for p in self.__paths:
fn = os.path.join(os.path.abspath(p), exe)
if os.path.isfile(fn):
return fn
for p in os.environ['Path'].split(';'):
fn = os.path.join(os.path.abspath(p), exe)
if os.path.isfile(fn):
return fn
return exe
|
'Return path to an MSVC executable program.
Tries to find the program in several places: first, one of the
MSVC program search paths from the registry; next, the directories
in the PATH environment variable. If any of those work, return an
absolute path that is known to exist. If none of them work, just
return the or... | def find_exe(self, exe):
| for p in self.__paths:
fn = os.path.join(os.path.abspath(p), exe)
if os.path.isfile(fn):
return fn
for p in os.environ['Path'].split(';'):
fn = os.path.join(os.path.abspath(p), exe)
if os.path.isfile(fn):
return fn
return exe
|
'Get a list of devstudio directories (include, lib or path).
Return a list of strings. The list will be empty if unable to
access the registry or appropriate registry keys not found.'
| def get_msvc_paths(self, path, platform='x86'):
| if (not _can_read_reg):
return []
path = (path + ' dirs')
if (self.__version >= 7):
key = ('%s\\%0.1f\\VC\\VC_OBJECTS_PLATFORM_INFO\\Win32\\Directories' % (self.__root, self.__version))
else:
key = ('%s\\6.0\\Build System\\Components\\Platforms\\Win32 (%s)\\Directories' ... |
'Set environment variable \'name\' to an MSVC path type value.
This is equivalent to a SET command prior to execution of spawned
commands.'
| def set_path_env_var(self, name):
| if (name == 'lib'):
p = self.get_msvc_paths('library')
else:
p = self.get_msvc_paths(name)
if p:
os.environ[name] = ';'.join(p)
|
'Parse a version predicate string.'
| def __init__(self, versionPredicateStr):
| versionPredicateStr = versionPredicateStr.strip()
if (not versionPredicateStr):
raise ValueError('empty package restriction')
match = re_validPackage.match(versionPredicateStr)
if (not match):
raise ValueError(('bad package name in %r' % versionPredicateStr))
(self.... |
'True if version is compatible with all the predicates in self.
The parameter version must be acceptable to the StrictVersion
constructor. It may be either a string or StrictVersion.'
| def satisfied_by(self, version):
| for (cond, ver) in self.pred:
if (not compmap[cond](version, ver)):
return False
return True
|
'Compiles the source by spawning GCC and windres if needed.'
| def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
| if ((ext == '.rc') or (ext == '.res')):
try:
self.spawn(['windres', '-i', src, '-o', obj])
except DistutilsExecError as msg:
raise CompileError(msg)
else:
try:
self.spawn((((self.compiler_so + cc_args) + [src, '-o', obj]) + extra_postargs))
exc... |
'Link the objects.'
| def link(self, target_desc, objects, output_filename, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None, build_temp=None, target_lang=None):
| extra_preargs = copy.copy((extra_preargs or []))
libraries = copy.copy((libraries or []))
objects = copy.copy((objects or []))
libraries.extend(self.dll_libraries)
if ((export_symbols is not None) and ((target_desc != self.EXECUTABLE) or (self.linker_dll == 'gcc'))):
temp_dir = os.path.dirna... |
'Adds supports for rc and res files.'
| def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
| if (output_dir is None):
output_dir = ''
obj_names = []
for src_name in source_filenames:
(base, ext) = os.path.splitext(os.path.normcase(src_name))
if (ext not in (self.src_extensions + ['.rc', '.res'])):
raise UnknownFileError(("unknown file type '%s' (from ... |
'Construct a new TextFile object. At least one of \'filename\'
(a string) and \'file\' (a file-like object) must be supplied.
They keyword argument options are described above and affect
the values returned by \'readline()\'.'
| def __init__(self, filename=None, file=None, **options):
| if ((filename is None) and (file is None)):
raise RuntimeError("you must supply either or both of 'filename' and 'file'")
for opt in self.default_options.keys():
if (opt in options):
setattr(self, opt, options[opt])
else:
setattr(self, o... |
'Open a new file named \'filename\'. This overrides both the
\'filename\' and \'file\' arguments to the constructor.'
| def open(self, filename):
| self.filename = filename
self.file = io.open(self.filename, 'r', errors=self.errors)
self.current_line = 0
|
'Close the current file and forget everything we know about it
(filename, current line number).'
| def close(self):
| self.file.close()
self.file = None
self.filename = None
self.current_line = None
|
'Print (to stderr) a warning message tied to the current logical
line in the current file. If the current logical line in the
file spans multiple physical lines, the warning refers to the
whole range, eg. "lines 3-5". If \'line\' supplied, it overrides
the current line number; it may be a list or tuple to indicate a
... | def warn(self, msg, line=None):
| sys.stderr.write((('warning: ' + self.gen_error(msg, line)) + '\n'))
|
'Read and return a single logical line from the current file (or
from an internal buffer if lines have previously been "unread"
with \'unreadline()\'). If the \'join_lines\' option is true, this
may involve reading multiple physical lines concatenated into a
single string. Updates the current line number, so calling
... | def readline(self):
| if self.linebuf:
line = self.linebuf[(-1)]
del self.linebuf[(-1)]
return line
buildup_line = ''
while True:
line = self.file.readline()
if (line == ''):
line = None
if (self.strip_comments and line):
pos = line.find('#')
if ... |
'Read and return the list of all logical lines remaining in the
current file.'
| def readlines(self):
| lines = []
while True:
line = self.readline()
if (line is None):
return lines
lines.append(line)
|
'Push \'line\' (a string) onto an internal buffer that will be
checked by future \'readline()\' calls. Handy for implementing
a parser with line-at-a-time lookahead.'
| def unreadline(self, line):
| self.linebuf.append(line)
|
'Create and initialize a new Command object. Most importantly,
invokes the \'initialize_options()\' method, which is the real
initializer and depends on the actual command being
instantiated.'
| def __init__(self, dist):
| from distutils.dist import Distribution
if (not isinstance(dist, Distribution)):
raise TypeError('dist must be a Distribution instance')
if (self.__class__ is Command):
raise RuntimeError('Command is an abstract class')
self.distribution = dist
self.initial... |
'Set default values for all the options that this command
supports. Note that these defaults may be overridden by other
commands, by the setup script, by config files, or by the
command-line. Thus, this is not the place to code dependencies
between options; generally, \'initialize_options()\' implementations
are just... | def initialize_options(self):
| raise RuntimeError(('abstract method -- subclass %s must override' % self.__class__))
|
'Set final values for all the options that this command supports.
This is always called as late as possible, ie. after any option
assignments from the command-line or from other commands have been
done. Thus, this is the place to code option dependencies: if
\'foo\' depends on \'bar\', then it is safe to set \'foo\' ... | def finalize_options(self):
| raise RuntimeError(('abstract method -- subclass %s must override' % self.__class__))
|
'A command\'s raison d\'etre: carry out the action it exists to
perform, controlled by the options initialized in
\'initialize_options()\', customized by other commands, the setup
script, the command-line, and config files, and finalized in
\'finalize_options()\'. All terminal output and filesystem
interaction should ... | def run(self):
| raise RuntimeError(('abstract method -- subclass %s must override' % self.__class__))
|
'If the current verbosity level is of greater than or equal to
\'level\' print \'msg\' to stdout.'
| def announce(self, msg, level=1):
| log.log(level, msg)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.