コード例 #1
0
 def _expand_attrs(self, attrs):
     for attr in attrs:
         val = getattr(self, attr)
         if val is not None:
             if os.name == 'posix' or os.name == 'nt':
                 val = os.path.expanduser(val)
             val = subst_vars(val, self.config_vars)
             setattr(self, attr, val)
コード例 #2
0
def GetModuleIncludes(modules):
    use_resources = GetConfigVar('RESOURCEBUNDLE')
    source_vars = {}
    for config_name, var_name in InstallConfig.CONFIG_MAPPING.items():
        source_vars[var_name] = GetConfigVar(config_name.upper())
    target_vars = Install.GetBundleScheme()
    includes = []
    for module in DATA_FILES:
        if module in modules:
            for filespec in DATA_FILES[module]:
                source = subst_vars(convert_path(filespec), source_vars)
                if use_resources:
                    resource = ImportUtil.OsPathToResource(source)
                    source = ImportUtil.GetResourceFilename(module, resource)
                target = subst_vars(convert_path(filespec), target_vars)[1:]
                includes.append((source, target))
    return includes
コード例 #3
0
ファイル: install.py プロジェクト: Orav/kbengine
 def _expand_attrs(self, attrs):
     for attr in attrs:
         val = getattr(self, attr)
         if val is not None:
             if os.name == "posix" or os.name == "nt":
                 val = os.path.expanduser(val)
             val = subst_vars(val, self.config_vars)
             setattr(self, attr, val)
コード例 #4
0
ファイル: ModuleFinder.py プロジェクト: flaub/Peach
def GetModuleIncludes(modules):
    use_resources = GetConfigVar("RESOURCEBUNDLE")
    source_vars = {}
    for config_name, var_name in InstallConfig.CONFIG_MAPPING.items():
        source_vars[var_name] = GetConfigVar(config_name.upper())
    target_vars = Install.GetBundleScheme()
    includes = []
    for module in DATA_FILES:
        if module in modules:
            for filespec in DATA_FILES[module]:
                source = subst_vars(convert_path(filespec), source_vars)
                if use_resources:
                    resource = ImportUtil.OsPathToResource(source)
                    source = ImportUtil.GetResourceFilename(module, resource)
                target = subst_vars(convert_path(filespec), target_vars)[1:]
                includes.append((source, target))
    return includes
コード例 #5
0
ファイル: setup.py プロジェクト: tdaff/portage
		def process_data_files(df):
			for d, files in df:
				# substitute man sources
				if d.startswith('$mandir/'):
					files = [os.path.join(self.build_base, v) for v in files]

				# substitute variables in path
				d = subst_vars(d, self.paths)
				yield (d, files)
コード例 #6
0
        def process_data_files(df):
            for d, files in df:
                # substitute man sources
                if d.startswith('$mandir/'):
                    files = [os.path.join(self.build_base, v) for v in files]

                # substitute variables in path
                d = subst_vars(d, self.paths)
                yield (d, files)
コード例 #7
0
ファイル: dist_installer.py プロジェクト: carlitux/gaebuild
 def _expand(self, *attrs):
     config_vars = self.get_finalized_command('install').config_vars
     from distutils.util import subst_vars
     for attr in attrs:
         val = getattr(self, attr)
         if val is not None:
             val = subst_vars(val, config_vars)
             if os.name == 'posix':
                 val = os.path.expanduser(val)
             setattr(self, attr, val)
コード例 #8
0
 def _expand(self, *attrs):
     config_vars = self.get_finalized_command('install').config_vars
     from distutils.util import subst_vars
     for attr in attrs:
         val = getattr(self, attr)
         if val is not None:
             val = subst_vars(val, config_vars)
             if os.name == 'posix':
                 val = os.path.expanduser(val)
             setattr(self, attr, val)
