Пример #1
0
    def run_egg_info(self):
        assert self.source_dir
        if self.name:
            logger.debug(
                'Running setup.py (path:%s) egg_info for package %s',
                self.setup_py,
                self.name,
            )
        else:
            logger.debug(
                'Running setup.py (path:%s) egg_info for package from %s',
                self.setup_py,
                self.link,
            )

        with indent_log():
            script = SETUPTOOLS_SHIM % self.setup_py
            base_cmd = [os.environ['PIP_PYTHON_PATH'], '-c', script]
            if self.isolated:
                base_cmd += ["--no-user-cfg"]
            egg_info_cmd = base_cmd + ['egg_info']
            # We can't put the .egg-info files at the root, because then the
            # source code will be mistaken for an installed egg, causing
            # problems
            if self.editable:
                egg_base_option = []
            else:
                egg_info_dir = os.path.join(self.setup_py_dir, 'pip-egg-info')
                ensure_dir(egg_info_dir)
                egg_base_option = ['--egg-base', 'pip-egg-info']
            call_subprocess(egg_info_cmd + egg_base_option,
                            cwd=self.setup_py_dir,
                            show_stdout=False,
                            command_desc='python setup.py egg_info')

        if not self.req:
            if isinstance(parse_version(self.pkg_info()["Version"]), Version):
                op = "=="
            else:
                op = "==="
            self.req = Requirement("".join([
                self.pkg_info()["Name"],
                op,
                self.pkg_info()["Version"],
            ]))
            self._correct_build_location()
        else:
            metadata_name = canonicalize_name(self.pkg_info()["Name"])
            if canonicalize_name(self.req.name) != metadata_name:
                logger.warning(
                    'Running setup.py (path:%s) egg_info for package %s '
                    'produced metadata for project name %s. Fix your '
                    '#egg=%s fragments.', self.setup_py, self.name,
                    metadata_name, self.name)
                self.req = Requirement(metadata_name)
Пример #2
0
 def get_git_version(self):
     VERSION_PFX = 'git version '
     version = self.run_command(['version'], show_stdout=False)
     if version.startswith(VERSION_PFX):
         version = version[len(VERSION_PFX):]
     else:
         version = ''
     # get first 3 positions of the git version becasue
     # on windows it is x.y.z.windows.t, and this parses as
     # LegacyVersion which always smaller than a Version.
     version = '.'.join(version.split('.')[:3])
     return parse_version(version)
Пример #3
0
 def update(self, dest, rev_options):
     # First fetch changes from the default remote
     if self.get_git_version() >= parse_version('1.9.0'):
         # fetch tags in addition to everything else
         self.run_command(['fetch', '-q', '--tags'], cwd=dest)
     else:
         self.run_command(['fetch', '-q'], cwd=dest)
     # Then reset to wanted revision (maybe even origin/master)
     if rev_options:
         rev_options = self.check_rev_options(
             rev_options[0],
             dest,
             rev_options,
         )
     self.run_command(['reset', '--hard', '-q'] + rev_options, cwd=dest)
     #: update submodules
     self.update_submodules(dest)
Пример #4
0
 def __init__(self, project, version, location, requires_python=''):
     self.project = project
     self.version = parse_version(version)
     self.location = location
     self._key = (self.project, self.version, self.location)
     self.requires_python = requires_python
Пример #5
0
    def find_requirement(self, req, upgrade, ignore_compatibility=False):
        """Try to find a Link matching req

        Expects req, an InstallRequirement and upgrade, a boolean
        Returns a Link if found,
        Raises DistributionNotFound or BestVersionAlreadyInstalled otherwise
        """
        all_candidates = self.find_all_candidates(req.name)

        # Filter out anything which doesn't match our specifier
        if not ignore_compatibility:
            compatible_versions = set(
                req.specifier.filter(
                    # We turn the version object into a str here because otherwise
                    # when we're debundled but setuptools isn't, Python will see
                    # packaging.version.Version and
                    # pkg_resources._vendor.packaging.version.Version as different
                    # types. This way we'll use a str as a common data interchange
                    # format. If we stop using the pkg_resources provided specifier
                    # and start using our own, we can drop the cast to str().
                    [str(c.version) for c in all_candidates],
                    prereleases=(
                        self.allow_all_prereleases
                        if self.allow_all_prereleases else None
                    ),
                )
            )
        else:
            compatible_versions = [str(c.version) for c in all_candidates]

        applicable_candidates = [
            # Again, converting to str to deal with debundling.
            c for c in all_candidates if str(c.version) in compatible_versions
        ]

        if applicable_candidates:
            best_candidate = max(applicable_candidates,
                                 key=self._candidate_sort_key)
        else:
            best_candidate = None

        if req.satisfied_by is not None:
            installed_version = parse_version(req.satisfied_by.version)
        else:
            installed_version = None

        if installed_version is None and best_candidate is None:
            logger.critical(
                'Could not find a version that satisfies the requirement %s '
                '(from versions: %s)',
                req,
                ', '.join(
                    sorted(
                        set(str(c.version) for c in all_candidates),
                        key=parse_version,
                    )
                )
            )

            raise DistributionNotFound(
                'No matching distribution found for %s' % req
            )

        best_installed = False
        if installed_version and (
                best_candidate is None or
                best_candidate.version <= installed_version):
            best_installed = True

        if not upgrade and installed_version is not None:
            if best_installed:
                logger.debug(
                    'Existing installed version (%s) is most up-to-date and '
                    'satisfies requirement',
                    installed_version,
                )
            else:
                logger.debug(
                    'Existing installed version (%s) satisfies requirement '
                    '(most up-to-date version is %s)',
                    installed_version,
                    best_candidate.version,
                )
            return None

        if best_installed:
            # We have an existing version, and its the best version
            logger.debug(
                'Installed version (%s) is most up-to-date (past versions: '
                '%s)',
                installed_version,
                ', '.join(sorted(compatible_versions, key=parse_version)) or
                "none",
            )
            raise BestVersionAlreadyInstalled

        logger.debug(
            'Using version %s (newest of versions: %s)',
            best_candidate.version,
            ', '.join(sorted(compatible_versions, key=parse_version))
        )
        return best_candidate.location
Пример #6
0
 def __init__(self, project, version, location):
     self.project = project
     self.version = parse_version(version)
     self.location = location
     self._key = (self.project, self.version, self.location)