desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'The python ``Executable``.'
def python(self, *args, **kwargs):
inspect.getmodule(self).python(*args, **kwargs)
'Runs the waf ``Executable``.'
def waf(self, *args, **kwargs):
jobs = inspect.getmodule(self).make_jobs with working_dir(self.build_directory): self.python('waf', '-j{0}'.format(jobs), *args, **kwargs)
'Configures the project.'
def configure(self, spec, prefix):
args = self.configure_args(spec, prefix) self.waf('configure', *args)
'Arguments to pass to configure.'
def configure_args(self, spec, prefix):
return ['--prefix={0}'.format(prefix)]
'Executes the build.'
def build(self, spec, prefix):
args = self.build_args(spec, prefix) self.waf('build', *args)
'Arguments to pass to build.'
def build_args(self, spec, prefix):
return []
'Installs the targets on the system.'
def install(self, spec, prefix):
args = self.install_args(spec, prefix) self.waf('install', *args)
'Arguments to pass to install.'
def install_args(self, spec, prefix):
return []
'Run unit tests after build. By default, does nothing. Override this if you want to add package-specific tests.'
def test(self):
pass
'Run unit tests after install. By default, does nothing. Override this if you want to add package-specific tests.'
def installtest(self):
pass
'Produces a list containing the arguments that must be passed to :py:meth:`~.PerlPackage.configure`. Arguments should not include the installation base directory, which is prepended automatically. :return: list of arguments for Makefile.PL or Build.PL'
def configure_args(self):
return []
'Runs Makefile.PL or Build.PL with arguments consisting of an appropriate installation base directory followed by the list returned by :py:meth:`~.PerlPackage.configure_args`. :raise RuntimeError: if neither Makefile.PL or Build.PL exist'
def configure(self, spec, prefix):
if os.path.isfile('Makefile.PL'): self.build_method = 'Makefile.PL' self.build_executable = inspect.getmodule(self).make elif os.path.isfile('Build.PL'): self.build_method = 'Build.PL' self.build_executable = Executable(join_path(self.stage.source_path, 'Build')) else: raise RuntimeError('Unknown build_method for perl package') if (self.build_method == 'Makefile.PL'): options = ['Makefile.PL', 'INSTALL_BASE={0}'.format(prefix)] elif (self.build_method == 'Build.PL'): options = ['Build.PL', '--install_base', prefix] options += self.configure_args() inspect.getmodule(self).perl(*options)
'Builds a Perl package.'
def build(self, spec, prefix):
self.build_executable()
'Runs built-in tests of a Perl package.'
def check(self):
self.build_executable('test')
'Installs a Perl package.'
def install(self, spec, prefix):
self.build_executable('install')
'Arguments to pass to build.'
def build_args(self, spec, prefix):
return []
'Build the package.'
def build(self, spec, prefix):
args = self.build_args(spec, prefix) inspect.getmodule(self).scons(*args)
'Arguments to pass to install.'
def install_args(self, spec, prefix):
return []
'Install the package.'
def install(self, spec, prefix):
args = self.install_args(spec, prefix) inspect.getmodule(self).scons('install', *args)
'Run unit tests after build. By default, does nothing. Override this if you want to add package-specific tests.'
def test(self):
pass
'Arguments to pass to install via ``--configure-args``.'
def configure_args(self, spec, prefix):
return []
'Arguments to pass to install via ``--configure-vars``.'
def configure_vars(self, spec, prefix):
return []
'Installs an R package.'
def install(self, spec, prefix):
config_args = self.configure_args(spec, prefix) config_vars = self.configure_vars(spec, prefix) args = ['CMD', 'INSTALL'] if config_args: args.append('--configure-args={0}'.format(' '.join(config_args))) if config_vars: args.append('--configure-vars={0}'.format(' '.join(config_vars))) args.extend(['--library={0}'.format(self.module.r_lib_dir), self.stage.source_path]) inspect.getmodule(self).R(*args)
'Returns the name of the setup file to use.'
def setup_file(self):
return 'setup.py'
'The directory containing the ``setup.py`` file.'
@property def build_directory(self):
return self.stage.source_path
'Determines whether or not a setup.py command exists. Args: command (str): The command to look for Returns: bool: True if the command is found, else False'
def _setup_command_available(self, command):
kwargs = {'output': os.devnull, 'error': os.devnull, 'fail_on_error': False} python = inspect.getmodule(self).python setup = self.setup_file() python(setup, '--no-user-cfg', command, '--help', **kwargs) return (python.returncode == 0)
'Build everything needed to install.'
def build(self, spec, prefix):
args = self.build_args(spec, prefix) self.setup_py('build', *args)
'Arguments to pass to build.'
def build_args(self, spec, prefix):
return []
'"Build" pure Python modules (copy to build directory).'
def build_py(self, spec, prefix):
args = self.build_py_args(spec, prefix) self.setup_py('build_py', *args)
'Arguments to pass to build_py.'
def build_py_args(self, spec, prefix):
return []
'Build C/C++ extensions (compile/link to build directory).'
def build_ext(self, spec, prefix):
args = self.build_ext_args(spec, prefix) self.setup_py('build_ext', *args)
'Arguments to pass to build_ext.'
def build_ext_args(self, spec, prefix):
return []
'Build C/C++ libraries used by Python extensions.'
def build_clib(self, spec, prefix):
args = self.build_clib_args(spec, prefix) self.setup_py('build_clib', *args)
'Arguments to pass to build_clib.'
def build_clib_args(self, spec, prefix):
return []
'"Build" scripts (copy and fixup #! line).'
def build_scripts(self, spec, prefix):
args = self.build_scripts_args(spec, prefix) self.setup_py('build_scripts', *args)
'Clean up temporary files from \'build\' command.'
def clean(self, spec, prefix):
args = self.clean_args(spec, prefix) self.setup_py('clean', *args)
'Arguments to pass to clean.'
def clean_args(self, spec, prefix):
return []
'Install everything from build directory.'
def install(self, spec, prefix):
args = self.install_args(spec, prefix) self.setup_py('install', *args)
'Arguments to pass to install.'
def install_args(self, spec, prefix):
args = ['--prefix={0}'.format(prefix)] if (('py-setuptools' == spec.name) or ('py-setuptools' in spec._dependencies)): args += ['--single-version-externally-managed', '--root=/'] return args
'Install all Python modules (extensions and pure Python).'
def install_lib(self, spec, prefix):
args = self.install_lib_args(spec, prefix) self.setup_py('install_lib', *args)
'Arguments to pass to install_lib.'
def install_lib_args(self, spec, prefix):
return []
'Install C/C++ header files.'
def install_headers(self, spec, prefix):
args = self.install_headers_args(spec, prefix) self.setup_py('install_headers', *args)
'Arguments to pass to install_headers.'
def install_headers_args(self, spec, prefix):
return []
'Install scripts (Python or otherwise).'
def install_scripts(self, spec, prefix):
args = self.install_scripts_args(spec, prefix) self.setup_py('install_scripts', *args)
'Arguments to pass to install_scripts.'
def install_scripts_args(self, spec, prefix):
return []
'Install data files.'
def install_data(self, spec, prefix):
args = self.install_data_args(spec, prefix) self.setup_py('install_data', *args)
'Arguments to pass to install_data.'
def install_data_args(self, spec, prefix):
return []
'Create a source distribution (tarball, zip file, etc.).'
def sdist(self, spec, prefix):
args = self.sdist_args(spec, prefix) self.setup_py('sdist', *args)
'Arguments to pass to sdist.'
def sdist_args(self, spec, prefix):
return []
'Register the distribution with the Python package index.'
def register(self, spec, prefix):
args = self.register_args(spec, prefix) self.setup_py('register', *args)
'Arguments to pass to register.'
def register_args(self, spec, prefix):
return []
'Create a built (binary) distribution.'
def bdist(self, spec, prefix):
args = self.bdist_args(spec, prefix) self.setup_py('bdist', *args)
'Arguments to pass to bdist.'
def bdist_args(self, spec, prefix):
return []
'Create a "dumb" built distribution.'
def bdist_dumb(self, spec, prefix):
args = self.bdist_dumb_args(spec, prefix) self.setup_py('bdist_dumb', *args)
'Arguments to pass to bdist_dumb.'
def bdist_dumb_args(self, spec, prefix):
return []
'Create an RPM distribution.'
def bdist_rpm(self, spec, prefix):
args = self.bdist_rpm(spec, prefix) self.setup_py('bdist_rpm', *args)
'Arguments to pass to bdist_rpm.'
def bdist_rpm_args(self, spec, prefix):
return []
'Create an executable installer for MS Windows.'
def bdist_wininst(self, spec, prefix):
args = self.bdist_wininst_args(spec, prefix) self.setup_py('bdist_wininst', *args)
'Arguments to pass to bdist_wininst.'
def bdist_wininst_args(self, spec, prefix):
return []
'Upload binary package to PyPI.'
def upload(self, spec, prefix):
args = self.upload_args(spec, prefix) self.setup_py('upload', *args)
'Arguments to pass to upload.'
def upload_args(self, spec, prefix):
return []
'Perform some checks on the package.'
def check(self, spec, prefix):
args = self.check_args(spec, prefix) self.setup_py('check', *args)
'Arguments to pass to check.'
def check_args(self, spec, prefix):
return []
'Run unit tests after in-place build. These tests are only run if the package actually has a \'test\' command.'
def test(self):
if self._setup_command_available('test'): args = self.test_args(self.spec, self.prefix) self.setup_py('test', *args)
'Arguments to pass to test.'
def test_args(self, spec, prefix):
return []
'Attempts to import the module that was just installed. This test is only run if the package overrides :py:attr:`import_modules` with a list of module names.'
def import_module_test(self):
with working_dir('..'): for module in self.import_modules: self.python('-c', 'import {0}'.format(module))
'The relative path to the directory containing CMakeLists.txt This path is relative to the root of the extracted tarball, not to the ``build_directory``. Defaults to the current directory. :return: directory containing CMakeLists.txt'
@property def root_cmakelists_dir(self):
return self.stage.source_path
'Standard cmake arguments provided as a property for convenience of package writers :return: standard cmake arguments'
@property def std_cmake_args(self):
return CMakePackage._std_args(self)
'Computes the standard cmake arguments for a generic package'
@staticmethod def _std_args(pkg):
try: build_type = pkg.spec.variants['build_type'].value except KeyError: build_type = 'RelWithDebInfo' args = ['-DCMAKE_INSTALL_PREFIX:PATH={0}'.format(pkg.prefix), '-DCMAKE_BUILD_TYPE:STRING={0}'.format(build_type), '-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON'] if platform.mac_ver()[0]: args.append('-DCMAKE_FIND_FRAMEWORK:STRING=LAST') args.append('-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=FALSE') rpaths = ':'.join(spack.build_environment.get_rpaths(pkg)) args.append('-DCMAKE_INSTALL_RPATH:STRING={0}'.format(rpaths)) return args
'Returns the directory to use when building the package :return: directory where to build the package'
@property def build_directory(self):
return join_path(self.stage.source_path, 'spack-build')
'Produces a list containing all the arguments that must be passed to cmake, except: * CMAKE_INSTALL_PREFIX * CMAKE_BUILD_TYPE which will be set automatically. :return: list of arguments for cmake'
def cmake_args(self):
return []
'Runs ``cmake`` in the build directory'
def cmake(self, spec, prefix):
options = [os.path.abspath(self.root_cmakelists_dir)] options += self.std_cmake_args options += self.cmake_args() with working_dir(self.build_directory, create=True): inspect.getmodule(self).cmake(*options)
'Make the build targets'
def build(self, spec, prefix):
with working_dir(self.build_directory): inspect.getmodule(self).make(*self.build_targets)
'Make the install targets'
def install(self, spec, prefix):
with working_dir(self.build_directory): inspect.getmodule(self).make(*self.install_targets)
'Searches the CMake-generated Makefile for the target ``test`` and runs it if found.'
def check(self):
with working_dir(self.build_directory): self._if_make_target_execute('test')
'Produces a list containing all the arguments that must be passed to qmake'
def qmake_args(self):
return []
'Run ``qmake`` to configure the project and generate a Makefile.'
def qmake(self, spec, prefix):
inspect.getmodule(self).qmake(*self.qmake_args())
'Make the build targets'
def build(self, spec, prefix):
inspect.getmodule(self).make()
'Make the install targets'
def install(self, spec, prefix):
inspect.getmodule(self).make('install')
'Searches the Makefile for a ``check:`` target and runs it if found.'
def check(self):
self._if_make_target_execute('check')
'Support instance methods.'
def __get__(self, obj, objtype):
return functools.partial(self.__call__, obj)
'Expunge cache so that self.func will be called again.'
def clear(self):
self.cache.clear()
'Type-agnostic clone method. Preserves subclass type.'
def copy(self):
T = type(self) clone = T() for key in self: clone[key] = self[key].copy() return clone
'Closes the pipes'
def __del__(self):
os.close(self.write) os.close(self.read)
'Redirect output from the with block to a file. Hijacks stdout / stderr and writes to the pipe connected to the logger daemon'
def __enter__(self):
self._force_color = color._force_color self._debug = tty._debug write = self.write try: self._stdout = os.dup(sys.stdout.fileno()) self._stderr = os.dup(sys.stderr.fileno()) os.dup2(write, sys.stdout.fileno()) os.dup2(write, sys.stderr.fileno()) except AttributeError: self.directAssignment = True self._stdout = sys.stdout self._stderr = sys.stderr output_redirect = os.fdopen(write, 'w') sys.stdout = output_redirect sys.stderr = output_redirect if self.force_color: color._force_color = True if self.debug: tty._debug = True
'Plugs back the original file descriptors for stdout and stderr'
def __exit__(self, exc_type, exception, traceback):
sys.stdout.flush() sys.stderr.flush() if self.directAssignment: sys.stdout = self._stdout sys.stderr = self._stderr else: os.dup2(self._stdout, sys.stdout.fileno()) os.dup2(self._stderr, sys.stderr.fileno()) color._force_color = self._force_color tty._debug = self._debug
'Returns a TTY escape sequence for a color'
def escape(self, s):
if self.color: return ('\x1b[%sm' % s) else: return ''
'Convert a match object generated by ``color_re`` into an ansi color code. This can be used as a handler in ``re.sub``.'
def __call__(self, match):
(style, color, text) = match.groups() m = match.group(0) if (m == '@@'): return '@' elif (m == '@.'): return self.escape(0) elif (m == '@'): raise ColorParseError(("Incomplete color format: '%s' in %s" % (m, match.string))) string = styles[style] if color: if (color not in colors): raise ColorParseError(("invalid color specifier: '%s' in '%s'" % (color, match.string))) string += (';' + str(colors[color])) colored_text = '' if text: colored_text = (text + self.escape(0)) return (self.escape(string) + colored_text)
'Returns the first file in dest that conflicts with src'
def find_conflict(self, dest_root, **kwargs):
kwargs['follow_nonexisting'] = False for (src, dest) in traverse_tree(self._root, dest_root, **kwargs): if os.path.isdir(src): if (os.path.exists(dest) and (not os.path.isdir(dest))): return dest elif os.path.exists(dest): return dest return None
'Link all files in src into dest, creating directories if necessary.'
def merge(self, dest_root, **kwargs):
kwargs['order'] = 'pre' for (src, dest) in traverse_tree(self._root, dest_root, **kwargs): if os.path.isdir(src): if (not os.path.exists(dest)): mkdirp(dest) continue if (not os.path.isdir(dest)): raise ValueError(('File blocks directory: %s' % dest)) if (not os.listdir(dest)): marker = os.path.join(dest, empty_file_name) touch(marker) else: assert (not os.path.exists(dest)) os.symlink(src, dest)
'Unlink all files in dest that exist in src. Unlinks directories in dest if they are empty.'
def unmerge(self, dest_root, **kwargs):
kwargs['order'] = 'post' for (src, dest) in traverse_tree(self._root, dest_root, **kwargs): if os.path.isdir(src): if (not os.path.exists(dest)): continue if (not os.path.isdir(dest)): raise ValueError(('File blocks directory: %s' % dest)) if (not os.listdir(dest)): shutil.rmtree(dest, ignore_errors=True) marker = os.path.join(dest, empty_file_name) if os.path.exists(marker): os.remove(marker) elif os.path.exists(dest): if (not os.path.islink(dest)): raise ValueError(('%s is not a link tree!' % dest)) os.remove(dest)
'Stable de-duplication of the directories where the files reside. >>> l = LibraryList([\'/dir1/liba.a\', \'/dir2/libb.a\', \'/dir1/libc.a\']) >>> l.directories [\'/dir1\', \'/dir2\'] >>> h = HeaderList([\'/dir1/a.h\', \'/dir1/b.h\', \'/dir2/c.h\']) >>> h.directories [\'/dir1\', \'/dir2\'] Returns: list of strings: A list of directories'
@property def directories(self):
return list(dedupe((os.path.dirname(x) for x in self.files if os.path.dirname(x))))
'Stable de-duplication of the base-names in the list >>> l = LibraryList([\'/dir1/liba.a\', \'/dir2/libb.a\', \'/dir3/liba.a\']) >>> l.basenames [\'liba.a\', \'libb.a\'] >>> h = HeaderList([\'/dir1/a.h\', \'/dir2/b.h\', \'/dir3/a.h\']) >>> h.basenames [\'a.h\', \'b.h\'] Returns: list of strings: A list of base-names'
@property def basenames(self):
return list(dedupe((os.path.basename(x) for x in self.files)))
'Stable de-duplication of file names in the list without extensions >>> h = HeaderList([\'/dir1/a.h\', \'/dir2/b.h\', \'/dir3/a.h\']) >>> h.names [\'a\', \'b\'] Returns: list of strings: A list of files without extensions'
@property def names(self):
return list(dedupe((x.split('.')[0] for x in self.basenames)))
'Stable de-duplication of the headers. Returns: list of strings: A list of header files'
@property def headers(self):
return self.files
'Include flags >>> h = HeaderList([\'/dir1/a.h\', \'/dir1/b.h\', \'/dir2/c.h\']) >>> h.include_flags \'-I/dir1 -I/dir2\' Returns: str: A joined list of include flags'
@property def include_flags(self):
return ' '.join([('-I' + x) for x in self.directories])
'Macro definitions >>> h = HeaderList([\'/dir1/a.h\', \'/dir1/b.h\', \'/dir2/c.h\']) >>> h.add_macro(\'-DBOOST_LIB_NAME=boost_regex\') >>> h.add_macro(\'-DBOOST_DYN_LINK\') >>> h.macro_definitions \'-DBOOST_LIB_NAME=boost_regex -DBOOST_DYN_LINK\' Returns: str: A joined list of macro definitions'
@property def macro_definitions(self):
return ' '.join(self._macro_definitions)
'Include flags + macro definitions >>> h = HeaderList([\'/dir1/a.h\', \'/dir1/b.h\', \'/dir2/c.h\']) >>> h.cpp_flags \'-I/dir1 -I/dir2\' >>> h.add_macro(\'-DBOOST_DYN_LINK\') >>> h.cpp_flags \'-I/dir1 -I/dir2 -DBOOST_DYN_LINK\' Returns: str: A joined list of include flags and macro definitions'
@property def cpp_flags(self):
cpp_flags = self.include_flags if self.macro_definitions: cpp_flags += (' ' + self.macro_definitions) return cpp_flags
'Add a macro definition Parameters: macro (str): The macro to add'
def add_macro(self, macro):
self._macro_definitions.append(macro)
'Stable de-duplication of library files. Returns: list of strings: A list of library files'
@property def libraries(self):
return self.files