コード例 #9
0
ファイル: scheme.py プロジェクト: czervenka/rvirtualenv
def get_scheme(platform, what, vars={}):
    # TODO: maybe use syslinux.get_path in next versions
    replace = {
        'base': sys.prefix,
        'py_version_short': sys.version[:3],
        'dist_name': 'UNKNOWN',
    }
    replace.update(vars)
    line = INSTALL_SCHEMES[platform][what]
    line = path.join(*line.split('/'))
    return subst_vars(line, replace)
コード例 #10
0
ファイル: scheme.py プロジェクト: wodole/rvirtualenv
def get_scheme(platform, what, vars={}):
    # TODO: maybe use syslinux.get_path in next versions
    replace = {
        'base': sys.prefix,
        'py_version_short': sys.version[:3],
        'dist_name': 'UNKNOWN',
    }
    replace.update(vars)
    line = INSTALL_SCHEMES[platform][what]
    line = path.join(*line.split('/'))
    return subst_vars(line, replace)
コード例 #11
0
ファイル: setup.py プロジェクト: tdaff/portage
	def finalize_options(self):
		install.finalize_options(self)

		# substitute variables
		new_paths = {
			'package': self.distribution.get_name(),
			'version': self.distribution.get_version(),
		}
		for key, default in self.paths:
			new_paths[key] = subst_vars(getattr(self, key), new_paths)
			setattr(self, key, new_paths[key])
		self.subst_paths = new_paths
コード例 #12
0
    def finalize_options(self):
        install.finalize_options(self)

        # substitute variables
        new_paths = {
            'package': self.distribution.get_name(),
            'version': self.distribution.get_version(),
        }
        for key, _default in self.paths:
            new_paths[key] = subst_vars(getattr(self, key), new_paths)
            setattr(self, key, new_paths[key])
        self.subst_paths = new_paths
コード例 #13
0
 def _expand_attrs(self, attrs):
     for attr in attrs:
         val = getattr(self, attr)
         if val is not None:
             if os.name == 'posix' or os.name == 'nt':
                 val = os.path.expanduser(val)
             val = subst_vars(val, self.config_vars)
             # install_headers can end with a '/' if $dist_name is ''
             # see issue 3140, and the comment in ./utils.py that CPython
             # apparently never uses $dist_name
             if len(val) > 0 and val[-1] == '/':
                 val = val[:-1]
             setattr(self, attr, val)
コード例 #14
0
ファイル: Install.py プロジェクト: yuetianle/binary_blobs
def GetBundleScheme():
    scheme = INSTALL_SCHEMES['zip'].copy()
    scheme['base'] = scheme['platbase'] = os.sep
    for key in SCHEME_KEYS:
        value = scheme[key]
        if value:
            value = util.subst_vars(value, scheme)
            value = util.convert_path(value)
            pathname = os.sep.join([ path for path in value.split(os.sep)
                                     if path not in ('', '.') ])
            if value.startswith(os.sep):
                pathname = os.sep + pathname
            scheme[key] = pathname
    scheme['lib'] = scheme['purelib']
    return scheme
コード例 #15
0
ファイル: install.py プロジェクト: vmssoftware/python_3_8_2
 def _expand_attrs(self, attrs):
     for attr in attrs:
         val = getattr(self, attr)
         if val is not None:
             if os.name == 'posix' or os.name == 'nt':
                 val = os.path.expanduser(val)
             if sys.platform == 'OpenVMS':
                 for key in [
                         'sys_prefix', 'prefix', 'sys_exec_prefix',
                         'exec_prefix'
                 ]:
                     value = self.config_vars.get(key)
                     if value and val.startswith(value):
                         val = '$' + key + val[len(value):]
                         break
             val = subst_vars(val, self.config_vars)
             setattr(self, attr, val)
