def copy_tree(source, destination): '''Copy (or update) a directory preserving symlinks ''' if not os.path.exists(source): raise OSError(errno.ENOENT, 'No such file or directory: ' + source) name = os.path.basename(source) debug('COPY', '%s from %s', name, os.path.dirname(source)) for root, _, files in os.walk(source): relpath = os.path.relpath(root, source) dirname = os.path.join(destination, relpath) _mkpath(dirname) for file_ in files: src = os.path.join(root, file_) dst = os.path.join(dirname, file_) if os.path.islink(src): try: os.remove(dst) except OSError: pass linkto = os.readlink(src) os.symlink(linkto, dst) else: copy_file(src, dst, update=True, verbose=False)
def run_sphinx(project_path, builders=['html', 'doctest'], keep=False, paper=''): '''Create and test documentation with Sphinx. ''' # change to ./doc dir os.chdir(os.path.join(project_path, 'doc')) doctrees = os.path.join('build', 'doctrees') for builder in builders: _rmtree(doctrees) _mkpath(doctrees) bildir = os.path.join('build', builder) _rmtree(bildir) _mkpath(bildir) # see _Sphinx_build -help opts = '-d', doctrees if _Verbose == 0: opts += '-q', # only warnings, no output if paper: # 'letter' or 'a4' opts += '-D', ('latex_paper_size=%s' % paper) opts += 'source', bildir # source and out dirs run_command(_Python_path, # use this Python binary os.path.join(project_path, 'tools', 'sphinx.py'), '-b', builder, *opts) if keep: # move bildir up _rmtree(builder) _mv(bildir, builder) # os.curdir zip_docs(builder, os.path.join('..', 'dist', 'pympler-docs.zip')) else: _rmtree(bildir) _rmtree(doctrees) os.chdir(project_path)
def run_sphinx(project_path, builders=['html', 'doctest'], keep=False, paper=''): '''Create and test documentation with Sphinx. ''' # change to ./doc dir os.chdir(os.path.join(project_path, 'doc')) doctrees = os.path.join('build', 'doctrees') for builder in builders: _rmtree(doctrees) _mkpath(doctrees) bildir = os.path.join('build', builder) _rmtree(bildir) _mkpath(bildir) # see _Sphinx_build -help opts = '-d', doctrees if _Verbose == 0: opts += '-q', # only warnings, no output if paper: # 'letter' or 'a4' opts += '-D', ('latex_paper_size=%s' % paper) opts += 'source', bildir # source and out dirs run_command(_Python_path, # use this Python binary os.path.join(project_path, 'tools', 'sphinx.py'), '-b', builder, *opts) if keep: # move bildir up _rmtree(builder) _mv(bildir, builder) # os.curdir zip_docs(builder, os.path.join('..', 'dist', 'pympler-docs.zip')) else: _rmtree(bildir) _rmtree(doctrees) os.chdir(project_path)
def _check_openmp_support(self): # Compile a test program to determine if compiler supports OpenMP. _mkpath(self.build_temp) with stdchannel_redirected(sys.stderr, os.devnull): with _tempfile.NamedTemporaryFile(mode='w', dir=self.build_temp, prefix='openmptest', suffix='.c') as srcfile: _log.info("checking if compiler supports OpenMP") srcfile.write(""" #include <omp.h> int testfunc() { int i; #pragma omp parallel for for (i = 0; i < 10; i ++) ; return omp_get_num_threads(); } """) srcfile.flush() try: objects = self.compiler.compile( [srcfile.name], extra_postargs=["-fopenmp"], output_dir=self.build_temp) except _CCompilerError: _log.info("compiler does not support OpenMP") use_openmp = False else: _log.info("enabling OpenMP support") use_openmp = True for o in objects: os.remove(o) return use_openmp
def build_extensions(self): if self.disable_openmp: _log.info("disabling OpenMP support") use_openmp = False else: # Compile a test program to determine if compiler supports OpenMP. _mkpath(self.build_temp) with _tempfile.NamedTemporaryFile(mode='w', dir=self.build_temp, prefix='openmptest', suffix='.c') as srcfile: _log.info("checking if compiler supports OpenMP") srcfile.write(""" #include <omp.h> int testfunc() { int i; #pragma omp parallel for for (i = 0; i < 10; i ++) ; return omp_get_num_threads(); } """) srcfile.flush() try: objects = self.compiler.compile( [srcfile.name], extra_postargs=["-fopenmp"], output_dir="/") except _CCompilerError: if self.enable_openmp: raise _DistutilsOptionError( "compiler does not support OpenMP") else: _log.info("compiler does not support OpenMP") use_openmp = False else: _log.info("enabling OpenMP support") use_openmp = True for o in objects: _os.remove(o) if use_openmp: for ext in self.extensions: if getattr(ext, 'openmp', False): if ext.extra_compile_args: ext.extra_compile_args += ['-fopenmp'] else: ext.extra_compile_args = ['-fopenmp'] if ext.extra_link_args: ext.extra_link_args += ['-fopenmp'] else: ext.extra_link_args = ['-fopenmp'] # Chain to method in parent class. _build_ext.build_extensions(self)
def build_extensions(self): if self.disable_openmp: _log.info("disabling OpenMP support") use_openmp = False else: # Compile a test program to determine if compiler supports OpenMP. _mkpath(self.build_temp) with _tempfile.NamedTemporaryFile(mode='w', dir=self.build_temp, prefix='openmptest', suffix='.c') as srcfile: _log.info("checking if compiler supports OpenMP") srcfile.write(""" #include <omp.h> int testfunc() { int i; #pragma omp parallel for for (i = 0; i < 10; i ++) ; return omp_get_num_threads(); } """) srcfile.flush() try: objects = self.compiler.compile([srcfile.name], extra_postargs=["-fopenmp"], output_dir="/") except _CCompilerError: if self.enable_openmp: raise _DistutilsOptionError("compiler does not support OpenMP") else: _log.info("compiler does not support OpenMP") use_openmp = False else: _log.info("enabling OpenMP support") use_openmp = True for o in objects: _os.remove(o) if use_openmp: for ext in self.extensions: if getattr(ext, 'openmp', False): if ext.extra_compile_args: ext.extra_compile_args += ['-fopenmp'] else: ext.extra_compile_args = ['-fopenmp'] if ext.extra_link_args: ext.extra_link_args += ['-fopenmp'] else: ext.extra_link_args = ['-fopenmp'] # Chain to method in parent class. _build_ext.build_extensions(self)
def make_tree(path): '''Create directories recursively if they don't exist ''' debug('MKDIR', path) return _mkpath(path)