Пример #1
0
def ensure_setup_requires(setuptools_spec,
                          dependency_links=None,
                          setup_requires=None):
    if 'PYTHONPATH' in os.environ:
        py_path = os.environ['PYTHONPATH'].split(os.pathsep)
    else:
        py_path = []
    # First, ensure the correct version of setuptools is active.
    setuptools_req = next(
        pkg_resources.parse_requirements('setuptools' + setuptools_spec))
    setuptools_dist = pkg_resources.get_distribution('setuptools')
    if setuptools_dist not in setuptools_req:
        setuptools_dist = setuptools.Distribution().fetch_build_eggs(
            str(setuptools_req))[0]
        py_path.insert(0, setuptools_dist.location)
        os.environ['PYTHONPATH'] = os.pathsep.join(py_path)
        args = [sys.executable] + sys.argv
        os.execv(args[0], args)
    # Second, install other setup requirements.
    setup_attrs = {}
    if dependency_links is not None:
        setup_attrs['dependency_links'] = dependency_links
    if setup_requires is not None:
        setup_attrs['setup_requires'] = setup_requires
    setup_dist = setuptools.Distribution(setup_attrs)
    setup_dist.parse_config_files(ignore_option_errors=True)
    if not setup_dist.setup_requires:
        return
    eggs_dir = setup_dist.get_egg_cache_dir()
    for dist in setup_dist.fetch_build_eggs(setup_dist.setup_requires):
        if dist.location.startswith(os.path.abspath(eggs_dir) + os.sep):
            py_path.insert(0, dist.location)
    os.environ['PYTHONPATH'] = os.pathsep.join(py_path)
