Unverified Commit d7b23405 authored by Sébastien Eustace's avatar Sébastien Eustace
Browse files

Fix error with pip 9.0.2 and change how wildcard constraints are handled

parent d27e5040
Loading
Loading
Loading
Loading
+11 −0
Changes for CHANGELOG.md: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Change Log

[Unreleased]

### Changed

- Changed how wilcard constraints are handled.

### Fixed

- Fixed errors with pip 9.0.2.


## [0.6.1] - 2018-02-18

### Fixed
+2 −3
Changes for poetry/locations.py: 2 added lines, 3 removed lines.
Original line number Diff line number Diff line
# -*- coding: utf-8 -*-

from pip.utils.appdirs import user_cache_dir, user_config_dir
from .utils.appdirs import user_cache_dir
from .utils.appdirs import user_config_dir


CACHE_DIR = user_cache_dir('pypoetry')
+120 −0
Changes for poetry/packages/__init__.py: 120 added lines, 0 removed lines.
Original line number Diff line number Diff line
import os
import re

from poetry.semver.version_parser import VersionParser
from poetry.version.markers import Marker
from poetry.version.requirements import Requirement

from .dependency import Dependency
from .locker import Locker
from .package import Package
from .utils.link import Link
from .utils.utils import convert_markers
from .utils.utils import group_markers
from .utils.utils import is_archive_file
from .utils.utils import is_installable_dir
from .utils.utils import is_url
from .utils.utils import path_to_url
from .utils.utils import strip_extras
from .vcs_dependency import VCSDependency


def dependency_from_pep_508(name):
    req = Requirement(name)

    if req.marker:
        markers = convert_markers(req.marker.markers)
    else:
        markers = {}

    name = req.name
    path = os.path.normpath(os.path.abspath(name))
    link = None

    if is_url(name):
        link = Link(name)
    else:
        p, extras = strip_extras(path)
        if (os.path.isdir(p) and
                (os.path.sep in name or name.startswith('.'))):

            if not is_installable_dir(p):
                raise ValueError(
                    "Directory %r is not installable. File 'setup.py' "
                    "not found." % name
                )
            link = Link(path_to_url(p))
        elif is_archive_file(p):
            link = Link(path_to_url(p))

    # it's a local file, dir, or url
    if link:
        # Handle relative file URLs
        if link.scheme == 'file' and re.search(r'\.\./', link.url):
            link = Link(
                path_to_url(os.path.normpath(os.path.abspath(link.path)))
            )
        # wheel file
        if link.is_wheel:
            m = re.match(
                '^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))',
                link.filename
            )
            if not m:
                raise ValueError(f'Invalid wheel name: {link.filename}')

            name = m.group('name')
            version = m.group('ver')
            dep = Dependency(name, version)
        else:
            name = link.egg_fragment

            if link.scheme == 'git':
                dep = VCSDependency(name, 'git', link.url_without_fragment)
            else:
                dep = Dependency(name, '*')
    else:
        if req.pretty_constraint:
            constraint = req.constraint
        else:
            constraint = '*'

        dep = Dependency(name, constraint)

    if 'extra' in markers:
        # If we have extras, the dependency is optional
        dep.deactivate()

        for or_ in markers['extra']:
            for _, extra in or_:
                dep.extras.append(extra)

    if 'python_version' in markers:
        ors = []
        for or_ in markers['python_version']:
            ands = []
            for op, version in or_:
                # Expand python version
                if op == '==':
                    version = '~' + version
                    op = ''
                elif op == '!=':
                    version += '.*'

                ands.append(f'{op}{version}')

            ors.append(' '.join(ands))

        dep.python_versions = ' || '.join(ors)

    if 'sys_platform' in markers:
        ors = []
        for or_ in markers['sys_platform']:
            ands = []
            for op, platform in or_:
                if op == '==':
                    op = ''

                ands.append(f'{op}{platform}')

            ors.append(' '.join(ands))

        dep.platform = ' || '.join(ors)

    return dep
+8 −0
Changes for poetry/packages/dependency.py: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ import poetry.packages
from poetry.semver.constraints import Constraint
from poetry.semver.constraints import EmptyConstraint
from poetry.semver.constraints import MultiConstraint
from poetry.semver.constraints.base_constraint import BaseConstraint
from poetry.semver.version_parser import VersionParser

from .constraints.platform_constraint import PlatformConstraint
@@ -21,7 +22,10 @@ class Dependency:
        self._parser = VersionParser()

        try:
            if not isinstance(constraint, BaseConstraint):
                self._constraint = self._parser.parse_constraints(constraint)
            else:
                self._constraint = constraint
        except ValueError:
            self._constraint = self._parser.parse_constraints('*')

@@ -130,6 +134,10 @@ class Dependency:

        return requirement

    @classmethod
    def from_pep_508(cls):
        return

    def _create_nested_marker(self, name, constraint):
        if isinstance(constraint, MultiConstraint):
            parts = []
+0 −0

Empty file added.

Loading