Example #1
0
 def _include_misc(self, name, value):
     if name == 'entry_points':
         old = getattr(self, name)
         for (group, entries) in value.iteritems():
             self.entry_points.setdefault(group, list()).extend(entries)
     else:
         Distribution._include_misc(self, name, value)
Example #2
0
	def fetch_build_egg(self, req):
		""" Specialized version of Distribution.fetch_build_egg
		that respects respects allow_hosts and index_url. """
		from setuptools.command.easy_install import easy_install
		dist = Distribution({'script_args': ['easy_install']})
		dist.parse_config_files()
		opts = dist.get_option_dict('easy_install')
		keep = (
			'find_links', 'site_dirs', 'index_url', 'optimize',
			'site_dirs', 'allow_hosts'
		)
		for key in list(opts):
			if key not in keep:
				del opts[key]  # don't use any other settings
		if self.dependency_links:
			links = self.dependency_links[:]
			if 'find_links' in opts:
				links = opts['find_links'][1].split() + links
			opts['find_links'] = ('setup', links)
		if self.allow_hosts:
			opts['allow_hosts'] = ('test', self.allow_hosts)
		if self.index_url:
			opts['index_url'] = ('test', self.index_url)
		install_dir_func = getattr(self, 'get_egg_cache_dir', _os.getcwd)
		install_dir = install_dir_func()
		cmd = easy_install(
			dist, args=["x"], install_dir=install_dir,
			exclude_scripts=True,
			always_copy=False, build_directory=None, editable=False,
			upgrade=False, multi_version=True, no_report=True, user=False
		)
		cmd.ensure_finalized()
		return cmd.easy_install(req)
Example #3
0
 def _exclude_misc(self, name, value):
     if name == 'entry_points':
         old = getattr(self, name)
         for (group, entries) in value.iteritems():
             old_entries = set(self.entry_points.get(group, list()))
             self.entry_points[group] = list(old_entries - set(entries))
     else:
         Distribution._exclude_misc(self, name, value)
Example #4
0
 def get_install_lib(args):
     # This helper uses the distutils/setuptools machinery to determine
     # where a command will install files based on the arguments passed
     # to setup.py
     dist = Distribution({'script_args': args})
     dist.parse_command_line()
     install_cmd = dist.get_command_obj('install')
     install_cmd.ensure_finalized()
     return install_cmd.install_lib
Example #5
0
 def get_setuptools_script_dir():
     " Get the directory setuptools installs scripts to for current python "
     dist = Distribution({'cmdclass': {'install': OnlyGetScriptPath}})
     dist.dry_run = True  # not sure if necessary
     dist.parse_config_files()
     command = dist.get_command_obj('install')
     command.ensure_finalized()
     command.run()
     return dist.install_scripts
Example #6
0
File: wheel.py Project: jsirois/pex
    def _convert_metadata(zf, destination_eggdir, dist_info, egg_info):
        def get_metadata(name):
            with zf.open(posixpath.join(dist_info, name)) as fp:
                value = fp.read().decode('utf-8') if PY3 else fp.read()
                return email.parser.Parser().parsestr(value)

        wheel_metadata = get_metadata('WHEEL')
        # Check wheel format version is supported.
        wheel_version = parse_version(wheel_metadata.get('Wheel-Version'))
        wheel_v1 = (
            parse_version('1.0') <= wheel_version < parse_version('2.0dev0')
        )
        if not wheel_v1:
            raise ValueError(
                'unsupported wheel format version: %s' % wheel_version)
        # Extract to target directory.
        os.mkdir(destination_eggdir)
        zf.extractall(destination_eggdir)
        # Convert metadata.
        dist_info = os.path.join(destination_eggdir, dist_info)
        dist = Distribution.from_location(
            destination_eggdir, dist_info,
            metadata=PathMetadata(destination_eggdir, dist_info),
        )

        # Note: Evaluate and strip markers now,
        # as it's difficult to convert back from the syntax:
        # foobar; "linux" in sys_platform and extra == 'test'
        def raw_req(req):
            req.marker = None
            return str(req)
        install_requires = list(sorted(map(raw_req, dist.requires())))
        extras_require = {
            extra: sorted(
                req
                for req in map(raw_req, dist.requires((extra,)))
                if req not in install_requires
            )
            for extra in dist.extras
        }
        os.rename(dist_info, egg_info)
        os.rename(
            os.path.join(egg_info, 'METADATA'),
            os.path.join(egg_info, 'PKG-INFO'),
        )
        setup_dist = SetuptoolsDistribution(
            attrs=dict(
                install_requires=install_requires,
                extras_require=extras_require,
            ),
        )
        write_requirements(
            setup_dist.get_command_obj('egg_info'),
            None,
            os.path.join(egg_info, 'requires.txt'),
        )
