Commit 49846247 by Sébastien Eustace

Fix handling of Python versions compatibility

parent 69f2f6db
......@@ -6,6 +6,7 @@
- Fixed installation of Poetry git dependencies with a build system.
- Fixed possible errors when resolving dependencies for specific packages.
- Fixed handling of Python versions compatibility.
## [0.12.4] - 2018-10-21
......
......@@ -8,10 +8,27 @@ class EnvCommand(Command):
super(EnvCommand, self).__init__()
def initialize(self, i, o):
from poetry.semver import parse_constraint
from poetry.utils.env import Env
super(EnvCommand, self).initialize(i, o)
# Checking compatibility of the current environment with
# the python dependency specified in pyproject.toml
current_env = Env.get()
supported_python = self.poetry.package.python_constraint
current_python = parse_constraint(
".".join(str(v) for v in current_env.version_info[:3])
)
if not supported_python.allows(current_python):
raise RuntimeError(
"The current Python version ({}) is not supported by the project ({})\n"
"Please activate a compatible Python version.".format(
current_python, self.poetry.package.python_versions
)
)
self._env = Env.create_venv(
o, self.poetry.package.name, cwd=self.poetry.file.parent
)
......
......@@ -37,6 +37,7 @@ The <info>init</info> command creates a basic <comment>pyproject.toml</> file in
def handle(self):
from poetry.layouts import layout
from poetry.utils._compat import Path
from poetry.utils.env import Env
from poetry.vcs.git import GitConfig
if (Path.cwd() / "pyproject.toml").exists():
......@@ -101,7 +102,16 @@ The <info>init</info> command creates a basic <comment>pyproject.toml</> file in
question.validator = self._validate_license
license = self.ask(question)
question = self.create_question("Compatible Python versions [*]: ", default="*")
current_env = Env.get()
default_python = "^{}".format(
".".join(str(v) for v in current_env.version_info[:2])
)
question = self.create_question(
"Compatible Python versions [<comment>{}</comment>]: ".format(
default_python
),
default=default_python,
)
python = self.ask(question)
self.line("")
......
......@@ -14,6 +14,7 @@ class NewCommand(Command):
def handle(self):
from poetry.layouts import layout
from poetry.utils._compat import Path
from poetry.utils.env import Env
from poetry.vcs.git import GitConfig
if self.option("src"):
......@@ -44,7 +45,17 @@ class NewCommand(Command):
if author_email:
author += " <{}>".format(author_email)
layout_ = layout_(name, "0.1.0", author=author, readme_format=readme_format)
current_env = Env.get()
default_python = "^{}".format(
".".join(str(v) for v in current_env.version_info[:2])
)
layout_ = layout_(
name,
"0.1.0",
author=author,
readme_format=readme_format,
python=default_python,
)
layout_.create(path)
self.line(
......
......@@ -516,3 +516,19 @@ class NullEnv(SystemEnv):
def _bin(self, bin):
return bin
class MockEnv(NullEnv):
def __init__(self, version_info=(3, 7, 0), python_implementation="cpython"):
super(MockEnv, self).__init__()
self._version_info = version_info
self._python_implementation = python_implementation
@property
def version_info(self): # type: () -> Tuple[int]
return self._version_info
@property
def python_implementation(self): # type: () -> str
return self._python_implementation
......@@ -148,7 +148,7 @@ description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "*"
python = "^3.7"
[tool.poetry.dev-dependencies]
"""
......
......@@ -17,6 +17,8 @@ from poetry.packages import Locker as BaseLocker
from poetry.repositories import Pool
from poetry.repositories import Repository
from poetry.utils._compat import Path
from poetry.utils.env import Env
from poetry.utils.env import MockEnv
from poetry.utils.toml_file import TomlFile
......@@ -48,6 +50,8 @@ def installed():
@pytest.fixture(autouse=True)
def setup(mocker, installer, installed):
Env._env = MockEnv()
# Set Installer's installer
p = mocker.patch("poetry.installation.installer.Installer._get_installer")
p.return_value = installer
......@@ -74,6 +78,7 @@ def setup(mocker, installer, installed):
os.environ.clear()
os.environ.update(environ)
Env._env = None
class Application(BaseApplication):
......
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