Esempio n. 1
0
 def update_editable(self, obtain=True):
     # type: (bool) -> None
     if not self.link:
         logger.debug(
             "Cannot update repository at %s; repository location is "
             "unknown",
             self.source_dir,
         )
         return
     assert self.editable
     assert self.source_dir
     if self.link.scheme == 'file':
         # Static paths don't get updated
         return
     assert '+' in self.link.url, "bad url: %r" % self.link.url
     if not self.update:
         return
     vc_type, url = self.link.url.split('+', 1)
     backend = vcs.get_backend(vc_type)
     if backend:
         vcs_backend = backend(self.link.url)
         if obtain:
             vcs_backend.obtain(self.source_dir)
         else:
             vcs_backend.export(self.source_dir)
     else:
         assert 0, (
             'Unexpected version control type (in %s): %s'
             % (self.link, vc_type))
Esempio n. 2
0
def parse_editable(editable_req):
    """Parses an editable requirement into:
        - a requirement name
        - an URL
        - extras
        - editable options
    Accepted requirements:
        svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir
        .[some_extra]
    """

    url = editable_req

    # If a file path is specified with extras, strip off the extras.
    url_no_extras, extras = _strip_extras(url)

    if os.path.isdir(url_no_extras):
        if not os.path.exists(os.path.join(url_no_extras, 'setup.py')):
            raise InstallationError(
                "Directory %r is not installable. File 'setup.py' not found." %
                url_no_extras)
        # Treating it as code that has already been checked out
        url_no_extras = path_to_url(url_no_extras)

    if url_no_extras.lower().startswith('file:'):
        package_name = Link(url_no_extras).egg_fragment
        if extras:
            return (
                package_name,
                url_no_extras,
                Requirement("placeholder" + extras.lower()).extras,
            )
        else:
            return package_name, url_no_extras, None

    for version_control in vcs:
        if url.lower().startswith('%s:' % version_control):
            url = '%s+%s' % (version_control, url)
            break

    if '+' not in url:
        raise InstallationError(
            '%s should either be a path to a local project or a VCS url '
            'beginning with svn+, git+, hg+, or bzr+' % editable_req)

    vc_type = url.split('+', 1)[0].lower()

    if not vcs.get_backend(vc_type):
        error_message = 'For --editable=%s only ' % editable_req + \
            ', '.join([backend.name + '+URL' for backend in vcs.backends]) + \
            ' is currently supported'
        raise InstallationError(error_message)

    package_name = Link(url).egg_fragment
    if not package_name:
        raise InstallationError(
            "Could not detect requirement name for '%s', please specify one "
            "with #egg=your_package_name" % editable_req)
    return package_name, url, None
Esempio n. 3
0
 def from_dist(cls, dist, dependency_links):
     location = os.path.normcase(os.path.abspath(dist.location))
     comments = []
     from pipenv.patched.notpip._internal.vcs import vcs, get_src_requirement
     if dist_is_editable(dist) and vcs.get_backend_name(location):
         editable = True
         try:
             req = get_src_requirement(dist, location)
         except InstallationError as exc:
             logger.warning(
                 "Error when trying to get requirement for VCS system %s, "
                 "falling back to uneditable format", exc
             )
             req = None
         if req is None:
             logger.warning(
                 'Could not determine repository location of %s', location
             )
             comments.append(
                 '## !! Could not determine repository location'
             )
             req = dist.as_requirement()
             editable = False
     else:
         editable = False
         req = dist.as_requirement()
         specs = req.specs
         assert len(specs) == 1 and specs[0][0] in ["==", "==="], \
             'Expected 1 spec with == or ===; specs = %r; dist = %r' % \
             (specs, dist)
         version = specs[0][1]
         ver_match = cls._rev_re.search(version)
         date_match = cls._date_re.search(version)
         if ver_match or date_match:
             svn_backend = vcs.get_backend('svn')
             if svn_backend:
                 svn_location = svn_backend().get_location(
                     dist,
                     dependency_links,
                 )
             if not svn_location:
                 logger.warning(
                     'Warning: cannot find svn location for %s', req,
                 )
                 comments.append(
                     '## FIXME: could not find svn URL in dependency_links '
                     'for this package:'
                 )
             else:
                 deprecated(
                     "SVN editable detection based on dependency links "
                     "will be dropped in the future.",
                     replacement=None,
                     gone_in="18.2",
                     issue=4187,
                 )
                 comments.append(
                     '# Installing as editable to satisfy requirement %s:' %
                     req
                 )
                 if ver_match:
                     rev = ver_match.group(1)
                 else:
                     rev = '{%s}' % date_match.group(1)
                 editable = True
                 req = '%s@%s#egg=%s' % (
                     svn_location,
                     rev,
                     cls.egg_name(dist)
                 )
     return cls(dist.project_name, req, editable, comments)