Example #7
0
 def __init__(self, attrs=None):
     self.translations = []
     Distribution.__init__(self, attrs)
     self.cmdclass = {
         'install_mo' : install_mo,
         'build_mo' : build_mo,
         # 'build_conf' : build_conf,
         'build_ext': BuildExt,
         'build_scripts': build_scripts_app,
         }
     self.command_obj['build_scripts'] = None
Example #8
0
def get_setuptools_script_dir():
    # Run the above class just to get paths
    dist = Distribution({'cmdclass': {'install': GetPaths}})
    dist.dry_run = True
    dist.parse_config_files()
    command = dist.get_command_obj('install')
    command.ensure_finalized()
    command.run()

    src_dir = glob(os.path.join(dist.install_libbase, 'pomoxis-*', 'exes'))[0]
    for exe in (os.path.join(src_dir, x) for x in os.listdir(src_dir)):
        print("Copying", os.path.basename(exe), '->', dist.install_scripts)
        shutil.copy(exe, dist.install_scripts)
    return dist.install_libbase, dist.install_scripts
Example #9
0
File: setup.py Project: rsms/smisk
	def __init__(self, attrs=None):
		Distribution.__init__(self, attrs)
		self.cmdclass = {
			'build': build,
			'build_ext': build_ext,
			'sdist': sdist,
			'config': config,
			'docs': sphinx_build,
			'clean': clean,
		}
		try:
			shell_cmd('which dpkg-buildpackage')
			self.cmdclass['debian'] = debian
		except IOError:
			# Not a debian system or dpkg-buildpackage not installed
			pass
    def run_command(self, command):
        '''Builds the documentation if needed, then passes control to
        the superclass' run_command(...) method.
        '''

        if command == 'install_data' and docutils:
            print 'creating doc/index.html'
            docutils.core.publish_file(writer_name='html',
                    source=open('doc/index.rst'),
                    source_path='doc',
                    destination=open('doc/index.html', 'w'),
                    destination_path='doc',
                    settings_overrides={'stylesheet_path':
                        'doc/documentation.css'}
            )
        Distribution.run_command(self, command)
Example #11
0
    def __init__(self, attrs=None):
        if attrs is None:
            attrs = {}

        attrs = _setup_cmd_classes(attrs)

        self.package = PackageDescription.from_yaml("setup.yaml")

        attrs.update({
            "name": self.package.name,
            "version": str(self.package.version),
            "long_description": self.package.description,
            "description": self.package.summary,
            "packages": self.package.packages,
        })

        OldDistribution.__init__(self, attrs)
Example #12
0
 def get_command_class(self, command):
     # Better raising an error than having some weird behavior for a command
     # we don't support
     if self.script_args is not None \
        and command in self.script_args \
        and command not in _BENTO_MONKEYED_CLASSES:
         raise ValueError("Command %s is not supported by bento.distutils compat layer" % command)
     return Distribution.get_command_class(self, command)
