def test_subst_vars_escaped(self): d = {'prefix': '/usr/local', 'eprefix': '$prefix', 'datarootdir': '$prefix/share', 'datadir': '$datarootdir'} self.assertEqual(subst_vars('$datadir', d), '/usr/local/share') self.assertEqual(subst_vars('$$datadir', d), '$datadir')
def test_subst_vars_recursive(): d = {'prefix': '/usr/local', 'eprefix': '$prefix', 'datarootdir': '$prefix/share', 'datadir': '$datarootdir'} assert_equal(subst_vars('$eprefix', d), '/usr/local') assert_equal(subst_vars('$datadir', d), '/usr/local/share')
def resolve_paths(self, src_root_dir="."): variables = copy.copy(self._path_variables) variables.update(self._variables) variables["_srcrootdir"] = src_root_dir destdir = subst_vars("$destdir", variables) file_sections = {} for category in self.files: file_sections[category] = {} for name, section in self.files[category].items(): srcdir = subst_vars(section.source_dir, variables) target = subst_vars(section.target_dir, variables) if target: tail = explode_path(target)[1:] if not tail: raise ValueError( "Invalid target directory in section %r (not absolute: %r)" % (name, section.target_dir) ) else: raise ValueError("Invalid target directory in section %r: %r" % (name, section.target_dir)) target = os.path.join(destdir, os.path.join(*tail)) file_sections[category][name] = [ (os.path.join(srcdir, f), os.path.join(target, g)) for f, g in section.files ] return file_sections
def _finalize_unix(self): scheme = self.scheme if self.root: scheme["destdir"] = self.root # TODO: user and home schemes if self.prefix is None: prefix_customized = False else: prefix_customized = True if self.prefix is None: if self.exec_prefix is not None: raise DistutilsOptionError("must not supply exec-prefix without prefix") self.prefix = os.path.normpath(sys.prefix) self.exec_prefix = os.path.normpath(sys.exec_prefix) else: if self.exec_prefix is None: self.exec_prefix = self.prefix py_version_short = ".".join(map(str, sys.version_info[:2])) dist_name = self.distribution.pkg.name if prefix_customized: if op.normpath(self.prefix) != '/usr/local': # unix prefix scheme['prefix'] = self.prefix scheme['exec_prefix'] = self.exec_prefix else: scheme['prefix'] = self.prefix scheme['exec_prefix'] = self.exec_prefix # use deb_system on debian-like systems if 'deb_system' in INSTALL_SCHEMES: v = {'py_version_short': py_version_short, 'dist_name': dist_name, 'base': self.prefix} scheme['includedir'] = subst_vars(INSTALL_SCHEMES['deb_system']['headers'], v) scheme['sitedir'] = subst_vars(INSTALL_SCHEMES['deb_system']['purelib'], v) else: # If no prefix is specified, we'd like to avoid installing anything # in /usr by default (i.e. like autotools, everything in # /usr/local). If prefix is not /usr, then we can't really guess # the best default location. if hasattr(sys, 'real_prefix'): # run under virtualenv prefix = sys.prefix exec_prefix = sys.exec_prefix elif sys.prefix == '/usr': prefix = exec_prefix = '/usr/local' else: prefix = sys.prefix exec_prefix = sys.exec_prefix scheme['prefix'] = prefix scheme['exec_prefix'] = exec_prefix # use unix_local on debian-like systems if 'unix_local' in INSTALL_SCHEMES: v = {'py_version_short': py_version_short, 'dist_name': dist_name, 'base': prefix} scheme['includedir'] = subst_vars(INSTALL_SCHEMES['unix_local']['headers'], v) scheme['sitedir'] = subst_vars(INSTALL_SCHEMES['unix_local']['purelib'], v)
def set_scheme_unix(scheme, options, package): # This mess is the simplest solution I can think of to support: # - /usr/local as default for prefix while using debian/ubuntu changes # (dist-packages instead of site-packages) # - virtualenv support # - arbitrary python install # # Cases to consider: # - if prefix is given: # - prefix and exec_prefix are customized following their options # - if prefix is not given: # - if under virtualenv: prefix and exec_prefix are set to their sys.* values # - else on unix != darwin: using /usr/local # - else on darwin: using sys values if options.prefix is not None: scheme["prefix"] = options.prefix if options.eprefix is None: scheme["eprefix"] = scheme["prefix"] else: scheme["eprefix"] = options.eprefix elif options.prefix is None and options.eprefix is not None: raise NotImplementedError("Customizing exec_prefix without " \ "customizing prefix is not implemented yet") elif options.prefix is None and options.eprefix is None: # XXX: what is real_prefix used for venv_prefix = virtualenv_prefix() if venv_prefix is not None: scheme["prefix"] = scheme["eprefix"] = venv_prefix elif 'real_prefix' in sys.__dict__: raise NotImplementedError("sys.__dict__['real_prefix'] == True not supported yet") elif sys.platform == "darwin": scheme["prefix"] = op.normpath(sys.prefix) scheme["eprefix"] = op.normpath(sys.exec_prefix) else: # XXX: unix_local is an ubuntu/debian thing only ? from distutils.command.install import INSTALL_SCHEMES if "unix_local" in INSTALL_SCHEMES: dist_scheme = INSTALL_SCHEMES["unix_local"] # This madness is used to support ubuntu/debian customization prefix = "/usr/local" base = "/usr" py_version = sys.version.split()[0] py_version_short = py_version[0:3] dist_name = package.name v = {"base": base, "py_version_short": py_version_short, "dist_name": dist_name} scheme["prefix"] = scheme["eprefix"] = prefix scheme["sitedir"] = subst_vars(dist_scheme["purelib"], v) scheme["includedir"] = subst_vars(dist_scheme["headers"], v) else: scheme["prefix"] = scheme["eprefix"] = "/usr/local"
def resolve_paths(self, src_root_dir="."): self.path_variables['_srcrootdir'] = src_root_dir file_sections = {} for tp in self.files: file_sections[tp] = {} for name, section in self.files[tp].items(): srcdir = subst_vars(section.source_dir, self.path_variables) target = subst_vars(section.target_dir, self.path_variables) file_sections[tp][name] = \ [(os.path.join(srcdir, f), os.path.join(target, f)) for f in section.files] return file_sections
def _config_content(paths): keys = sorted(paths.keys()) n = max([len(k) for k in keys]) + 2 content = [] for name, value in sorted(paths.items()): content.append('%s = r"%s"' % (name.upper().ljust(n), subst_vars(value, paths))) return "\n".join(content)
def _prefix_destdir(path): destdir = subst_vars("$destdir", variables) if path: tail = explode_path(path)[1:] if not tail: raise ValueError("Invalid target directory in section %r " "(not absolute: %r)" % (name, path)) return os.path.join(destdir, os.path.join(*tail)) else: raise ValueError("Invalid target directory in section " "%r: %r" % (name, path))
def get_default_scheme(pkg_name, py_version_short=None, prefix=None): if py_version_short is None: py_version_short = ".".join([str(i) for i in sys.version_info[:2]]) if prefix is None: prefix = sys.exec_prefix scheme, _ = get_scheme(sys.platform) scheme["prefix"] = scheme["eprefix"] = prefix scheme["pkgname"] = pkg_name scheme["py_version_short"] = py_version_short ret = {} for k in scheme: ret[k] = subst_vars(scheme[k], scheme) return ret
def _resolve_paths(self, src_root_node, use_destdir): variables = copy.copy(self._path_variables) variables.update(self._variables) variables['_srcrootdir'] = src_root_node.abspath() root = find_root(src_root_node) def _prefix_destdir(path): destdir = subst_vars("$destdir", variables) if path: tail = explode_path(path)[1:] if not tail: raise ValueError("Invalid target directory in section %r " "(not absolute: %r)" % (name, path)) return os.path.join(destdir, os.path.join(*tail)) else: raise ValueError("Invalid target directory in section " "%r: %r" % (name, path)) node_sections = {} for category in self.files: node_sections[category] = {} for name, section in self.files[category].items(): srcdir = subst_vars(section.source_dir, variables) target = subst_vars(section.target_dir, variables) if use_destdir: target = _prefix_destdir(target) srcdir_node = root.find_node(srcdir) if srcdir_node is None: raise IOError("directory %r not found !" % (srcdir,)) target_node = root.make_node(target) node_sections[category][name] = \ [(srcdir_node.find_node(f), target_node.make_node(g)) for f, g in section.files] return node_sections
def build_bento_files(pkg): s = get_configured_state() scheme = s.paths if pkg.config_py is not None: tmp_config = os.path.join(BUILD_DIR, "__tmp_config.py") fid = open(tmp_config, "w") try: for name, value in scheme.items(): fid.write('%s = "%s"\n' % (name.upper(), subst_vars(value, scheme))) finally: fid.close() target = os.path.join(os.path.dirname(tmp_config), pkg.config_py) ensure_dir(target) rename(tmp_config, target) section = InstalledSection("bentofiles", "config", os.path.join("$_srcrootdir", BUILD_DIR), "$sitedir", [pkg.config_py]) return {"bentofiles": section} else: return {}
def test_subst_vars_simple(self): d = {'prefix': '/usr/local'} self.assertEqual(subst_vars('$prefix', d), d['prefix'])
def _resolve_isection(self, node, isection): source_dir = subst_vars(isection.source_dir, {"_srcrootdir": self.build_node.abspath()}) isection.source_dir = source_dir return isection
def test_subst_vars_simple(): d = {'prefix': '/usr/local'} assert_equal(subst_vars('$prefix', d), d['prefix'])
def _install_node(category, node, from_node, target_dir): installed_path = subst_vars(target_dir, scheme) target = os.path.join(installed_path, node.path_from(from_node)) copy_installer(node.srcpath(), target, category)
def resolve_path(self, path): variables = copy.copy(self._path_variables) variables.update(self._variables) return subst_vars(path, variables)