Пример #2
0
    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')
                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 = pkg_resources.Distribution.from_location(
            destination_eggdir,
            dist_info,
            metadata=pkg_resources.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(map(raw_req, dist.requires()))
        extras_require = {
            extra: [
                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 = setuptools.Distribution(attrs=dict(
            install_requires=install_requires,
            extras_require=extras_require,
        ), )
        # Temporarily disable info traces.
        log_threshold = log._global_log.threshold
        log.set_threshold(log.WARN)
        try:
            write_requirements(
                setup_dist.get_command_obj('egg_info'),
                None,
                os.path.join(egg_info, 'requires.txt'),
            )
        finally:
            log.set_threshold(log_threshold)
Пример #3
0
    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 = pkg_resources.Distribution.from_location(
            destination_eggdir,
            dist_info,
            metadata=pkg_resources.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 = setuptools.Distribution(
            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"),
        )
Пример #4
0
def get_libpython2():
    d = setuptools.Distribution()
    b = build_ext(d)
    b.finalize_options()
    fpaths = b.library_dirs
    for fpath in fpaths:
        fpath = os.path.join(fpath,
                             "python%s.lib" % sys.version[:3].replace('.', ''))
        if os.path.exists(fpath):
            return fpath
    return ""
Пример #5
0
def get_libpython2():
    d = setuptools.Distribution()
    b = build_ext(d)
    b.finalize_options()
    version = "".join([str(x) for x in sys.version_info[:2]])
    fpaths = b.library_dirs
    for fpath in fpaths:
        fpath = os.path.join(fpath, f"python{version}.lib")
        if os.path.exists(fpath):
            return fpath

    return ""
Пример #6
0
def distribution():
    return setuptools.Distribution({
        'author': 'John Doe',
        'author_email': '*****@*****.**',
        'description': 'long story short',
        'install_requires': ['test==1.2.3'],
        'keywords': ['foo', 'bar', 'baz'],
        'license': 'BSD',
        'long_description': 'long story long',
        'name': 'simple',
        'url': 'https://example.com',
        'version': '0.0.0',
    })
Пример #7
0
    def _build_egg(self):
        import setuptools

        attrs = {
            'name': EGG_NAME,
            'version': '1.0',
            'script_name':
            os.path.split(os.path.split(hdpmanager.__file__)[0])[0],
            'zip_safe': False,
        }

        if self._packages:
            attrs['packages'] = self._packages
        if self._modules:
            attrs['py_modules'] = self._modules
        if self._package_data:
            attrs['package_data'] = self._package_data

        dist = setuptools.Distribution(attrs)

        # Move dist folders to /tmp
        opt_dict = dist.get_option_dict('bdist_egg')
        opt_dict['bdist_dir'] = (EGG_NAME, self._hdpm._get_tmp_dir('bdist'))
        opt_dict['dist_dir'] = (EGG_NAME, self._hdpm._get_tmp_dir('dist'))

        # Move build folders to /tmp
        build_opt_dict = dist.get_option_dict('build_py')
        build_opt_dict['build_lib'] = (EGG_NAME,
                                       self._hdpm._get_tmp_dir('build'))
        install_opt_dict = dist.get_option_dict('install_lib')
        install_opt_dict['build_dir'] = (EGG_NAME,
                                         self._hdpm._get_tmp_dir('build'))

        # Move egg folders to /tmp
        egg_opt_dict = dist.get_option_dict('egg_info')
        egg_opt_dict['egg_base'] = (EGG_NAME, self._hdpm._get_tmp_dir('egg'))

        dist.run_command('bdist_egg')

        egg_python_version = '%s.%s' % (sys.version_info.major,
                                        sys.version_info.minor)
        egg_filename = '%s-%s-py%s.egg' % (EGG_NAME, EGG_VERSION,
                                           egg_python_version)

        return [(egg_filename,
                 os.path.join(opt_dict['dist_dir'][1], egg_filename))]
Пример #8
0
            archive_path.write_bytes(request.read())
    dest = archive_path.stem
    shutil.rmtree(dest, ignore_errors=True)
    shutil.unpack_archive(archive_path, dest)

# Get cairo.dll (normally loaded by pycairo), checking that it include
# FreeType support.
Path("cairo/win64").mkdir(parents=True)
cairo_dll, = enum_process_modules(b"cairo_ft_font_face_create_for_ft_face")
shutil.copyfile(cairo_dll, "cairo/win64/cairo.dll")
# Get hold of a CCompiler object, by creating a dummy Distribution with a list
# of extension modules that claims to be truthy (but is actually empty) and
# running its build_ext command.  Prior to the deprecation of distutils, this
# was just ``cc = distutils.ccompiler.new_compiler(); cc.initialize()``.
class L(list): __bool__ = lambda self: True
be = setuptools.Distribution({"ext_modules": L()}).get_command_obj("build_ext")
be.finalize_options()
be.run()
cc = be.compiler
cc.initialize()
# On setuptools versions that use "local" distutils,
# ``cc.spawn(["dumpbin", ...])`` and ``cc.spawn(["lib", ...])`` no longer
# manage to locate the right executables, even though they are correctly on the
# PATH; instead, use shutil.which to walk the PATH and get absolute executable
# paths.
with TemporaryDirectory() as tmpdir:
    dest = Path(dest, "path")
    cc.spawn([
        "python", "-c",
        f"from shutil import which; "
        f"print(which('dumpbin'), file=open({str(dest)!r}, 'w'), end='')",
Пример #9
0
        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 = setuptools.Distribution(
            attrs=dict(
                install_requires=install_requires,
                extras_require=extras_require,
            ),
        )
        # Temporarily disable info traces.
        log_threshold = log._global_log.threshold
        log.set_threshold(log.WARN)
        try:
            write_requirements(
                setup_dist.get_command_obj('egg_info'),
                None,
                os.path.join(egg_info, 'requires.txt'),
            )
        finally:
            log.set_threshold(log_threshold)

    @staticmethod
Пример #10
0
import os
import sys
import setuptools
from py2app.util import skipjunk

_bdist_mpkg = setuptools.Distribution().get_command_class('bdist_mpkg')


class bdist_mpkg(_bdist_mpkg):
    def initialize_options(self):
        _bdist_mpkg.initialize_options(self)
        self.scheme_descriptions['tools'] = u'(Optional) py2app tools'
        self.scheme_map[
            'tools'] = '/Developer/Applications/Python Tools/py2app'

        self.scheme_descriptions[
            'examples'] = u'(Optional) py2app example code'
        self.scheme_map['examples'] = '/Developer/Python/py2app/Examples'
        self.scheme_copy['examples'] = 'examples'

        self.scheme_descriptions['doc'] = u'(Optional) py2app documentation'
        self.scheme_map['doc'] = '/Developer/Python/py2app/Documentation'
        self.scheme_copy['doc'] = 'doc'

    def run_extra(self):
        self.py2app_tools()

    def copy_tree(self, *args, **kw):
        if kw.get('condition') is None:
            kw['condition'] = skipjunk
        return _bdist_mpkg.copy_tree(self, *args, **kw)
Пример #11
0
 def test_issue_39_regression(self):
     distribution = setuptools.Distribution()
     cmd = main.Flake8Command(distribution)
     cmd.options_dict = {}
     cmd.run()