Example #13
0
File: setup.py Project: zjc5415/pyq
    def finalize_options(self):
        self.cmdclass['config'] = config

        self.cmdclass['build'] = build
        self.cmdclass['build_exe'] = build_exe
        self.cmdclass['build_qk'] = build_qk
        self.cmdclass['build_ext'] = build_ext
        self.cmdclass['build_qext'] = build_qext

        self.cmdclass['install'] = install
        self.cmdclass['install_exe'] = install_exe
        self.cmdclass['install_qlib'] = install_qlib
        self.cmdclass['install_qext'] = install_qext

        self.cmdclass['test'] = PyTest

        default_qhome_root = os.getenv('SystemDrive') + '\\' if platform == 'Windows' else os.getenv('HOME')
        self.qhome = os.getenv('QHOME') or os.path.join(default_qhome_root, 'q')

        bits = BITS
        if platform == 'Linux':
            o = 'l'
        elif platform == 'SunOS':
            o = 'v' if uname()[-1] == 'i86pc' else 's'
        elif platform == 'Darwin':
            o = 'm'
            bits = 32
        elif platform == 'Windows':
            o = 'w'
            bits = 32  # FIXME: We test with 32-bit kdb+ on Windows, so forcing 32-bit version.
        else:
            sys.stderr.write("Unknown platform: %s\n" % str(platform))
            sys.exit(1)
        self.qarch = "%s%d" % (o, bits)
        self.install_data = os.path.join(self.qhome, self.qarch)
        self.kxver = self.get_kxver(self.qhome)
        self.qexecutable = os.path.join(self.qhome, self.qarch, 'q')
        _Distribution.finalize_options(self)
        for ext in self.ext_modules + self.qext_modules:
            ext.define_macros.append(('KXVER', self.kxver.split('.')[0]))
            ext.define_macros.append(('QVER', self.kxver.split('.')[0]))
            if sys.hexversion >= 0x3000000:
                ext.define_macros.append(('PY3K', "%s%s" % sys.version_info[:2]))
Example #14
0
 def get_option_dict(self, command_name):
     opts = Distribution.get_option_dict(self, command_name)
     if command_name == 'easy_install':
         if find_links is not None:
             opts['find_links'] = ('setup script', find_links)
         if index_url is not None:
             opts['index_url'] = ('setup script', index_url)
         if allow_hosts is not None:
             opts['allow_hosts'] = ('setup script', allow_hosts)
     return opts
Example #15
0
def test_dist_fetch_build_egg(tmpdir):
    """
    Check multiple calls to `Distribution.fetch_build_egg` work as expected.
    """
    index = tmpdir.mkdir('index')
    index_url = urljoin('file://', pathname2url(str(index)))

    def sdist_with_index(distname, version):
        dist_dir = index.mkdir(distname)
        dist_sdist = '%s-%s.tar.gz' % (distname, version)
        make_nspkg_sdist(str(dist_dir.join(dist_sdist)), distname, version)
        with dist_dir.join('index.html').open('w') as fp:
            fp.write(DALS(
                '''
                <!DOCTYPE html><html><body>
                <a href="{dist_sdist}" rel="internal">{dist_sdist}</a><br/>
                </body></html>
                '''
            ).format(dist_sdist=dist_sdist))
    sdist_with_index('barbazquux', '3.2.0')
    sdist_with_index('barbazquux-runner', '2.11.1')
    with tmpdir.join('setup.cfg').open('w') as fp:
        fp.write(DALS(
            '''
            [easy_install]
            index_url = {index_url}
            '''
        ).format(index_url=index_url))
    reqs = '''
    barbazquux-runner
    barbazquux
    '''.split()
    with tmpdir.as_cwd():
        dist = Distribution()
        dist.parse_config_files()
        resolved_dists = [
            dist.fetch_build_egg(r)
            for r in reqs
        ]
    assert [dist.key for dist in resolved_dists if dist] == reqs
Example #16
0
    def __init__(self, attrs=None):
        if attrs is None:
            attrs = {}

        if not "bento_info" in attrs:
            bento_info = "bento.info"
        else:
            bento_info = attrs["bento.info"]
        self.pkg = PackageDescription.from_file(bento_info)
        self.package_options = PackageOptions.from_file(bento_info)


        attrs = _setup_cmd_classes(attrs)

        d = pkg_to_distutils_meta(self.pkg)
        attrs.update(d)

        Distribution.__init__(self, attrs)

        self.packages = self.pkg.packages
        self.py_modules = self.pkg.py_modules
        if hasattr(self, "entry_points"):
            if self.entry_points is None:
                self.entry_points = {}
            console_scripts = [e.full_representation() for e in self.pkg.executables.values()]
            if "console_scripts" in self.entry_points:
                self.entry_points["console_scripts"].extend(console_scripts)
            else:
                self.entry_points["console_scripts"] = console_scripts

        source_root = os.getcwd()
        build_root = os.path.join(source_root, "build")
        root = create_root_with_source_tree(source_root, build_root)
        self.top_node = root._ctx.srcnode
        self.build_node = root._ctx.bldnode
        self.run_node = root._ctx.srcnode

        self.global_context = global_context_factory(self.package_options)
        modules = set_main(self.top_node, self.build_node, self.pkg)