コード例 #16
0
 def finalize_config_vars(self):
     # Expand configuration variables, tilde, etc.
     main_distribution = self.distribution.main_distribution
     if main_distribution is None:
         main_distribution = self.distribution
     self.config_vars = {
         'name': main_distribution.get_name(),
         'version': main_distribution.get_version(),
         'fullname': main_distribution.get_fullname(),
         'python_version': sys.version[:3],
     }
     for key in CONFIG_KEYS:
         value = getattr(self, key)
         # Distutils prior to Python 2.3 cannot handle empty strings
         # in the util.* functions.
         if isinstance(value, str) and value:
             if os.name == 'posix':
                 value = os.path.expanduser(value)
             value = util.convert_path(value)
             value = util.subst_vars(value, self.config_vars)
         self.config_vars[key] = value
     return self.config_vars
コード例 #17
0
ファイル: Config.py プロジェクト: H1d3r/binary_blobs
 def finalize_config_vars(self):
     # Expand configuration variables, tilde, etc.
     main_distribution = self.distribution.main_distribution
     if main_distribution is None:
         main_distribution = self.distribution
     self.config_vars = {
         'name' : main_distribution.get_name(),
         'version' : main_distribution.get_version(),
         'fullname' : main_distribution.get_fullname(),
         'python_version' : sys.version[:3],
         }
     for key in CONFIG_KEYS:
         value = getattr(self, key)
         # Distutils prior to Python 2.3 cannot handle empty strings
         # in the util.* functions.
         if isinstance(value, str) and value:
             if os.name == 'posix':
                 value = os.path.expanduser(value)
             value = util.convert_path(value)
             value = util.subst_vars(value, self.config_vars)
         self.config_vars[key] = value
     return self.config_vars
コード例 #18
0
    def copy_transformed_tree(self, install_specs, dst_root=None, src_root=None, substitutions={}):
        """
        Copy parts of a source tree to a destination tree with a
        different tree structure and/or names.

        The basic idea: given a set of source files, copy them to a
        destination directory, let's call this operation an
        install_spec. A sequence of install_spec's allows one to build
        up the destrination tree in any structure desired.

        Each install_spec consists of 3 components
        (manifest_template, dst_xforms, dst_dir):

        The manifest_template is a sequence where each item is identical
        to a line in the MANIFEST.in template described in distutils. This
        gives you ability to easily specify a set of source files in a
        compact abstract manner (with recursion, exclusion, etc.) The
        manifest_template yields a sequence of source paths.

        dst_xforms is a sequence of regular expression substitutions
        applied to the each source path to yield a rewritten destination
        path. Each transform is expressed as a two-valued sequence
        (pattern, replacement)

        dst_dir is a destination directory where the destinations paths
        are written to. dst_dir is always relative to the dst_root.

        All input may be parametrized via variable substitutions
        supplied by a substitution dict. Any use of $name will cause
        name to be looked up first in the substitution dict and then
        if its not found there in the enviorment. If found it will be
        replaced with it's value.

        The pseudo code algorithm for processing an install_spec is:

        substitute all variables in manifest template
        src_list = evaluate manifest template
        for each src_path in src_list:
            dst_path = src_path
            for each xform in dst_xform:
                apply xform to dst_path
            copy src_root+src_path to dst_root+dest_dir+dest_path

        This process is repeated for each install spec. The src_root and
        dst_root are also subject to variable substitution.


        Examples:

        Copy all text files in build/doc to doc:

            copy_transformed_tree([[["include build/doc *.txt"], None, 'doc']])

        Copy all html files found under build to doc/html and change the extension from
        .html to .htm

            copy_transformed_tree([[["include build *.html"], [('\.html$','.htm')], 'doc']])

    """

        if src_root is not None: src_root = subst_vars(src_root, substitutions)
        if dst_root is not None: dst_root = subst_vars(dst_root, substitutions)

        filelist = FileList()
        if src_root is None:
            filelist.findall()
        else:
            filelist.findall(src_root)

        for manifest_template, dst_xforms, dst_dir in install_specs:
            if dst_dir is not None: dst_dir = subst_vars(dst_dir, substitutions)

            filelist.files = [] # reinitialize to empty

            for line in manifest_template:
                filelist.process_template_line(subst_vars(line, substitutions))

            for src_path in filelist.files:
                dst_path = src_path
                if dst_xforms:
                    for dst_xform in dst_xforms:
                        dst_path = re.sub(dst_xform[0], dst_xform[1], dst_path)
                if dst_dir is not None:
                    dst_path = change_root(dst_dir, dst_path)
                if dst_root is None:
                    full_dst_path = dst_path
                else:
                    full_dst_path = change_root(dst_root, dst_path)
                full_dst_dir = os.path.dirname(full_dst_path)
                self.mkpath(full_dst_dir)
                self.copy_file(src_path, full_dst_path)
