Commit 6f747bf7 by Sébastien Eustace

Fix dependency resolution with post releases

parent c615c5b2
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
- Fixed `add` command picking up prereleases by default. - Fixed `add` command picking up prereleases by default.
- Fixed dependendency resolution on Windows when unpacking distributions. - Fixed dependendency resolution on Windows when unpacking distributions.
- Fixed dependency resolution with post releases.
## [0.8.1] - 2018-04-13 ## [0.8.1] - 2018-04-13
......
...@@ -127,7 +127,7 @@ lists all packages available.""" ...@@ -127,7 +127,7 @@ lists all packages available."""
color = 'yellow' color = 'yellow'
line += ' <fg={}>{:{}}</>'.format( line += ' <fg={}>{:{}}</>'.format(
color, latest.version, latest_length color, latest.pretty_version, latest_length
) )
if self.option('outdated') and update_status == 'up-to-date': if self.option('outdated') and update_status == 'up-to-date':
continue continue
...@@ -249,7 +249,7 @@ lists all packages available.""" ...@@ -249,7 +249,7 @@ lists all packages available."""
selector = VersionSelector(self.poetry.pool) selector = VersionSelector(self.poetry.pool)
return selector.find_best_candidate( return selector.find_best_candidate(
name, '>={}'.format(package.version) name, '>={}'.format(package.pretty_version)
) )
def get_update_status(self, latest, package): def get_update_status(self, latest, package):
...@@ -258,7 +258,7 @@ lists all packages available.""" ...@@ -258,7 +258,7 @@ lists all packages available."""
if latest.full_pretty_version == package.full_pretty_version: if latest.full_pretty_version == package.full_pretty_version:
return 'up-to-date' return 'up-to-date'
constraint = '^' + package.version constraint = '^' + package.pretty_version
if latest.version and statisfies(latest.version, constraint): if latest.version and statisfies(latest.version, constraint):
# It needs an immediate semver-compliant upgrade # It needs an immediate semver-compliant upgrade
......
...@@ -86,18 +86,6 @@ class Constraint(BaseConstraint): ...@@ -86,18 +86,6 @@ class Constraint(BaseConstraint):
) )
) )
# If we can't normalize the version
# we delegate to parse_version()
try:
a = normalize_version(a)
except ValueError:
pass
try:
b = normalize_version(b)
except ValueError:
pass
return version_compare(a, b, operator) return version_compare(a, b, operator)
def match_specific(self, provider): # type: (Constraint) -> bool def match_specific(self, provider): # type: (Constraint) -> bool
......
...@@ -39,9 +39,7 @@ def normalize_version(version): ...@@ -39,9 +39,7 @@ def normalize_version(version):
# Some versions have the form M.m.p-\d+ # Some versions have the form M.m.p-\d+
# which means M.m.p-post\d+ # which means M.m.p-post\d+
m = re.match( m = re.match(
'(?i)^v?(\d{{1,5}})(\.\d+)?(\.\d+)?(\.\d+)?-(?:\d+){}$'.format( '(?i)^v?(\d{1,5})(\.\d+)?(\.\d+)?(\.\d+)?-(\d+)$',
_modifier_regex
),
version version
) )
if m: if m:
...@@ -51,6 +49,16 @@ def normalize_version(version): ...@@ -51,6 +49,16 @@ def normalize_version(version):
m.group(3) if m.group(3) else '.0', m.group(3) if m.group(3) else '.0',
m.group(4) if m.group(4) else '.0', m.group(4) if m.group(4) else '.0',
) )
if m.group(5):
version += '-post.' + m.group(5)
m = re.match(
'(?i)^v?(\d{{1,5}})(\.\d+)?(\.\d+)?(\.\d+)?{}$'.format(
_modifier_regex
),
version
)
index = 5 index = 5
else: else:
# Match date(time) based versioning # Match date(time) based versioning
...@@ -71,9 +79,14 @@ def normalize_version(version): ...@@ -71,9 +79,14 @@ def normalize_version(version):
if m.group(index) == 'post': if m.group(index) == 'post':
# Post releases should be considered # Post releases should be considered
# stable releases # stable releases
return version if '-post' in version:
return version
version = '{}-{}'.format(version, _expand_stability(m.group(index))) version = '{}-post'.format(version)
else:
version = '{}-{}'.format(
version, _expand_stability(m.group(index))
)
if m.group(index + 1): if m.group(index + 1):
version = '{}.{}'.format( version = '{}.{}'.format(
...@@ -135,6 +148,6 @@ def _expand_stability(stability): # type: (str) -> str ...@@ -135,6 +148,6 @@ def _expand_stability(stability): # type: (str) -> str
elif stability in ['p', 'pl']: elif stability in ['p', 'pl']:
return 'patch' return 'patch'
elif stability in ['post']: elif stability in ['post']:
return '' return 'post'
return stability return stability
...@@ -8,14 +8,14 @@ from .constraints.base_constraint import BaseConstraint ...@@ -8,14 +8,14 @@ from .constraints.base_constraint import BaseConstraint
from .constraints.empty_constraint import EmptyConstraint from .constraints.empty_constraint import EmptyConstraint
from .constraints.multi_constraint import MultiConstraint from .constraints.multi_constraint import MultiConstraint
from .constraints.wildcard_constraint import WilcardConstraint from .constraints.wildcard_constraint import WilcardConstraint
from .helpers import normalize_version, _expand_stability from .helpers import normalize_version, _expand_stability, parse_stability
class VersionParser: class VersionParser:
_modifier_regex = ( _modifier_regex = (
'[._-]?' '[._-]?'
'(?:(stable|beta|b|RC|alpha|a|patch|pl|p)((?:[.-]?\d+)*)?)?' '(?:(stable|beta|b|RC|alpha|a|patch|post|pl|p)((?:[.-]?\d+)*)?)?'
'([.-]?dev)?' '([.-]?dev)?'
) )
...@@ -96,11 +96,30 @@ class VersionParser: ...@@ -96,11 +96,30 @@ class VersionParser:
def _parse_constraint( def _parse_constraint(
self, constraint self, constraint
): # type: (str) -> Union[Tuple[BaseConstraint], Tuple[BaseConstraint, BaseConstraint]] ): # type: (str) -> Union[Tuple[BaseConstraint], Tuple[BaseConstraint, BaseConstraint]]
m = re.match('(?i)^v?[xX*](\.[xX*])*$', constraint) m = re.match('(?i)^v?[xX*](\.[xX*])*$', constraint)
if m: if m:
return EmptyConstraint(), return EmptyConstraint(),
# Some versions have the form M.m.p-\d+
# which means M.m.p-post\d+
m = re.match(
'(?i)^(~=?|\^|<> ?|!= ?|>=? ?|<=? ?|==? ?)v?(\d{{1,5}})(\.\d+)?(\.\d+)?(\.\d+)?-(\d+){}$'.format(
self._modifier_regex
),
constraint
)
if m:
constraint = '{}{}{}{}{}'.format(
m.group(1),
m.group(2),
m.group(3) if m.group(3) else '.0',
m.group(4) if m.group(4) else '.0',
m.group(5) if m.group(5) else '.0',
)
if m.group(6):
constraint += '-post.' + m.group(6)
version_regex = ( version_regex = (
'v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?{}(?:\+[^\s]+)?' 'v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?{}(?:\+[^\s]+)?'
).format(self._modifier_regex) ).format(self._modifier_regex)
...@@ -165,6 +184,14 @@ class VersionParser: ...@@ -165,6 +184,14 @@ class VersionParser:
else: else:
position = 2 position = 2
# Calculate the stability suffix
stability_suffix = ''
if m.group(5):
stability_suffix += '-{}{}'.format(
_expand_stability(m.group(5)),
'.' + m.group(6) if m.group(6) else ''
)
low_version = normalize_version(constraint[1:]) low_version = normalize_version(constraint[1:])
lower_bound = Constraint('>=', low_version) lower_bound = Constraint('>=', low_version)
...@@ -197,6 +224,13 @@ class VersionParser: ...@@ -197,6 +224,13 @@ class VersionParser:
if m: if m:
try: try:
version = normalize_version(m.group(2)) version = normalize_version(m.group(2))
stability = parse_stability(version)
stability_re = re.match(
'(?:[^-]*)(-{})$'.format(self._modifier_regex),
m.group(2).lower()
)
if stability == 'stable' and stability_re:
version = version.split('-')[0] + stability_re.group(1)
return Constraint(m.group(1) or '=', version), return Constraint(m.group(1) or '=', version),
except ValueError: except ValueError:
......
...@@ -46,6 +46,8 @@ def parse(version, # type: str ...@@ -46,6 +46,8 @@ def parse(version, # type: str
def version_compare(version1, version2, operator def version_compare(version1, version2, operator
): # type: (str, str, str) -> bool ): # type: (str, str, str) -> bool
from poetry.semver.helpers import normalize_version
if operator in _trans_op: if operator in _trans_op:
operator = _trans_op[operator] operator = _trans_op[operator]
elif operator in _trans_op.values(): elif operator in _trans_op.values():
...@@ -56,4 +58,14 @@ def version_compare(version1, version2, operator ...@@ -56,4 +58,14 @@ def version_compare(version1, version2, operator
version1 = parse(version1) version1 = parse(version1)
version2 = parse(version2) version2 = parse(version2)
try:
version1 = parse(normalize_version(str(version1)))
except ValueError:
pass
try:
version2 = parse(normalize_version(str(version2)))
except ValueError:
pass
return operator(version1, version2) return operator(version1, version2)
...@@ -28,7 +28,7 @@ from poetry.semver.helpers import normalize_version ...@@ -28,7 +28,7 @@ from poetry.semver.helpers import normalize_version
('20100102-203040-p1', '20100102.203040-patch.1'), ('20100102-203040-p1', '20100102.203040-patch.1'),
('1.0.0-beta.5+foo', '1.0.0.0-beta.5'), ('1.0.0-beta.5+foo', '1.0.0.0-beta.5'),
('0.6c', '0.6.0.0-rc'), ('0.6c', '0.6.0.0-rc'),
('3.0.17-20140602', '3.0.17.0'), ('3.0.17-20140602', '3.0.17.0-post.20140602'),
('3.0pre', '3.0.0.0-rc') ('3.0pre', '3.0.0.0-rc')
] ]
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment