Commit d3491fe7 by Sébastien Eustace

Add missing modules

parent ea9726dc
......@@ -21,20 +21,6 @@ class Builder:
if fmt not in self._FORMATS:
raise ValueError(f'Invalid format: {fmt}')
self.check()
builder = self._FORMATS[fmt](self._poetry, self._io)
return builder.build()
def check(self) -> None:
package = self._poetry.package
# Checking for disjunctive python versions
if isinstance(package.python_constraint, MultiConstraint):
if package.python_constraint.is_disjunctive():
raise RuntimeError(
'Disjunctive python versions are not yet supported '
'when building packages. Rewrite your python requirements '
'in a conjunctive way.'
)
......@@ -11,7 +11,7 @@ from pprint import pformat
from typing import List
from poetry.packages import Dependency
from poetry.semver.constraints import MultiConstraint
from poetry.version.helpers import format_python_constraint
from ..utils.helpers import normalize_file_permissions
......@@ -149,13 +149,7 @@ class SdistBuilder(Builder):
extra.append("'entry_points': entry_points,")
if self._package.python_versions != '*':
constraint = self._package.python_constraint
if isinstance(constraint, MultiConstraint):
python_requires = ','.join(
[str(c).replace(' ', '') for c in constraint.constraints]
)
else:
python_requires = str(constraint).replace(' ', '')
python_requires = format_python_constraint(self._package.python_constraint)
extra.append("'python_requires': {!r},".format(python_requires))
......
......@@ -16,6 +16,7 @@ from poetry.__version__ import __version__
from poetry.semver.constraints import Constraint
from poetry.semver.constraints import MultiConstraint
from poetry.vcs import get_vcs
from poetry.version.helpers import format_python_constraint
from ..utils.helpers import normalize_file_permissions
from ..utils.tags import get_abbr_impl
......@@ -311,13 +312,7 @@ class WheelBuilder(Builder):
fp.write(f'Author-email: {author["email"]}\n')
if self._package.python_versions != '*':
constraint = self._package.python_constraint
if isinstance(constraint, MultiConstraint):
python_requires = ','.join(
[str(c).replace(' ', '') for c in constraint.constraints]
)
else:
python_requires = str(constraint).replace(' ', '')
python_requires = format_python_constraint(self._package.python_constraint)
fp.write(f'Requires-Python: {python_requires}\n')
......
......@@ -37,5 +37,5 @@ class MultiConstraint(BaseConstraint):
constraints.append(str(constraint))
return '{}'.format(
(' ' if self._conjunctive else ' || ').join(constraints)
(', ' if self._conjunctive else ' || ').join(constraints)
)
......@@ -176,24 +176,31 @@ class VersionParser:
# A partial version range is treated as an X-Range,
# so the special character is in fact optional.
m = re.match(
'^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.[xX*])+$',
'^(!=)?v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.[xX*])+$',
constraint
)
if m:
if m.group(3):
if m.group(4):
position = 2
elif m.group(2):
elif m.group(3):
position = 1
else:
position = 0
groups = m.groups()[1:]
low_version = self._manipulate_version_string(
m.groups(), position
groups, position
)
high_version = self._manipulate_version_string(
m.groups(), position, 1
groups, position, 1
)
if m.group(1):
if low_version == '0.0.0.0':
return Constraint('>=', high_version),
return self.parse_constraints(f'<{low_version} || >={high_version}'),
if low_version == '0.0.0.0':
return Constraint('<', high_version),
......
from poetry.semver.constraints import MultiConstraint
from poetry.semver.version_parser import VersionParser
PYTHON_VERSION = [
'2.7.*',
'3.0.*', '3.1.*', '3.2.*', '3.3.*', '3.4.*',
'3.5.*', '3.6.*', '3.7.*', '3.8.*',
]
def format_python_constraint(constraint):
"""
This helper will help in transforming
disjunctive constraint into proper constraint.
"""
if not isinstance(constraint, MultiConstraint):
return str(constraint)
has_disjunctive = False
for c in constraint.constraints:
if isinstance(c, MultiConstraint) and c.is_disjunctive():
has_disjunctive = True
break
parser = VersionParser()
formatted = []
accepted = []
if not constraint.is_disjunctive() and not has_disjunctive:
return str(constraint)
for version in PYTHON_VERSION:
matches = constraint.matches(parser.parse_constraints(version))
if not matches:
formatted.append('!=' + version)
else:
accepted.append(version)
# Checking lower bound
low = accepted[0]
formatted.insert(0, '>=' + '.'.join(low.split('.')[:2]))
return ', '.join(formatted)
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