コード例 #19
0
ファイル: apps.py プロジェクト: anthonyrisinger/zippy
def create_wheel(cache_path):
    ctx = _new_context()
    pydist = ctx['pydist']
    sections = ctx['sections']
    prefix = ctx['sections']['prefix']
    egginfo = ctx['paths']['egginfo']
    distinfo = ctx['paths']['distinfo']
    buildbase = ctx['paths']['buildbase']
    ns = dict(globals(), **{
        '__name__': '__main__',
        '__file__': 'setup.py',
        '__package__': None,
        })

    # fake bdist_wheel for packages that try to be too fancy
    class _wheel(type(sys)):
        def bdist_wheel(*args, **kwargs):
            pass
    sys.modules['wheel'] = _wheel('wheel')
    sys.modules['wheel.bdist_wheel'] = _wheel('wheel.bdist_wheel')

    sys.argv[:] = (
        'setup.py'
        '\0egg_info'
        '\0--no-svn-revision'
        '\0--no-date'
        '\0--tag-build='
        '\0build'
        '\0--build-base={paths[buildbase]}'
        '\0--executable=python'
        '\0install'
        '\0--single-version-externally-managed'
        '\0--record={sections[prefix]}/installed-files.txt'
        '\0--install-purelib={sections[purelib]}'
        '\0--install-platlib={sections[platlib]}'
        '\0--install-headers={sections[headers]}'
        '\0--install-scripts={sections[scripts]}'
        '\0--install-data={sections[data]}'
        ).format(**ctx).split('\0')

    #TODO: drop this!
    # install setuptools directly
    if pydist.name == 'setuptools':
        sys.argv[sys.argv.index('install')+3:] = []

    for impl in (
        'setup.cpyext.py',
        'setup.py',
        ):
        if os.path.exists(impl):
            execfile(impl, ns)
            break

    # skip and bail on setuptools else it can't find it's own stuff after
    # installation and because we aren't bulding a setuptools wheel (for now)
    #TODO: setuptools-4.0.1-py2.py3-none-any.whl?
    #TODO: impl/replace pkg_resources?
    if pydist.name == 'setuptools':
        shutil.rmtree(distinfo)
        return

    #FIXME: recompute the version from dist.egg-info; glob for now
    if not os.path.isdir(egginfo):
        import glob
        egginfo_glob = os.path.join(ctx['sections']['purelib'], '*')
        # fixup the name
        for egginfo in glob.glob(egginfo_glob):
            if egginfo.endswith('.egg-info'):
                ctx['paths']['egginfo'] = egginfo
                break

    # ensure exports are correct in case they differ from index-metadata
    # this happens when custom builds add new wrap_console scripts, etc
    entry_points = os.path.join(egginfo, 'entry_points.txt')
    kill = set()
    try:
        with open(entry_points) as fp:
            from ConfigParser import MissingSectionHeaderError
            read_exports = get_module('distlib.util').read_exports

            def conv(s):
                return s.split('=', 1)[-1].strip()

            ep_trans = {
                'console_scripts': 'wrap_console',
                'gui_scripts': 'wrap_gui',
                'prebuilt': 'prebuilt',
                }
            extensions = pydist.dictionary.setdefault('extensions', dict())
            extensions.setdefault('python.exports', dict())
            extensions.setdefault('python.commands', dict())
            ep_map = extensions['python.commands']
            try:
                ep_new = read_exports(fp, conv=conv)
            except MissingSectionHeaderError:
                #FIXME: UPSTREAM distlib: could be indented!
                # entry_points setup keyword argument could be a str
                # gunicorn does this
                from textwrap import dedent
                fp.seek(0)
                ep_dedent = dedent(fp.read().strip('\n\r'))
                fp.seek(0)
                fp.truncate()
                fp.write(ep_dedent)
                fp.seek(0)
                ep_new = read_exports(fp, conv=conv)

            exports = dict()
            for k in ep_new:
                if k not in ep_trans:
                    exports[k] = ep_new[k]
                    continue

                k2 = ep_trans[k]
                ep_map[k2] = ep_new[k]
                if k2 != 'prebuilt':
                    kill.update(ep_new[k].keys())

            # update python.exports
            if exports:
                extensions['python.exports'].update(exports)

            # check for accidental overlap with prebuilt (bad metadata)
            prebuilt = ep_map.get('prebuilt')
            if prebuilt:
                ep_map['prebuilt'] = [p for p in prebuilt if p not in kill]
                if not ep_map['prebuilt']:
                    del ep_map['prebuilt']

            #TODO: impl zippy.pkg_resources
            # write out entry_points.txt for legacy plugin discovery
            if extensions['python.exports']:
                exports = extensions['python.exports']
                ep_out = os.path.join(distinfo, 'entry_points.txt')
                with open(ep_out, mode='w') as fp2:
                    for ep_sect, ep_dict in exports.iteritems():
                        fp2.write('[{0}]\n'.format(ep_sect))
                        for ep_info in ep_dict.iteritems():
                            fp2.write('{} = {}\n'.format(*ep_info))

            if not extensions['python.exports']:
                del extensions['python.exports']
            if not extensions['python.commands']:
                del extensions['python.commands']
    except IOError:
        pass

    # drop all the scripts we know setuptools created
    for s in kill:
        s = os.path.join(sections['scripts'], s)
        os.unlink(s)

    # drop egg-info
    shutil.rmtree(egginfo)
    if os.path.exists(pydist.name + '.egg-info'):
        shutil.rmtree(pydist.name + '.egg-info')

    # [over]write metadata 2.x
    pydist.write(path='pydist.json')
    pydist.write(os.path.join(distinfo, 'METADATA'), legacy=True)
    shutil.copy2('pydist.json', os.path.join(distinfo, 'pydist.json'))

    whl = wheel.Wheel()
    whl.dirname = 'dist'
    whl.metadata = pydist
    whl.version = pydist.version
    whl.name = pydist.name

    #FIXME: del one of purelib/platlib
    whl_file = whl.build(sections)
    shutil.copy2(whl_file, cache_path)

    #TODO: minor: move binary (or `sys.executable = None`?) to avoid this...
    #import sysconfig
    #sysconfig._INSTALL_SCHEMES['posix_prefix'].update({
    #    'prefix': '{base}',
    #    'include': '{base}/include/python{py_version_short}',
    #    'platinclude': '{platbase}/include/python{py_version_short}',
    #    })
    from distutils.command.install import INSTALL_SCHEMES
    from distutils.util import subst_vars
    info = {
        'base': sys.prefix,
        'platbase': sys.exec_prefix,
        'py_version_short': '%s.%s' % sys.version_info[0:2],
        'dist_name': pydist.name,
        }
    scheme = dict(INSTALL_SCHEMES['unix_prefix'], prefix='$base')
    sections = dict()
    for k,v in scheme.iteritems():
        sections[k] = subst_vars(v, info)

    maker = scripts.ScriptMaker(None, None)
    # supercede setuptools version
    maker.clobber = True
    maker.executable = 'python'
    #TODO: go back to multi-version?
    # no point in versioning bin right now...
    maker.variants = set(('',))
    whl.install(sections, maker)

    #FIXME
    #if pydist.name != __package__:
    #    return

    shutil.rmtree(buildbase, ignore_errors=True)