Example #17
0
File: setup.py Project: e42s/pyq
    def finalize_options(self):
        self.cmdclass['config'] = config

        self.cmdclass['build'] = build
        self.cmdclass['build_exe'] = build_exe
        self.cmdclass['build_qk'] = build_qk
        self.cmdclass['build_ext'] = build_ext
        self.cmdclass['build_qext'] = build_qext

        self.cmdclass['install'] = install
        self.cmdclass['install_exe'] = install_exe
        self.cmdclass['install_qlib'] = install_qlib
        self.cmdclass['install_qext'] = install_qext

        self.cmdclass['test'] = PyTest

        self.qhome = os.getenv('QHOME') or os.path.join(os.getenv('HOME'), 'q')
        bits = 8 * get_config_var('SIZEOF_VOID_P')
        u = os.uname()
        if u[0] == 'Linux':
            o = 'l'
        elif u[0] == 'SunOS':
            o = 'v' if u[-1] == 'i86pc' else 's'
        elif u[0] == 'Darwin':
            o = 'm'
            bits = 32
        else:
            sys.stderr.write("Unknown platform: %s\n" % str(u))
            sys.exit(1)
        self.qarch = "%s%d" % (o, bits)
        self.install_data = os.path.join(self.qhome, self.qarch)
        self.kxver = self.get_kxver(self.qhome)
        self.qexecutable = os.path.join(self.qhome, self.qarch, 'q')
        _Distribution.finalize_options(self)
        for ext in self.ext_modules + self.qext_modules:
            ext.define_macros.append(('KXVER', self.kxver.split('.')[0]))
            ext.define_macros.append(('QVER', self.kxver.split('.')[0]))
            if sys.hexversion >= 0x3000000:
                ext.define_macros.append(('PY3K', "%s%s" % sys.version_info[:2]))
Example #18
0
def ensure_sphinx_astropy_installed():
    """
    Make sure that sphinx-astropy is available, installing it temporarily if not.

    This returns the available version of sphinx-astropy as well as any
    paths that should be added to sys.path for sphinx-astropy to be available.
    """
    # We've split out the Sphinx part of astropy-helpers into sphinx-astropy
    # but we want it to be auto-installed seamlessly for anyone using
    # build_docs. We check if it's already installed, and if not, we install
    # it to a local .eggs directory and add the eggs to the path (these
    # have to each be added to the path, we can't add them by simply adding
    # .eggs to the path)
    sys_path_inserts = []
    sphinx_astropy_version = None
    try:
        from sphinx_astropy import __version__ as sphinx_astropy_version  # noqa
    except ImportError:

        from setuptools import Distribution
        dist = Distribution()
        eggs = dist.fetch_build_eggs('sphinx-astropy')

        # Find out the version of sphinx-astropy if possible. For some old
        # setuptools version, eggs will be None even if sphinx-astropy was
        # successfully installed.
        if eggs is not None:
            for egg in eggs:
                if egg.project_name == 'sphinx-astropy':
                    sphinx_astropy_version = egg.parsed_version.public
                    break

        eggs_path = os.path.abspath('.eggs')
        for egg in glob.glob(os.path.join(eggs_path, '*.egg')):
            sys_path_inserts.append(egg)

    return sphinx_astropy_version, sys_path_inserts
Example #19
0
    def getprefix(self):
        '''Retrieve setup tool calculated prefix

        :returns: prefix
        :rtype: string
        '''
        dist = Distribution({'cmdclass': {'install': OnlyGetScriptPath}})
        dist.dry_run = True  # not sure if necessary, but to be safe
        dist.parse_config_files()
        try:
            dist.parse_command_line()
        except (distutils.errors.DistutilsArgError, AttributeError):
            pass
        command = dist.get_command_obj('install')
        command.ensure_finalized()
        command.run()
        prefix = dist.install_scripts.replace('/bin', '')
        return prefix
