Commit 24da824b by Sébastien Eustace Committed by Sébastien Eustace

Fix handling of single versions when packaging

parent 434e5409
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
- Poetry now only uses [TOML Kit](https://github.com/sdispater/tomlkit) for TOML files manipulation. - Poetry now only uses [TOML Kit](https://github.com/sdispater/tomlkit) for TOML files manipulation.
### Fixed ### Fixed
- Fixed missing dependency information for some packages. - Fixed missing dependency information for some packages.
- Fixed handling of single versions when packaging.
## [0.11.2] - 2018-07-03 ## [0.11.2] - 2018-07-03
......
...@@ -23,7 +23,7 @@ class Version(VersionRange): ...@@ -23,7 +23,7 @@ class Version(VersionRange):
pre=None, # type: Union[str, None] pre=None, # type: Union[str, None]
build=None, # type: Union[str, None] build=None, # type: Union[str, None]
text=None, # type: Union[str, None] text=None, # type: Union[str, None]
precision=None, # type: Union[str, None] precision=None, # type: Union[int, None]
): # type: () -> None ): # type: () -> None
self._major = int(major) self._major = int(major)
self._precision = None self._precision = None
...@@ -106,6 +106,10 @@ class Version(VersionRange): ...@@ -106,6 +106,10 @@ class Version(VersionRange):
return self._text return self._text
@property @property
def precision(self): # type: () -> int
return self._precision
@property
def stable(self): def stable(self):
if not self.is_prerelease(): if not self.is_prerelease():
return self return self
......
from poetry.semver import parse_constraint from poetry.semver import parse_constraint
from poetry.semver import Version
from poetry.semver import VersionUnion from poetry.semver import VersionUnion
PYTHON_VERSION = [ PYTHON_VERSION = [
...@@ -20,6 +21,16 @@ def format_python_constraint(constraint): ...@@ -20,6 +21,16 @@ def format_python_constraint(constraint):
This helper will help in transforming This helper will help in transforming
disjunctive constraint into proper constraint. disjunctive constraint into proper constraint.
""" """
if isinstance(constraint, Version) and constraint.precision < 3:
# Transform 3.6 or 3
if constraint.precision == 2:
# 3.6
constraint = parse_constraint(
"~{}.{}".format(constraint.major, constraint.minor)
)
else:
constraint = parse_constraint("^{}.0".format(constraint.major))
if not isinstance(constraint, VersionUnion): if not isinstance(constraint, VersionUnion):
return str(constraint) return str(constraint)
......
[tool.poetry]
name = "simple-version"
version = "0.1"
description = "Some description."
authors = [
"Sébastien Eustace <sebastien@eustace.io>"
]
license = "MIT"
readme = "README.rst"
homepage = "https://poetry.eustace.io/"
[tool.poetry.dependencies]
python = "3.6"
...@@ -395,3 +395,14 @@ def test_package_with_include(mocker): ...@@ -395,3 +395,14 @@ def test_package_with_include(mocker):
assert "with-include-1.2.3/pyproject.toml" in names assert "with-include-1.2.3/pyproject.toml" in names
assert "with-include-1.2.3/setup.py" in names assert "with-include-1.2.3/setup.py" in names
assert "with-include-1.2.3/PKG-INFO" in names assert "with-include-1.2.3/PKG-INFO" in names
def test_proper_python_requires_if_single_version_specified():
poetry = Poetry.create(project("simple_version"))
builder = SdistBuilder(poetry, NullVenv(), NullIO())
pkg_info = builder.build_pkg_info()
p = Parser()
parsed = p.parsestr(to_str(pkg_info))
assert parsed["Requires-Python"] == ">=3.6,<3.7"
...@@ -8,3 +8,17 @@ def test_format_python_constraint(): ...@@ -8,3 +8,17 @@ def test_format_python_constraint():
result = format_python_constraint(constraint) result = format_python_constraint(constraint)
assert result == ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" assert result == ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*"
def test_format_python_constraint_single_version():
constraint = parse_constraint("3.6")
result = format_python_constraint(constraint)
assert result == ">=3.6,<3.7"
constraint = parse_constraint("3")
result = format_python_constraint(constraint)
assert result == ">=3.0,<4.0"
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