コード例 #20
0
 def expand_filename(self, filename):
     new_filename = subst_vars(filename, self.config_dirs)
     # Make paths with replacements absolute
     if filename.startswith('$'):
         new_filename = change_root('/', new_filename)
     return new_filename
コード例 #21
0
 def expand_filename(self, filename):
     """Expand parametrized filename."""
     return subst_vars(filename, self.config_dirs)
コード例 #22
0
ファイル: freeze.py プロジェクト: mythZhu/sync-dist
def _expand_prefix(prefix, configs):
    """ Expand variables in the prefix.
    """
    return subst_vars(prefix, configs)
コード例 #23
0
    def copy_transformed_tree(self, install_specs, dst_root=None, src_root=None, substitutions={}):
        """
        Copy parts of a source tree to a destination tree with a
        different tree structure and/or names.

        The basic idea: given a set of source files, copy them to a
        destination directory, let's call this operation an
        install_spec. A sequence of install_spec's allows one to build
        up the destrination tree in any structure desired.

        Each install_spec consists of 3 components
        (manifest_template, dst_xforms, dst_dir):

        The manifest_template is a sequence where each item is identical
        to a line in the MANIFEST.in template described in distutils. This
        gives you ability to easily specify a set of source files in a
        compact abstract manner (with recursion, exclusion, etc.) The
        manifest_template yields a sequence of source paths.

        dst_xforms is a sequence of regular expression substitutions
        applied to the each source path to yield a rewritten destination
        path. Each transform is expressed as a two-valued sequence
        (pattern, replacement)

        dst_dir is a destination directory where the destinations paths
        are written to. dst_dir is always relative to the dst_root.

        All input may be parametrized via variable substitutions
        supplied by a substitution dict. Any use of $name will cause
        name to be looked up first in the substitution dict and then
        if its not found there in the enviorment. If found it will be
        replaced with it's value.

        The pseudo code algorithm for processing an install_spec is:

        substitute all variables in manifest template
        src_list = evaluate manifest template
        for each src_path in src_list:
            dst_path = src_path
            for each xform in dst_xform:
                apply xform to dst_path
            copy src_root+src_path to dst_root+dest_dir+dest_path

        This process is repeated for each install spec. The src_root and
        dst_root are also subject to variable substitution.


        Examples:

        Copy all text files in build/doc to doc:

            copy_transformed_tree([[["include build/doc *.txt"], None, 'doc']])

        Copy all html files found under build to doc/html and change the extension from
        .html to .htm

            copy_transformed_tree([[["include build *.html"], [('\.html$','.htm')], 'doc']])

    """

        if src_root is not None: src_root = subst_vars(src_root, substitutions)
        if dst_root is not None: dst_root = subst_vars(dst_root, substitutions)

        filelist = FileList()
        if src_root is None:
            filelist.findall()
        else:
            filelist.findall(src_root)

        for manifest_template, dst_xforms, dst_dir in install_specs:
            if dst_dir is not None: dst_dir = subst_vars(dst_dir, substitutions)

            filelist.files = [] # reinitialize to empty

            for line in manifest_template:
                filelist.process_template_line(subst_vars(line, substitutions))

            for src_path in filelist.files:
                dst_path = src_path
                if dst_xforms:
                    for dst_xform in dst_xforms:
                        dst_path = re.sub(dst_xform[0], dst_xform[1], dst_path)
                if dst_dir is not None:
                    dst_path = change_root(dst_dir, dst_path)
                if dst_root is None:
                    full_dst_path = dst_path
                else:
                    full_dst_path = change_root(dst_root, dst_path)
                full_dst_dir = os.path.dirname(full_dst_path)
                self.mkpath(full_dst_dir)
                self.copy_file(src_path, full_dst_path)
コード例 #24
0
"""distutils.command.install