def finalize_options(self): super(build_ext, self).finalize_options() if self.strategy is not None: self.strategy = get_strategy(self.strategy) else: self.strategy = base.BuildStrategy()
def finalize_options(self): self.set_undefined_options('build', ('build_base', 'build_base'), ('build_lib', 'build_lib'), ('force', 'force')) if self.package is None: self.package = self.distribution.ext_package self.extensions = self.distribution.ext_modules self.libraries = self.distribution.libraries or [] self.py_modules = self.distribution.py_modules or [] self.py_modules_dict = {} self.data_files = self.distribution.data_files or [] if self.build_src is None: self.build_src = os.path.join( self.build_base, f"src.{get_platform()}-{sys.version[:3]}") if self.templates is not None: self.templates = [ get_template(name) for name in shlex.split(self.templates) ] if self.strategy is not None: self.strategy = get_strategy(self.strategy) if self.f2x_options is None: self.f2x_options = [] else: self.f2x_options = shlex.split(self.f2x_options) if self.inplace is None: build_ext = self.get_finalized_command('build_ext') self.inplace = build_ext.inplace
def _templates_from_args(log, args): strategy = None template_path = args.template_path or [] templates = [] if args.wrap: # Load strategy and build extension from F2x.distutils.strategy import get_strategy strategy = get_strategy(args.wrap) if not args.template: for name in strategy.templates: module = get_template(name) if module is None: continue for filename in module.templates or []: filepath = os.path.join(module.package_dir, filename) suffix, _ = os.path.splitext(os.path.basename(filename)) templates.append((module, filename, filepath, suffix)) if args.template: # If templates are supplied, process them for filename in args.template: try: if filename[0] == u'@': filename = filename[1:] filepath = os.path.join(template_package_dir, filename) template_path.append(os.path.dirname(filepath)) modpath, *_, basename = os.path.split(filename) suffix, _ = os.path.splitext(basename) module = get_template(modpath) else: filepath = filename basename, ext = os.path.splitext(filename) suffix = os.path.basename(basename) # Template without extension is most probably a built-in so we can (try to) load it if not ext: module = get_template(basename) else: module = None templates.append((module, filename, filepath, suffix)) except ImportError: log.warn(f'could not load template "{filename}" as {modpath}.') continue return templates, template_path, strategy
def get_items(self, names): # type: (List[str]) -> List[Tuple[str, BuildStrategy]] """ Collect strategies and return them with name. """ from F2x.distutils.strategy import get_strategy items = [] for name in names: mod = get_strategy(name) if mod is None: log.warning(f'Could not load strategy "{name}".') items.append((name, mod)) return items
def __init__(self, name, sources, **kwargs): """ Take every parameter as keyword argument to allow easier cloning later on. :param name: (Full) name of the extension. :param sources: List of sources to build into the extension. :param kwargs: * :code:`library_name` (optional) holds the name of the library to build. * :code:`strategy` (optional) selects a strategy to use for build. * :code:`templates` (optional) contains a list of templates or names of templates to load. * :code:`f2x_options` (optional) is used for passing extra arguments to F2x. * :code:`autosplit` allows to automatically split extensions so that every extension contains only one wrapped Fortran module (Default: False). * :code:`inline_sources` instructs the build process to compile all sources together into the final extension (Default: True). """ self._kwarg_keys = list(kwargs.keys()) self.library_name = kwargs.pop('library_name', None) self.strategy = kwargs.pop('strategy', 'lib') self.templates = kwargs.pop('templates', []) self.f2x_options = kwargs.pop('f2x_options', []) self.autosplit = kwargs.pop('autosplit', False) self.inline_sources = kwargs.pop('inline_sources', True) super(Extension, self).__init__(name, sources, **kwargs) if self.strategy is None or isinstance(self.strategy, str): from F2x.distutils.strategy import get_strategy self.strategy = get_strategy(self.strategy or 'lib') if self.templates: self.templates = self.strategy.load_templates(self.templates) else: self.templates = self.strategy.templates self.ext_modules = []
def _templates_from_args(self): strategy = None templates = [] template_args = self.args.template[:] if self.args.wrap: # Load strategy if supplied strategy = get_strategy(self.args.wrap) if strategy is not None and not templates: template_args = strategy.templates[:] if template_args: for filename in template_args: if filename[0] == '@': # Add internal template templates.append((filename, os.path.join(template_package_dir, filename[1:]), [])) else: # Add external template with path dirname, basename = os.path.split(filename) templates.append((basename, filename, [dirname])) return strategy, templates