desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'a // b'
| def __rfloordiv__(b, a):
| div = (a / b)
if isinstance(div, Rational):
return (div.numerator // div.denominator)
else:
return math.floor(div)
|
'a % b'
| def __mod__(a, b):
| div = (a // b)
return (a - (b * div))
|
'a % b'
| def __rmod__(b, a):
| div = (a // b)
return (a - (b * div))
|
'a ** b
If b is not an integer, the result will be a float or complex
since roots are generally irrational. If b is an integer, the
result will be rational.'
| def __pow__(a, b):
| if isinstance(b, Rational):
if (b.denominator == 1):
power = b.numerator
if (power >= 0):
return Fraction((a._numerator ** power), (a._denominator ** power))
else:
return Fraction((a._denominator ** (- power)), (a._numerator ** (- power)))
... |
'a ** b'
| def __rpow__(b, a):
| if ((b._denominator == 1) and (b._numerator >= 0)):
return (a ** b._numerator)
if isinstance(a, Rational):
return (Fraction(a.numerator, a.denominator) ** b)
if (b._denominator == 1):
return (a ** b._numerator)
return (a ** float(b))
|
'+a: Coerces a subclass instance to Fraction'
| def __pos__(a):
| return Fraction(a._numerator, a._denominator)
|
'-a'
| def __neg__(a):
| return Fraction((- a._numerator), a._denominator)
|
'abs(a)'
| def __abs__(a):
| return Fraction(abs(a._numerator), a._denominator)
|
'trunc(a)'
| def __trunc__(a):
| if (a._numerator < 0):
return (- ((- a._numerator) // a._denominator))
else:
return (a._numerator // a._denominator)
|
'hash(self)
Tricky because values that are exactly representable as a
float must have the same hash as that float.'
| def __hash__(self):
| if (self._denominator == 1):
return hash(self._numerator)
if (self == float(self)):
return hash(float(self))
else:
return hash((self._numerator, self._denominator))
|
'a == b'
| def __eq__(a, b):
| if isinstance(b, Rational):
return ((a._numerator == b.numerator) and (a._denominator == b.denominator))
if (isinstance(b, numbers.Complex) and (b.imag == 0)):
b = b.real
if isinstance(b, float):
if (math.isnan(b) or math.isinf(b)):
return (0.0 == b)
else:
... |
'Helper for comparison operators, for internal use only.
Implement comparison between a Rational instance `self`, and
either another Rational instance or a float `other`. If
`other` is not a Rational instance or a float, return
NotImplemented. `op` should be one of the six standard
comparison operators.'
| def _richcmp(self, other, op):
| if isinstance(other, Rational):
return op((self._numerator * other.denominator), (self._denominator * other.numerator))
if isinstance(other, complex):
raise TypeError('no ordering relation is defined for complex numbers')
if isinstance(other, float):
if (math.isn... |
'a < b'
| def __lt__(a, b):
| return a._richcmp(b, operator.lt)
|
'a > b'
| def __gt__(a, b):
| return a._richcmp(b, operator.gt)
|
'a <= b'
| def __le__(a, b):
| return a._richcmp(b, operator.le)
|
'a >= b'
| def __ge__(a, b):
| return a._richcmp(b, operator.ge)
|
'a != 0'
| def __nonzero__(a):
| return (a._numerator != 0)
|
'Create directories under ~'
| def create_home_path(self):
| if (not self.user):
return
home = convert_path(os.path.expanduser('~'))
for (name, path) in self.config_vars.iteritems():
if (path.startswith(home) and (not os.path.isdir(path))):
self.debug_print(("os.makedirs('%s', 0700)" % path))
os.makedirs(path, 448)
|
'Return true if the current distribution has any Python
modules to install.'
| def has_lib(self):
| return (self.distribution.has_pure_modules() or self.distribution.has_ext_modules())
|
'Deprecated API.'
| def check_metadata(self):
| warn('distutils.command.register.check_metadata is deprecated, use the check command instead', PendingDeprecationWarning)
check = self.distribution.get_command_obj('check')
check.ensure_finalized()
check.strict = self.strict
... |
'Reads the configuration file and set attributes.'
| def _set_config(self):
| config = self._read_pypirc()
if (config != {}):
self.username = config['username']
self.password = config['password']
self.repository = config['repository']
self.realm = config['realm']
self.has_config = True
else:
if (self.repository not in ('pypi', self.DEFA... |
'Fetch the list of classifiers from the server.'
| def classifiers(self):
| response = urllib2.urlopen((self.repository + '?:action=list_classifiers'))
log.info(response.read())
|
'Send the metadata to the package index server to be checked.'
| def verify_metadata(self):
| (code, result) = self.post_to_server(self.build_post_data('verify'))
log.info(('Server response (%s): %s' % (code, result)))
|
'Send the metadata to the package index server.
Well, do the following:
1. figure who the user is, and then
2. send the data as a Basic auth\'ed POST.
First we try to read the username/password from $HOME/.pypirc,
which is a ConfigParser-formatted file with a section
[distutils] containing username and password entries... | def send_metadata(self):
| if self.has_config:
choice = '1'
username = self.username
password = self.password
else:
choice = 'x'
username = password = ''
choices = '1 2 3 4'.split()
while (choice not in choices):
self.announce('We need to know who you are,... |
'Post a query to the server, and return a string response.'
| def post_to_server(self, data, auth=None):
| if ('name' in data):
self.announce(('Registering %s to %s' % (data['name'], self.repository)), log.INFO)
boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
sep_boundary = ('\n--' + boundary)
end_boundary = (sep_boundary + '--')
body = StringIO.StringIO()
for (key, ... |
'Generate list of \'(package,src_dir,build_dir,filenames)\' tuples'
| def get_data_files(self):
| data = []
if (not self.packages):
return data
for package in self.packages:
src_dir = self.get_package_dir(package)
build_dir = os.path.join(*([self.build_lib] + package.split('.')))
plen = 0
if src_dir:
plen = (len(src_dir) + 1)
filenames = [file[... |
'Return filenames for package\'s data files in \'src_dir\''
| def find_data_files(self, package, src_dir):
| globs = (self.package_data.get('', []) + self.package_data.get(package, []))
files = []
for pattern in globs:
filelist = glob(os.path.join(src_dir, convert_path(pattern)))
files.extend([fn for fn in filelist if (fn not in files)])
return files
|
'Copy data files into build directory'
| def build_package_data(self):
| for (package, src_dir, build_dir, filenames) in self.data_files:
for filename in filenames:
target = os.path.join(build_dir, filename)
self.mkpath(os.path.dirname(target))
self.copy_file(os.path.join(src_dir, filename), target, preserve_mode=False)
|
'Return the directory, relative to the top of the source
distribution, where package \'package\' should be found
(at least according to the \'package_dir\' option, if any).'
| def get_package_dir(self, package):
| path = package.split('.')
if (not self.package_dir):
if path:
return os.path.join(*path)
else:
return ''
else:
tail = []
while path:
try:
pdir = self.package_dir['.'.join(path)]
except KeyError:
t... |
'Finds individually-specified Python modules, ie. those listed by
module name in \'self.py_modules\'. Returns a list of tuples (package,
module_base, filename): \'package\' is a tuple of the path through
package-space to the module; \'module_base\' is the bare (no
packages, no dots) module name, and \'filename\' is th... | def find_modules(self):
| packages = {}
modules = []
for module in self.py_modules:
path = module.split('.')
package = '.'.join(path[0:(-1)])
module_base = path[(-1)]
try:
(package_dir, checked) = packages[package]
except KeyError:
package_dir = self.get_package_dir(pac... |
'Compute the list of all modules that will be built, whether
they are specified one-module-at-a-time (\'self.py_modules\') or
by whole packages (\'self.packages\'). Return a list of tuples
(package, module, module_file), just like \'find_modules()\' and
\'find_package_modules()\' do.'
| def find_all_modules(self):
| modules = []
if self.py_modules:
modules.extend(self.find_modules())
if self.packages:
for package in self.packages:
package_dir = self.get_package_dir(package)
m = self.find_package_modules(package, package_dir)
modules.extend(m)
return modules
|
'Check that \'self.compiler\' really is a CCompiler object;
if not, make it one.'
| def _check_compiler(self):
| from distutils.ccompiler import CCompiler, new_compiler
if (not isinstance(self.compiler, CCompiler)):
self.compiler = new_compiler(compiler=self.compiler, dry_run=self.dry_run, force=1)
customize_compiler(self.compiler)
if self.include_dirs:
self.compiler.set_include_dirs(se... |
'Construct a source file from \'body\' (a string containing lines
of C/C++ code) and \'headers\' (a list of header files to include)
and run it through the preprocessor. Return true if the
preprocessor succeeded, false if there were any errors.
(\'body\' probably isn\'t of much use, but what the heck.)'
| def try_cpp(self, body=None, headers=None, include_dirs=None, lang='c'):
| from distutils.ccompiler import CompileError
self._check_compiler()
ok = 1
try:
self._preprocess(body, headers, include_dirs, lang)
except CompileError:
ok = 0
self._clean()
return ok
|
'Construct a source file (just like \'try_cpp()\'), run it through
the preprocessor, and return true if any line of the output matches
\'pattern\'. \'pattern\' should either be a compiled regex object or a
string containing a regex. If both \'body\' and \'headers\' are None,
preprocesses an empty file -- which can be... | def search_cpp(self, pattern, body=None, headers=None, include_dirs=None, lang='c'):
| self._check_compiler()
(src, out) = self._preprocess(body, headers, include_dirs, lang)
if isinstance(pattern, str):
pattern = re.compile(pattern)
file = open(out)
match = 0
while 1:
line = file.readline()
if (line == ''):
break
if pattern.search(line)... |
'Try to compile a source file built from \'body\' and \'headers\'.
Return true on success, false otherwise.'
| def try_compile(self, body, headers=None, include_dirs=None, lang='c'):
| from distutils.ccompiler import CompileError
self._check_compiler()
try:
self._compile(body, headers, include_dirs, lang)
ok = 1
except CompileError:
ok = 0
log.info(((ok and 'success!') or 'failure.'))
self._clean()
return ok
|
'Try to compile and link a source file, built from \'body\' and
\'headers\', to executable form. Return true on success, false
otherwise.'
| def try_link(self, body, headers=None, include_dirs=None, libraries=None, library_dirs=None, lang='c'):
| from distutils.ccompiler import CompileError, LinkError
self._check_compiler()
try:
self._link(body, headers, include_dirs, libraries, library_dirs, lang)
ok = 1
except (CompileError, LinkError):
ok = 0
log.info(((ok and 'success!') or 'failure.'))
self._clean()
retur... |
'Try to compile, link to an executable, and run a program
built from \'body\' and \'headers\'. Return true on success, false
otherwise.'
| def try_run(self, body, headers=None, include_dirs=None, libraries=None, library_dirs=None, lang='c'):
| from distutils.ccompiler import CompileError, LinkError
self._check_compiler()
try:
(src, obj, exe) = self._link(body, headers, include_dirs, libraries, library_dirs, lang)
self.spawn([exe])
ok = 1
except (CompileError, LinkError, DistutilsExecError):
ok = 0
log.info(... |
'Determine if function \'func\' is available by constructing a
source file that refers to \'func\', and compiles and links it.
If everything succeeds, returns true; otherwise returns false.
The constructed source file starts out by including the header
files listed in \'headers\'. If \'decl\' is true, it then declares... | def check_func(self, func, headers=None, include_dirs=None, libraries=None, library_dirs=None, decl=0, call=0):
| self._check_compiler()
body = []
if decl:
body.append(('int %s ();' % func))
body.append('int main () {')
if call:
body.append((' %s();' % func))
else:
body.append((' %s;' % func))
body.append('}')
body = ('\n'.join(body) + '\n')
r... |
'Determine if \'library\' is available to be linked against,
without actually checking that any particular symbols are provided
by it. \'headers\' will be used in constructing the source file to
be compiled, but the only effect of this is to check if all the
header files listed are available. Any libraries listed in
... | def check_lib(self, library, library_dirs=None, headers=None, include_dirs=None, other_libraries=[]):
| self._check_compiler()
return self.try_link('int main (void) { }', headers, include_dirs, ([library] + other_libraries), library_dirs)
|
'Determine if the system header file named by \'header_file\'
exists and can be found by the preprocessor; return true if so,
false otherwise.'
| def check_header(self, header, include_dirs=None, library_dirs=None, lang='c'):
| return self.try_cpp(body='/* No body */', headers=[header], include_dirs=include_dirs)
|
'Sets default values for options.'
| def initialize_options(self):
| self.restructuredtext = 0
self.metadata = 1
self.strict = 0
self._warnings = 0
|
'Counts the number of warnings that occurs.'
| def warn(self, msg):
| self._warnings += 1
return Command.warn(self, msg)
|
'Runs the command.'
| def run(self):
| if self.metadata:
self.check_metadata()
if self.restructuredtext:
if HAS_DOCUTILS:
self.check_restructuredtext()
elif self.strict:
raise DistutilsSetupError('The docutils package is needed.')
if (self.strict and (self._warnings > 0)):
raise... |
'Ensures that all required elements of meta-data are supplied.
name, version, URL, (author and author_email) or
(maintainer and maintainer_email)).
Warns if any are missing.'
| def check_metadata(self):
| metadata = self.distribution.metadata
missing = []
for attr in ('name', 'version', 'url'):
if (not (hasattr(metadata, attr) and getattr(metadata, attr))):
missing.append(attr)
if missing:
self.warn(('missing required meta-data: %s' % ', '.join(missing)))
if me... |
'Checks if the long string fields are reST-compliant.'
| def check_restructuredtext(self):
| data = self.distribution.get_long_description()
for warning in self._check_rst_data(data):
line = warning[(-1)].get('line')
if (line is None):
warning = warning[1]
else:
warning = ('%s (line %s)' % (warning[1], line))
self.warn(warning)
|
'Returns warnings when the provided data doesn\'t compile.'
| def _check_rst_data(self, data):
| source_path = StringIO()
parser = Parser()
settings = frontend.OptionParser().get_default_values()
settings.tab_width = 4
settings.pep_references = None
settings.rfc_references = None
reporter = SilentReporter(source_path, settings.report_level, settings.halt_level, stream=settings.warning_s... |
'Generate the text of an RPM spec file and return it as a
list of strings (one per line).'
| def _make_spec_file(self):
| spec_file = [('%define name ' + self.distribution.get_name()), ('%define version ' + self.distribution.get_version().replace('-', '_')), ('%define unmangled_version ' + self.distribution.get_version()), ('%define release ' + self.release.replace('-', '_')), '', ('Summary: ' + self.distrib... |
'Format the changelog correctly and convert it to a list of strings'
| def _format_changelog(self, changelog):
| if (not changelog):
return changelog
new_changelog = []
for line in string.split(string.strip(changelog), '\n'):
line = string.strip(line)
if (line[0] == '*'):
new_changelog.extend(['', line])
elif (line[0] == '-'):
new_changelog.append(line)
e... |
'Ensure that the list of extensions (presumably provided as a
command option \'extensions\') is valid, i.e. it is a list of
Extension objects. We also support the old-style list of 2-tuples,
where the tuples are (ext_name, build_info), which are converted to
Extension instances here.
Raise DistutilsSetupError if the s... | def check_extensions_list(self, extensions):
| if (not isinstance(extensions, list)):
raise DistutilsSetupError, "'ext_modules' option must be a list of Extension instances"
for (i, ext) in enumerate(extensions):
if isinstance(ext, Extension):
continue
if ((not isinstance(ext, tuple)) or (len(ext) ... |
'Walk the list of source files in \'sources\', looking for SWIG
interface (.i) files. Run SWIG on all that are found, and
return a modified \'sources\' list with SWIG source files replaced
by the generated C (or C++) files.'
| def swig_sources(self, sources, extension):
| new_sources = []
swig_sources = []
swig_targets = {}
if self.swig_cpp:
log.warn('--swig-cpp is deprecated - use --swig-opts=-c++')
if (self.swig_cpp or ('-c++' in self.swig_opts) or ('-c++' in extension.swig_opts)):
target_ext = '.cpp'
else:
target_ext = '.... |
'Return the name of the SWIG executable. On Unix, this is
just "swig" -- it should be in the PATH. Tries a bit harder on
Windows.'
| def find_swig(self):
| if (os.name == 'posix'):
return 'swig'
elif (os.name == 'nt'):
for vers in ('1.3', '1.2', '1.1'):
fn = os.path.join(('c:\\swig%s' % vers), 'swig.exe')
if os.path.isfile(fn):
return fn
else:
return 'swig.exe'
elif (os.name == 'os2'):... |
'Returns the path of the filename for a given extension.
The file is located in `build_lib` or directly in the package
(inplace option).'
| def get_ext_fullpath(self, ext_name):
| all_dots = string.maketrans(('/' + os.sep), '..')
ext_name = ext_name.translate(all_dots)
fullname = self.get_ext_fullname(ext_name)
modpath = fullname.split('.')
filename = self.get_ext_filename(ext_name)
filename = os.path.split(filename)[(-1)]
if (not self.inplace):
filename = os.... |
'Returns the fullname of a given extension name.
Adds the `package.` prefix'
| def get_ext_fullname(self, ext_name):
| if (self.package is None):
return ext_name
else:
return ((self.package + '.') + ext_name)
|
'Convert the name of an extension (eg. "foo.bar") into the name
of the file from which it will be loaded (eg. "foo/bar.so", or
"foo\bar.pyd").'
| def get_ext_filename(self, ext_name):
| from distutils.sysconfig import get_config_var
ext_path = string.split(ext_name, '.')
if (os.name == 'os2'):
ext_path[(len(ext_path) - 1)] = ext_path[(len(ext_path) - 1)][:8]
so_ext = get_config_var('SO')
if ((os.name == 'nt') and self.debug):
return ((os.path.join(*ext_path) + '_d')... |
'Return the list of symbols that a shared extension has to
export. This either uses \'ext.export_symbols\' or, if it\'s not
provided, "init" + module_name. Only relevant on Windows, where
the .pyd file (DLL) must export the module "init" function.'
| def get_export_symbols(self, ext):
| initfunc_name = ('init' + ext.name.split('.')[(-1)])
if (initfunc_name not in ext.export_symbols):
ext.export_symbols.append(initfunc_name)
return ext.export_symbols
|
'Return the list of libraries to link against when building a
shared extension. On most platforms, this is just \'ext.libraries\';
on Windows and OS/2, we add the Python library (eg. python20.dll).'
| def get_libraries(self, ext):
| if (sys.platform == 'win32'):
from distutils.msvccompiler import MSVCCompiler
if (not isinstance(self.compiler, MSVCCompiler)):
template = 'python%d%d'
if self.debug:
template = (template + '_d')
pythonlib = (template % ((sys.hexversion >> 24), ((s... |
'Copy each script listed in \'self.scripts\'; if it\'s marked as a
Python script in the Unix way (first line matches \'first_line_re\',
ie. starts with "\#!" and contains "python"), then adjust the first
line to refer to the current Python interpreter as we copy.'
| def copy_scripts(self):
| _sysconfig = __import__('sysconfig')
self.mkpath(self.build_dir)
outfiles = []
for script in self.scripts:
adjust = 0
script = convert_path(script)
outfile = os.path.join(self.build_dir, os.path.basename(script))
outfiles.append(outfile)
if ((not self.force) and (... |
'Dialog(database, name, x, y, w, h, attributes, title, first,
default, cancel, bitmap=true)'
| def __init__(self, *args, **kw):
| Dialog.__init__(self, *args)
ruler = (self.h - 36)
self.line('BottomLine', 0, ruler, self.w, 0)
|
'Set the title text of the dialog at the top.'
| def title(self, title):
| self.text('Title', 15, 10, 320, 60, 196611, ('{\\VerdanaBold10}%s' % title))
|
'Add a back button with a given title, the tab-next button,
its name in the Control table, possibly initially disabled.
Return the button, so that events can be associated'
| def back(self, title, next, name='Back', active=1):
| if active:
flags = 3
else:
flags = 1
return self.pushbutton(name, 180, (self.h - 27), 56, 17, flags, title, next)
|
'Add a cancel button with a given title, the tab-next button,
its name in the Control table, possibly initially disabled.
Return the button, so that events can be associated'
| def cancel(self, title, next, name='Cancel', active=1):
| if active:
flags = 3
else:
flags = 1
return self.pushbutton(name, 304, (self.h - 27), 56, 17, flags, title, next)
|
'Add a Next button with a given title, the tab-next button,
its name in the Control table, possibly initially disabled.
Return the button, so that events can be associated'
| def next(self, title, next, name='Next', active=1):
| if active:
flags = 3
else:
flags = 1
return self.pushbutton(name, 236, (self.h - 27), 56, 17, flags, title, next)
|
'Add a button with a given title, the tab-next button,
its name in the Control table, giving its x position; the
y-position is aligned with the other buttons.
Return the button, so that events can be associated'
| def xbutton(self, name, title, next, xpos):
| return self.pushbutton(name, int(((self.w * xpos) - 28)), (self.h - 27), 56, 17, 3, title, next)
|
'Adds code to the installer to compute the location of Python.
Properties PYTHON.MACHINE.X.Y and PYTHON.USER.X.Y will be set from the
registry for each version of Python.
Properties TARGETDIRX.Y will be set from PYTHON.USER.X.Y if defined,
else from PYTHON.MACHINE.X.Y.
Properties PYTHONX.Y will be set to TARGETDIRX.Y\p... | def add_find_python(self):
| start = 402
for ver in self.versions:
install_path = ('SOFTWARE\\Python\\PythonCore\\%s\\InstallPath' % ver)
machine_reg = ('python.machine.' + ver)
user_reg = ('python.user.' + ver)
machine_prop = ('PYTHON.MACHINE.' + ver)
user_prop = ('PYTHON.USER.' + ver)
machi... |
'Callable used for the check sub-command.
Placed here so user_options can view it'
| def checking_metadata(self):
| return self.metadata_check
|
'Deprecated API.'
| def check_metadata(self):
| warn('distutils.command.sdist.check_metadata is deprecated, use the check command instead', PendingDeprecationWarning)
check = self.distribution.get_command_obj('check')
check.ensure_finalized()
check.run()
|
'Figure out the list of files to include in the source
distribution, and put it in \'self.filelist\'. This might involve
reading the manifest template (and writing the manifest), or just
reading the manifest, or just using the default file set -- it all
depends on the user\'s options.'
| def get_file_list(self):
| template_exists = os.path.isfile(self.template)
if (not template_exists):
self.warn((("manifest template '%s' does not exist " + '(using default file list)') % self.template))
self.filelist.findall()
if self.use_defaults:
self.add_defaults()
if template_exi... |
'Add all the default files to self.filelist:
- README or README.txt
- setup.py
- test/test*.py
- all pure Python modules mentioned in setup script
- all files pointed by package_data (build_py)
- all files defined in data_files.
- all files defined as scripts.
- all C sources listed as part of extensions or C libraries... | def add_defaults(self):
| standards = [('README', 'README.txt'), self.distribution.script_name]
for fn in standards:
if isinstance(fn, tuple):
alts = fn
got_it = 0
for fn in alts:
if os.path.exists(fn):
got_it = 1
self.filelist.append(fn)... |
'Read and parse manifest template file named by self.template.
(usually "MANIFEST.in") The parsing and processing is done by
\'self.filelist\', which updates itself accordingly.'
| def read_template(self):
| log.info("reading manifest template '%s'", self.template)
template = TextFile(self.template, strip_comments=1, skip_blanks=1, join_lines=1, lstrip_ws=1, rstrip_ws=1, collapse_join=1)
try:
while 1:
line = template.readline()
if (line is None):
break
... |
'Prune off branches that might slip into the file list as created
by \'read_template()\', but really don\'t belong there:
* the build tree (typically "build")
* the release tree itself (only an issue if we ran "sdist"
previously with --keep-temp, or it aborted)
* any RCS, CVS, .svn, .hg, .git, .bzr, _darcs directories'... | def prune_file_list(self):
| build = self.get_finalized_command('build')
base_dir = self.distribution.get_fullname()
self.filelist.exclude_pattern(None, prefix=build.build_base)
self.filelist.exclude_pattern(None, prefix=base_dir)
if (sys.platform == 'win32'):
seps = '/|\\\\'
else:
seps = '/'
vcs_dirs = ... |
'Write the file list in \'self.filelist\' (presumably as filled in
by \'add_defaults()\' and \'read_template()\') to the manifest file
named by \'self.manifest\'.'
| def write_manifest(self):
| if os.path.isfile(self.manifest):
fp = open(self.manifest)
try:
first_line = fp.readline()
finally:
fp.close()
if (first_line != '# file GENERATED by distutils, do NOT edit\n'):
log.info(("not writing to manually ma... |
'Read the manifest file (named by \'self.manifest\') and use it to
fill in \'self.filelist\', the list of files to include in the source
distribution.'
| def read_manifest(self):
| log.info("reading manifest file '%s'", self.manifest)
manifest = open(self.manifest)
while 1:
line = manifest.readline()
if (line == ''):
break
if (line[(-1)] == '\n'):
line = line[0:(-1)]
self.filelist.append(line)
manifest.close()
|
'Create the directory tree that will become the source
distribution archive. All directories implied by the filenames in
\'files\' are created under \'base_dir\', and then we hard link or copy
(if hard linking is unavailable) those files into place.
Essentially, this duplicates the developer\'s source tree, but in a
d... | def make_release_tree(self, base_dir, files):
| self.mkpath(base_dir)
dir_util.create_tree(base_dir, files, dry_run=self.dry_run)
if hasattr(os, 'link'):
link = 'hard'
msg = ('making hard links in %s...' % base_dir)
else:
link = None
msg = ('copying files to %s...' % base_dir)
if (not files):
... |
'Create the source distribution(s). First, we create the release
tree with \'make_release_tree()\'; then, we create all required
archive files (according to \'self.formats\') from the release tree.
Finally, we clean up by blowing away the release tree (unless
\'self.keep_temp\' is true). The list of archive files cre... | def make_distribution(self):
| base_dir = self.distribution.get_fullname()
base_name = os.path.join(self.dist_dir, base_dir)
self.make_release_tree(base_dir, self.filelist.files)
archive_files = []
if ('tar' in self.formats):
self.formats.append(self.formats.pop(self.formats.index('tar')))
for fmt in self.formats:
... |
'Return the list of archive files created when the command
was run, or None if the command hasn\'t run yet.'
| def get_archive_files(self):
| return self.archive_files
|
'Return the list of files that would be installed if this command
were actually run. Not affected by the "dry-run" flag or whether
modules have actually been built yet.'
| def get_outputs(self):
| pure_outputs = self._mutate_outputs(self.distribution.has_pure_modules(), 'build_py', 'build_lib', self.install_dir)
if self.compile:
bytecode_outputs = self._bytecode_filenames(pure_outputs)
else:
bytecode_outputs = []
ext_outputs = self._mutate_outputs(self.distribution.has_ext_modules... |
'Get the list of files that are input to this command, ie. the
files that get installed as they are named in the build tree.
The files in this list correspond one-to-one to the output
filenames returned by \'get_outputs()\'.'
| def get_inputs(self):
| inputs = []
if self.distribution.has_pure_modules():
build_py = self.get_finalized_command('build_py')
inputs.extend(build_py.get_outputs())
if self.distribution.has_ext_modules():
build_ext = self.get_finalized_command('build_ext')
inputs.extend(build_ext.get_outputs())
... |
'Ensure that the list of libraries is valid.
`library` is presumably provided as a command option \'libraries\'.
This method checks that it is a list of 2-tuples, where the tuples
are (library_name, build_info_dict).
Raise DistutilsSetupError if the structure is invalid anywhere;
just returns otherwise.'
| def check_library_list(self, libraries):
| if (not isinstance(libraries, list)):
raise DistutilsSetupError, "'libraries' option must be a list of tuples"
for lib in libraries:
if ((not isinstance(lib, tuple)) and (len(lib) != 2)):
raise DistutilsSetupError, "each element of 'libraries' must ... |
'Define the executables (and options for them) that will be run
to perform the various stages of compilation. The exact set of
executables that may be specified here depends on the compiler
class (via the \'executables\' class attribute), but most will have:
compiler the C/C++ compiler
linker_so linker used t... | def set_executables(self, **args):
| for key in args.keys():
if (key not in self.executables):
raise ValueError, ("unknown executable '%s' for class %s" % (key, self.__class__.__name__))
self.set_executable(key, args[key])
|
'Ensures that every element of \'definitions\' is a valid macro
definition, ie. either (name,value) 2-tuple or a (name,) tuple. Do
nothing if all definitions are OK, raise TypeError otherwise.'
| def _check_macro_definitions(self, definitions):
| for defn in definitions:
if (not (isinstance(defn, tuple) and ((len(defn) == 1) or ((len(defn) == 2) and (isinstance(defn[1], str) or (defn[1] is None)))) and isinstance(defn[0], str))):
raise TypeError, ((("invalid macro definition '%s': " % defn) + 'must be tuple (string,)... |
'Define a preprocessor macro for all compilations driven by this
compiler object. The optional parameter \'value\' should be a
string; if it is not supplied, then the macro will be defined
without an explicit value and the exact outcome depends on the
compiler used (XXX true? does ANSI say anything about this?)'
| def define_macro(self, name, value=None):
| i = self._find_macro(name)
if (i is not None):
del self.macros[i]
defn = (name, value)
self.macros.append(defn)
|
'Undefine a preprocessor macro for all compilations driven by
this compiler object. If the same macro is defined by
\'define_macro()\' and undefined by \'undefine_macro()\' the last call
takes precedence (including multiple redefinitions or
undefinitions). If the macro is redefined/undefined on a
per-compilation basi... | def undefine_macro(self, name):
| i = self._find_macro(name)
if (i is not None):
del self.macros[i]
undefn = (name,)
self.macros.append(undefn)
|
'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... |
'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 1
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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.