Commit 5d229dba by finswimmer Committed by GitHub

Merge pull request #2561 from fcoclavero/init-python-version-option

Python version option (`--python`) for `init` script.
parents 6795b88c c468052d
...@@ -81,6 +81,7 @@ poetry init ...@@ -81,6 +81,7 @@ poetry init
* `--name`: Name of the package. * `--name`: Name of the package.
* `--description`: Description of the package. * `--description`: Description of the package.
* `--author`: Author of the package. * `--author`: Author of the package.
* `--python` Compatible Python versions.
* `--dependency`: Package to require with a version constraint. Should be in format `foo:1.0.0`. * `--dependency`: Package to require with a version constraint. Should be in format `foo:1.0.0`.
* `--dev-dependency`: Development requirements, see `--require`. * `--dev-dependency`: Development requirements, see `--require`.
......
...@@ -32,6 +32,7 @@ class InitCommand(Command): ...@@ -32,6 +32,7 @@ class InitCommand(Command):
option("name", None, "Name of the package.", flag=False), option("name", None, "Name of the package.", flag=False),
option("description", None, "Description of the package.", flag=False), option("description", None, "Description of the package.", flag=False),
option("author", None, "Author name of the package.", flag=False), option("author", None, "Author name of the package.", flag=False),
option("python", None, "Compatible Python versions.", flag=False),
option( option(
"dependency", "dependency",
None, None,
...@@ -126,6 +127,8 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the ...@@ -126,6 +127,8 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
question.set_validator(self._validate_license) question.set_validator(self._validate_license)
license = self.ask(question) license = self.ask(question)
python = self.option("python")
if not python:
current_env = SystemEnv(Path(sys.executable)) current_env = SystemEnv(Path(sys.executable))
default_python = "^{}".format( default_python = "^{}".format(
".".join(str(v) for v in current_env.version_info[:2]) ".".join(str(v) for v in current_env.version_info[:2])
......
...@@ -445,3 +445,41 @@ pytest = "^3.6.0" ...@@ -445,3 +445,41 @@ pytest = "^3.6.0"
""" """
assert expected in tester.io.fetch_output() assert expected in tester.io.fetch_output()
def test_python_option(app, mocker, poetry):
command = app.find("init")
command._pool = poetry.pool
mocker.patch("poetry.utils._compat.Path.open")
p = mocker.patch("poetry.utils._compat.Path.cwd")
p.return_value = Path(__file__)
tester = CommandTester(command)
inputs = [
"my-package", # Package name
"1.2.3", # Version
"This is a description", # Description
"n", # Author
"MIT", # License
"n", # Interactive packages
"n", # Interactive dev packages
"\n", # Generate
]
tester.execute("--python '~2.7 || ^3.6'", inputs="\n".join(inputs))
expected = """\
[tool.poetry]
name = "my-package"
version = "1.2.3"
description = "This is a description"
authors = ["Your Name <you@example.com>"]
license = "MIT"
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
[tool.poetry.dev-dependencies]
"""
assert expected in tester.io.fetch_output()
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