Example #20
0
 def find_config_files(self):
     configs = Distribution.find_config_files(self)
     configs.append("setup.py3.cfg" if running_python3 else "setup.py2.cfg")
     return configs
Example #21
0
 def __init__(self, attrs=None):
     self.vcpkg_root = None
     _distribution.__init__(self, attrs)
Example #22
0
 def run_commands(self):
       opts = self.command_options
       if "install" in opts:
             self.preprocess_files(opts["install"].get("prefix",
                                                       ("", None))[1])
       Distribution.run_commands(self)
Example #23
0
 def run_command(self, command):
     self._last_run_command = command
     Distribution.run_command(self, command)
Example #24
0
 def __init__(self, *args, **kwargs):
     self.configure_files = []
     self.configure_values = {}
     self.man_pages = []
     _Distribution.__init__(self, *args, **kwargs)
Example #25
0
 def install_as_egg(self, destination_eggdir):
     '''Install wheel as an egg directory.'''
     with zipfile.ZipFile(self.filename) as zf:
         dist_basename = '%s-%s' % (self.project_name, self.version)
         dist_info = '%s.dist-info' % dist_basename
         dist_data = '%s.data' % dist_basename
         def get_metadata(name):
             with zf.open('%s/%s' % (dist_info, name)) as fp:
                 value = fp.read().decode('utf-8') if PY3 else fp.read()
                 return email.parser.Parser().parsestr(value)
         wheel_metadata = get_metadata('WHEEL')
         dist_metadata = get_metadata('METADATA')
         # Check wheel format version is supported.
         wheel_version = parse_version(wheel_metadata.get('Wheel-Version'))
         if not parse_version('1.0') <= wheel_version < parse_version('2.0dev0'):
             raise ValueError('unsupported wheel format version: %s' % wheel_version)
         # Extract to target directory.
         os.mkdir(destination_eggdir)
         zf.extractall(destination_eggdir)
         # Convert metadata.
         dist_info = os.path.join(destination_eggdir, dist_info)
         dist = Distribution.from_location(
             destination_eggdir, dist_info,
             metadata=PathMetadata(destination_eggdir, dist_info)
         )
         # Note: we need to evaluate and strip markers now,
         # as we can't easily convert back from the syntax:
         # foobar; "linux" in sys_platform and extra == 'test'
         def raw_req(req):
             req.marker = None
             return str(req)
         install_requires = list(sorted(map(raw_req, dist.requires())))
         extras_require = {
             extra: list(sorted(
                 req
                 for req in map(raw_req, dist.requires((extra,)))
                 if req not in install_requires
             ))
             for extra in dist.extras
         }
         egg_info = os.path.join(destination_eggdir, 'EGG-INFO')
         os.rename(dist_info, egg_info)
         os.rename(os.path.join(egg_info, 'METADATA'),
                   os.path.join(egg_info, 'PKG-INFO'))
         setup_dist = SetuptoolsDistribution(attrs=dict(
             install_requires=install_requires,
             extras_require=extras_require,
         ))
         write_requirements(setup_dist.get_command_obj('egg_info'),
                            None, os.path.join(egg_info, 'requires.txt'))
         # Move data entries to their correct location.
         dist_data = os.path.join(destination_eggdir, dist_data)
         dist_data_scripts = os.path.join(dist_data, 'scripts')
         if os.path.exists(dist_data_scripts):
             egg_info_scripts = os.path.join(destination_eggdir,
                                             'EGG-INFO', 'scripts')
             os.mkdir(egg_info_scripts)
             for entry in os.listdir(dist_data_scripts):
                 # Remove bytecode, as it's not properly handled
                 # during easy_install scripts install phase.
                 if entry.endswith('.pyc'):
                     os.unlink(os.path.join(dist_data_scripts, entry))
                 else:
                     os.rename(os.path.join(dist_data_scripts, entry),
                               os.path.join(egg_info_scripts, entry))
             os.rmdir(dist_data_scripts)
         for subdir in filter(os.path.exists, (
             os.path.join(dist_data, d)
             for d in ('data', 'headers', 'purelib', 'platlib')
         )):
             unpack(subdir, destination_eggdir)
         if os.path.exists(dist_data):
             os.rmdir(dist_data)
         # Fix namespace packages.
         namespace_packages = os.path.join(egg_info, 'namespace_packages.txt')
         if os.path.exists(namespace_packages):
             with open(namespace_packages) as fp:
                 namespace_packages = fp.read().split()
             for mod in namespace_packages:
                 mod_dir = os.path.join(destination_eggdir, *mod.split('.'))
                 mod_init = os.path.join(mod_dir, '__init__.py')
                 if os.path.exists(mod_dir) and not os.path.exists(mod_init):
                     with open(mod_init, 'w') as fp:
                         fp.write(NAMESPACE_PACKAGE_INIT)