Esempio n. 4
0
def parse_editable(editable_req):
    # type: (str) -> Tuple[Optional[str], str, Optional[Set[str]]]
    """Parses an editable requirement into:
        - a requirement name
        - an URL
        - extras
        - editable options
    Accepted requirements:
        svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir
        .[some_extra]
    """

    url = editable_req

    # If a file path is specified with extras, strip off the extras.
    url_no_extras, extras = _strip_extras(url)

    if os.path.isdir(url_no_extras):
        if not os.path.exists(os.path.join(url_no_extras, 'setup.py')):
            msg = ('File "setup.py" not found. Directory cannot be installed '
                   'in editable mode: {}'.format(
                       os.path.abspath(url_no_extras)))
            pyproject_path = make_pyproject_path(url_no_extras)
            if os.path.isfile(pyproject_path):
                msg += ('\n(A "pyproject.toml" file was found, but editable '
                        'mode currently requires a setup.py based build.)')
            raise InstallationError(msg)

        # Treating it as code that has already been checked out
        url_no_extras = path_to_url(url_no_extras)

    if url_no_extras.lower().startswith('file:'):
        package_name = Link(url_no_extras).egg_fragment
        if extras:
            return (
                package_name,
                url_no_extras,
                Requirement("placeholder" + extras.lower()).extras,
            )
        else:
            return package_name, url_no_extras, None

    for version_control in vcs:
        if url.lower().startswith('%s:' % version_control):
            url = '%s+%s' % (version_control, url)
            break

    if '+' not in url:
        raise InstallationError(
            '{} is not a valid editable requirement. '
            'It should either be a path to a local project or a VCS URL '
            '(beginning with svn+, git+, hg+, or bzr+).'.format(editable_req))

    vc_type = url.split('+', 1)[0].lower()

    if not vcs.get_backend(vc_type):
        error_message = 'For --editable=%s only ' % editable_req + \
            ', '.join([backend.name + '+URL' for backend in vcs.backends]) + \
            ' is currently supported'
        raise InstallationError(error_message)

    package_name = Link(url).egg_fragment
    if not package_name:
        raise InstallationError(
            "Could not detect requirement name for '%s', please specify one "
            "with #egg=your_package_name" % editable_req)
    return package_name, url, None
Esempio n. 5
0
 def from_dist(cls, dist, dependency_links):
     location = os.path.normcase(os.path.abspath(dist.location))
     comments = []
     from pipenv.patched.notpip._internal.vcs import vcs, get_src_requirement
     if dist_is_editable(dist) and vcs.get_backend_name(location):
         editable = True
         try:
             req = get_src_requirement(dist, location)
         except InstallationError as exc:
             logger.warning(
                 "Error when trying to get requirement for VCS system %s, "
                 "falling back to uneditable format", exc
             )
             req = None
         if req is None:
             logger.warning(
                 'Could not determine repository location of %s', location
             )
             comments.append(
                 '## !! Could not determine repository location'
             )
             req = dist.as_requirement()
             editable = False
     else:
         editable = False
         req = dist.as_requirement()
         specs = req.specs
         assert len(specs) == 1 and specs[0][0] in ["==", "==="], \
             'Expected 1 spec with == or ===; specs = %r; dist = %r' % \
             (specs, dist)
         version = specs[0][1]
         ver_match = cls._rev_re.search(version)
         date_match = cls._date_re.search(version)
         if ver_match or date_match:
             svn_backend = vcs.get_backend('svn')
             if svn_backend:
                 svn_location = svn_backend().get_location(
                     dist,
                     dependency_links,
                 )
             if not svn_location:
                 logger.warning(
                     'Warning: cannot find svn location for %s', req,
                 )
                 comments.append(
                     '## FIXME: could not find svn URL in dependency_links '
                     'for this package:'
                 )
             else:
                 warnings.warn(
                     "SVN editable detection based on dependency links "
                     "will be dropped in the future.",
                     RemovedInPip11Warning,
                 )
                 comments.append(
                     '# Installing as editable to satisfy requirement %s:' %
                     req
                 )
                 if ver_match:
                     rev = ver_match.group(1)
                 else:
                     rev = '{%s}' % date_match.group(1)
                 editable = True
                 req = '%s@%s#egg=%s' % (
                     svn_location,
                     rev,
                     cls.egg_name(dist)
                 )
     return cls(dist.project_name, req, editable, comments)