Example #26
0
 def run_commands(self):
     # By now the setup_requires deps have been fetched.
     if not self.ext_modules:
         self.ext_modules = list()
     self.ext_modules.extend(self.pyrobufize_builtins())
     Distribution.run_commands(self)
Example #27
0
def fetch_build_eggs(requires, dist):
    return Distribution.fetch_build_eggs(dist, requires)
Example #28
0
 def __init__(self, attrs=None):
     self.test_dirs = []
     self.test_build_dir = None
     self.doctest_exts = ['.py', '.rst']
     self.pyversion_patching = False
     _Distribution.__init__(self, attrs)
Example #29
0
 def __init__(self, *args, **kwargs):
     self.egl = False
     self.debug = False
     Distribution.__init__(self, *args, **kwargs)
Example #30
0
def main(argv=None, **kw):
    """ Run a test package's tests.
    """
    # TODO: allow cmdline override of org config?
    config.setup_org_config()

    from path import path

    USAGE = """\
usage: %(script)s <package name> [test options]
   or: %(script)s --help
""" % {'script': sys.argv[0] or 'runtests'}

    if argv is None:
        argv = sys.argv[1:]

    if not argv:
        print "Please specify a package name."
        print USAGE
        sys.exit(1)

    pkg_name, argv = argv[0], argv[1:]
    test_pkg_name = 'test.%s' % pkg_name

    # Find our
    real_dist = [i for i in working_set if i.project_name == pkg_name]
    if not real_dist:
        print "Package %s is not installed" % pkg_name
        sys.exit(1)
    real_dist = real_dist[0]

    test_dist = [i for i in working_set if i.project_name == test_pkg_name]
    if not test_dist:
        print "Test package %s is not installed" % test_pkg_name
        sys.exit(1)
    test_dist = test_dist[0]

    # Construct a distutils.Distribtion class from the pkg_resources.Distribution
    # of the real package so we can pass it into the test command class.
    # We have checked that the packages are already installed so we set the install
    # requirements to blank.

    args = {'name': real_dist.project_name,
            'install_requires': [],
            'tests_require': [],
            'namespace_packages': list(real_dist._get_metadata('namespace_packages')),
            'packages': [real_dist.project_name],
            }
    real_cmd_dist = Distribution(args)
    cmd = test(real_cmd_dist)
    cmd.args = argv

    # Read in the test options saved away during egg_info and set the command defaults,
    # this would normally be done by the setup() method via the Distribution class
    test_options = path(test_dist.location) / 'EGG-INFO' / 'test_options.txt'
    if test_options.isfile():
        real_cmd_dist.parse_config_files([test_options])
    for k, v in real_cmd_dist.get_option_dict('test').items():
        print "Found test option in %s: %s = %s" % (v[0], k, v[1])
        setattr(cmd, k, v[1])

    # Finalize and run the command, overriding the test root to be inside the test egg
    cmd.finalize_options()
    cmd.test_root = path(test_dist.location) / CONFIG.test_egg_namespace / \
                         real_dist.project_name.replace('.', '/')
    # Pylint is only for regular Jenkins jobs, this in itself should not trigger even if
    # running under Jenkins
    cmd.no_pylint = True
    cmd.run()