We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Discrepancy regarding license between doc and poetry init
<!--
  Hi there! Thank you for discovering and submitting an issue.

  Before you submit this; let's make sure of a few things.
  Please make sure the following boxes are ticked if they are correct.
  If not, please try and fulfill these first.
-->

<!-- Checked checkbox should look like this: [x] -->
- [x] I am on the [latest](https://github.com/sdispater/poetry/releases/latest) Poetry version.
- [x] I have searched the [issues](https://github.com/sdispater/poetry/issues) of this repo and believe that this is not a duplicate.
- [x] If an exception occurs when executing a command, I executed it again in debug mode (`-vvv` option).

<!--
  Once those are done, if you're able to fill in the following list with your information,
  it'd be very helpful to whoever handles the issue.
-->

- **OS version and name**: Manjaro Linux
- **Poetry version**: 0.11.1
- **Link of a [Gist](https://gist.github.com/) with the contents of your pyproject.toml file**: 

## Issue
<!-- Now feel free to write your issue, but please be descriptive! Thanks again 🙌 ❤️ -->
During the `license` prompt of `poetry init`, a valid license is required as input. Acording to the documentation, a license is highly recommended, but not actually required. This descrepancy should be removed by updating either the documentation or the code.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `poetry/console/commands/init.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3 
4 import re
5 
6 from typing import List
7 from typing import Tuple
8 
9 from .command import Command
10 from .venv_command import VenvCommand
11 
12 
13 class InitCommand(Command):
14     """
15     Creates a basic <comment>pyproject.toml</> file in the current directory.
16 
17     init
18         {--name= : Name of the package}
19         {--description= : Description of the package}
20         {--author= : Author name of the package}
21         {--dependency=* : Package to require with an optional version constraint,
22                           e.g. requests:^2.10.0 or requests=2.11.1}
23         {--dev-dependency=* : Package to require for development with an optional version constraint,
24                               e.g. requests:^2.10.0 or requests=2.11.1}
25         {--l|license= : License of the package}
26     """
27 
28     help = """\
29 The <info>init</info> command creates a basic <comment>pyproject.toml</> file in the current directory.
30 """
31 
32     def __init__(self):
33         super(InitCommand, self).__init__()
34 
35         self._pool = None
36 
37     def handle(self):
38         from poetry.layouts import layout
39         from poetry.utils._compat import Path
40         from poetry.vcs.git import GitConfig
41 
42         if (Path.cwd() / "pyproject.toml").exists():
43             self.error("A pyproject.toml file already exists.")
44             return 1
45 
46         vcs_config = GitConfig()
47 
48         self.line(
49             [
50                 "",
51                 "This command will guide you through creating your <info>poetry.toml</> config.",
52                 "",
53             ]
54         )
55 
56         name = self.option("name")
57         if not name:
58             name = Path.cwd().name.lower()
59 
60             question = self.create_question(
61                 "Package name [<comment>{}</comment>]: ".format(name), default=name
62             )
63             name = self.ask(question)
64 
65         version = "0.1.0"
66         question = self.create_question(
67             "Version [<comment>{}</comment>]: ".format(version), default=version
68         )
69         version = self.ask(question)
70 
71         description = self.option("description") or ""
72         question = self.create_question(
73             "Description [<comment>{}</comment>]: ".format(description),
74             default=description,
75         )
76         description = self.ask(question)
77 
78         author = self.option("author")
79         if not author and vcs_config and vcs_config.get("user.name"):
80             author = vcs_config["user.name"]
81             author_email = vcs_config.get("user.email")
82             if author_email:
83                 author += " <{}>".format(author_email)
84 
85         question = self.create_question(
86             "Author [<comment>{}</comment>, n to skip]: ".format(author), default=author
87         )
88         question.validator = lambda v: self._validate_author(v, author)
89         author = self.ask(question)
90 
91         if not author:
92             authors = []
93         else:
94             authors = [author]
95 
96         license = self.option("license") or ""
97 
98         question = self.create_question(
99             "License [<comment>{}</comment>]: ".format(license), default=license
100         )
101         question.validator = self._validate_license
102         license = self.ask(question)
103 
104         question = self.create_question("Compatible Python versions [*]: ", default="*")
105         python = self.ask(question)
106 
107         self.line("")
108 
109         requirements = {}
110 
111         question = "Would you like to define your dependencies" " (require) interactively?"
112         if self.confirm(question, True):
113             requirements = self._format_requirements(
114                 self._determine_requirements(self.option("dependency"))
115             )
116 
117         dev_requirements = {}
118 
119         question = "Would you like to define your dev dependencies" " (require-dev) interactively"
120         if self.confirm(question, True):
121             dev_requirements = self._format_requirements(
122                 self._determine_requirements(self.option("dev-dependency"))
123             )
124 
125         layout_ = layout("standard")(
126             name,
127             version,
128             description=description,
129             author=authors[0] if authors else None,
130             license=license,
131             python=python,
132             dependencies=requirements,
133             dev_dependencies=dev_requirements,
134         )
135 
136         content = layout_.generate_poetry_content()
137         if self.input.is_interactive():
138             self.line("<info>Generated file</info>")
139             self.line(["", content, ""])
140 
141         if not self.confirm("Do you confirm generation?", True):
142             self.line("<error>Command aborted</error>")
143 
144             return 1
145 
146         with (Path.cwd() / "pyproject.toml").open("w") as f:
147             f.write(content)
148 
149     def _determine_requirements(
150         self, requires, allow_prereleases=False  # type: List[str]  # type: bool
151     ):  # type: (...) -> List[str]
152         if not requires:
153             requires = []
154 
155             package = self.ask("Search for package:")
156             while package is not None:
157                 matches = self._get_pool().search(package)
158 
159                 if not matches:
160                     self.line("<error>Unable to find package</error>")
161                     package = False
162                 else:
163                     choices = []
164 
165                     for found_package in matches:
166                         choices.append(found_package.pretty_name)
167 
168                     self.line(
169                         "Found <info>{}</info> packages matching <info>{}</info>".format(
170                             len(matches), package
171                         )
172                     )
173 
174                     package = self.choice(
175                         "\nEnter package # to add, or the complete package name if it is not listed",
176                         choices,
177                         attempts=3,
178                     )
179 
180                 # no constraint yet, determine the best version automatically
181                 if package is not False and " " not in package:
182                     question = self.create_question(
183                         "Enter the version constraint to require "
184                         "(or leave blank to use the latest version):"
185                     )
186                     question.attempts = 3
187                     question.validator = lambda x: (x or "").strip() or False
188 
189                     constraint = self.ask(question)
190 
191                     if constraint is False:
192                         _, constraint = self._find_best_version_for_package(package)
193 
194                         self.line(
195                             "Using version <info>{}</info> for <info>{}</info>".format(
196                                 constraint, package
197                             )
198                         )
199 
200                     package += " {}".format(constraint)
201 
202                 if package is not False:
203                     requires.append(package)
204 
205                 package = self.ask("\nSearch for a package:")
206 
207             return requires
208 
209         requires = self._parse_name_version_pairs(requires)
210         result = []
211         for requirement in requires:
212             if "version" not in requirement:
213                 # determine the best version automatically
214                 name, version = self._find_best_version_for_package(
215                     requirement["name"], allow_prereleases=allow_prereleases
216                 )
217                 requirement["version"] = version
218                 requirement["name"] = name
219 
220                 self.line(
221                     "Using version <info>{}</> for <info>{}</>".format(version, name)
222                 )
223             else:
224                 # check that the specified version/constraint exists
225                 # before we proceed
226                 name, _ = self._find_best_version_for_package(
227                     requirement["name"],
228                     requirement["version"],
229                     allow_prereleases=allow_prereleases,
230                 )
231 
232                 requirement["name"] = name
233 
234             result.append("{} {}".format(requirement["name"], requirement["version"]))
235 
236         return result
237 
238     def _find_best_version_for_package(
239         self, name, required_version=None, allow_prereleases=False
240     ):  # type: (...) -> Tuple[str, str]
241         from poetry.version.version_selector import VersionSelector
242 
243         selector = VersionSelector(self._get_pool())
244         package = selector.find_best_candidate(
245             name, required_version, allow_prereleases=allow_prereleases
246         )
247 
248         if not package:
249             # TODO: find similar
250             raise ValueError(
251                 "Could not find a matching version of package {}".format(name)
252             )
253 
254         return (package.pretty_name, selector.find_recommended_require_version(package))
255 
256     def _parse_name_version_pairs(self, pairs):  # type: (list) -> list
257         result = []
258 
259         for i in range(len(pairs)):
260             pair = re.sub("^([^=: ]+)[=: ](.*)$", "\\1 \\2", pairs[i].strip())
261             pair = pair.strip()
262 
263             if " " in pair:
264                 name, version = pair.split(" ", 2)
265                 result.append({"name": name, "version": version})
266             else:
267                 result.append({"name": pair})
268 
269         return result
270 
271     def _format_requirements(self, requirements):  # type: (List[str]) -> dict
272         requires = {}
273         requirements = self._parse_name_version_pairs(requirements)
274         for requirement in requirements:
275             requires[requirement["name"]] = requirement["version"]
276 
277         return requires
278 
279     def _validate_author(self, author, default):
280         from poetry.packages.package import AUTHOR_REGEX
281 
282         author = author or default
283 
284         if author in ["n", "no"]:
285             return
286 
287         m = AUTHOR_REGEX.match(author)
288         if not m:
289             raise ValueError(
290                 "Invalid author string. Must be in the format: "
291                 "John Smith <john@example.com>"
292             )
293 
294         return author
295 
296     def _validate_license(self, license):
297         from poetry.spdx import license_by_id
298 
299         license_by_id(license)
300 
301         return license
302 
303     def _get_pool(self):
304         from poetry.repositories import Pool
305         from poetry.repositories.pypi_repository import PyPiRepository
306 
307         if isinstance(self, VenvCommand):
308             return self.poetry.pool
309 
310         if self._pool is None:
311             self._pool = Pool()
312             self._pool.add_repository(PyPiRepository())
313 
314         return self._pool
315
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/poetry/console/commands/init.py b/poetry/console/commands/init.py
--- a/poetry/console/commands/init.py
+++ b/poetry/console/commands/init.py
@@ -296,7 +296,8 @@
     def _validate_license(self, license):
         from poetry.spdx import license_by_id
 
-        license_by_id(license)
+        if license:
+            license_by_id(license)
 
         return license

{"golden_diff": "diff --git a/poetry/console/commands/init.py b/poetry/console/commands/init.py\n--- a/poetry/console/commands/init.py\n+++ b/poetry/console/commands/init.py\n@@ -296,7 +296,8 @@\n     def _validate_license(self, license):\n         from poetry.spdx import license_by_id\n \n-        license_by_id(license)\n+        if license:\n+            license_by_id(license)\n \n         return license\n", "issue": "Discrepancy regarding license between doc and poetry init\n<!--\r\n  Hi there! Thank you for discovering and submitting an issue.\r\n\r\n  Before you submit this; let's make sure of a few things.\r\n  Please make sure the following boxes are ticked if they are correct.\r\n  If not, please try and fulfill these first.\r\n-->\r\n\r\n<!-- Checked checkbox should look like this: [x] -->\r\n- [x] I am on the [latest](https://github.com/sdispater/poetry/releases/latest) Poetry version.\r\n- [x] I have searched the [issues](https://github.com/sdispater/poetry/issues) of this repo and believe that this is not a duplicate.\r\n- [x] If an exception occurs when executing a command, I executed it again in debug mode (`-vvv` option).\r\n\r\n<!--\r\n  Once those are done, if you're able to fill in the following list with your information,\r\n  it'd be very helpful to whoever handles the issue.\r\n-->\r\n\r\n- **OS version and name**: Manjaro Linux\r\n- **Poetry version**: 0.11.1\r\n- **Link of a [Gist](https://gist.github.com/) with the contents of your pyproject.toml file**: \r\n\r\n## Issue\r\n<!-- Now feel free to write your issue, but please be descriptive! Thanks again \ud83d\ude4c \u2764\ufe0f -->\r\nDuring the `license` prompt of `poetry init`, a valid license is required as input. Acording to the documentation, a license is highly recommended, but not actually required. This descrepancy should be removed by updating either the documentation or the code.\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\nfrom __future__ import unicode_literals\n\nimport re\n\nfrom typing import List\nfrom typing import Tuple\n\nfrom .command import Command\nfrom .venv_command import VenvCommand\n\n\nclass InitCommand(Command):\n    \"\"\"\n    Creates a basic <comment>pyproject.toml</> file in the current directory.\n\n    init\n        {--name= : Name of the package}\n        {--description= : Description of the package}\n        {--author= : Author name of the package}\n        {--dependency=* : Package to require with an optional version constraint,\n                          e.g. requests:^2.10.0 or requests=2.11.1}\n        {--dev-dependency=* : Package to require for development with an optional version constraint,\n                              e.g. requests:^2.10.0 or requests=2.11.1}\n        {--l|license= : License of the package}\n    \"\"\"\n\n    help = \"\"\"\\\nThe <info>init</info> command creates a basic <comment>pyproject.toml</> file in the current directory.\n\"\"\"\n\n    def __init__(self):\n        super(InitCommand, self).__init__()\n\n        self._pool = None\n\n    def handle(self):\n        from poetry.layouts import layout\n        from poetry.utils._compat import Path\n        from poetry.vcs.git import GitConfig\n\n        if (Path.cwd() / \"pyproject.toml\").exists():\n            self.error(\"A pyproject.toml file already exists.\")\n            return 1\n\n        vcs_config = GitConfig()\n\n        self.line(\n            [\n                \"\",\n                \"This command will guide you through creating your <info>poetry.toml</> config.\",\n                \"\",\n            ]\n        )\n\n        name = self.option(\"name\")\n        if not name:\n            name = Path.cwd().name.lower()\n\n            question = self.create_question(\n                \"Package name [<comment>{}</comment>]: \".format(name), default=name\n            )\n            name = self.ask(question)\n\n        version = \"0.1.0\"\n        question = self.create_question(\n            \"Version [<comment>{}</comment>]: \".format(version), default=version\n        )\n        version = self.ask(question)\n\n        description = self.option(\"description\") or \"\"\n        question = self.create_question(\n            \"Description [<comment>{}</comment>]: \".format(description),\n            default=description,\n        )\n        description = self.ask(question)\n\n        author = self.option(\"author\")\n        if not author and vcs_config and vcs_config.get(\"user.name\"):\n            author = vcs_config[\"user.name\"]\n            author_email = vcs_config.get(\"user.email\")\n            if author_email:\n                author += \" <{}>\".format(author_email)\n\n        question = self.create_question(\n            \"Author [<comment>{}</comment>, n to skip]: \".format(author), default=author\n        )\n        question.validator = lambda v: self._validate_author(v, author)\n        author = self.ask(question)\n\n        if not author:\n            authors = []\n        else:\n            authors = [author]\n\n        license = self.option(\"license\") or \"\"\n\n        question = self.create_question(\n            \"License [<comment>{}</comment>]: \".format(license), default=license\n        )\n        question.validator = self._validate_license\n        license = self.ask(question)\n\n        question = self.create_question(\"Compatible Python versions [*]: \", default=\"*\")\n        python = self.ask(question)\n\n        self.line(\"\")\n\n        requirements = {}\n\n        question = \"Would you like to define your dependencies\" \" (require) interactively?\"\n        if self.confirm(question, True):\n            requirements = self._format_requirements(\n                self._determine_requirements(self.option(\"dependency\"))\n            )\n\n        dev_requirements = {}\n\n        question = \"Would you like to define your dev dependencies\" \" (require-dev) interactively\"\n        if self.confirm(question, True):\n            dev_requirements = self._format_requirements(\n                self._determine_requirements(self.option(\"dev-dependency\"))\n            )\n\n        layout_ = layout(\"standard\")(\n            name,\n            version,\n            description=description,\n            author=authors[0] if authors else None,\n            license=license,\n            python=python,\n            dependencies=requirements,\n            dev_dependencies=dev_requirements,\n        )\n\n        content = layout_.generate_poetry_content()\n        if self.input.is_interactive():\n            self.line(\"<info>Generated file</info>\")\n            self.line([\"\", content, \"\"])\n\n        if not self.confirm(\"Do you confirm generation?\", True):\n            self.line(\"<error>Command aborted</error>\")\n\n            return 1\n\n        with (Path.cwd() / \"pyproject.toml\").open(\"w\") as f:\n            f.write(content)\n\n    def _determine_requirements(\n        self, requires, allow_prereleases=False  # type: List[str]  # type: bool\n    ):  # type: (...) -> List[str]\n        if not requires:\n            requires = []\n\n            package = self.ask(\"Search for package:\")\n            while package is not None:\n                matches = self._get_pool().search(package)\n\n                if not matches:\n                    self.line(\"<error>Unable to find package</error>\")\n                    package = False\n                else:\n                    choices = []\n\n                    for found_package in matches:\n                        choices.append(found_package.pretty_name)\n\n                    self.line(\n                        \"Found <info>{}</info> packages matching <info>{}</info>\".format(\n                            len(matches), package\n                        )\n                    )\n\n                    package = self.choice(\n                        \"\\nEnter package # to add, or the complete package name if it is not listed\",\n                        choices,\n                        attempts=3,\n                    )\n\n                # no constraint yet, determine the best version automatically\n                if package is not False and \" \" not in package:\n                    question = self.create_question(\n                        \"Enter the version constraint to require \"\n                        \"(or leave blank to use the latest version):\"\n                    )\n                    question.attempts = 3\n                    question.validator = lambda x: (x or \"\").strip() or False\n\n                    constraint = self.ask(question)\n\n                    if constraint is False:\n                        _, constraint = self._find_best_version_for_package(package)\n\n                        self.line(\n                            \"Using version <info>{}</info> for <info>{}</info>\".format(\n                                constraint, package\n                            )\n                        )\n\n                    package += \" {}\".format(constraint)\n\n                if package is not False:\n                    requires.append(package)\n\n                package = self.ask(\"\\nSearch for a package:\")\n\n            return requires\n\n        requires = self._parse_name_version_pairs(requires)\n        result = []\n        for requirement in requires:\n            if \"version\" not in requirement:\n                # determine the best version automatically\n                name, version = self._find_best_version_for_package(\n                    requirement[\"name\"], allow_prereleases=allow_prereleases\n                )\n                requirement[\"version\"] = version\n                requirement[\"name\"] = name\n\n                self.line(\n                    \"Using version <info>{}</> for <info>{}</>\".format(version, name)\n                )\n            else:\n                # check that the specified version/constraint exists\n                # before we proceed\n                name, _ = self._find_best_version_for_package(\n                    requirement[\"name\"],\n                    requirement[\"version\"],\n                    allow_prereleases=allow_prereleases,\n                )\n\n                requirement[\"name\"] = name\n\n            result.append(\"{} {}\".format(requirement[\"name\"], requirement[\"version\"]))\n\n        return result\n\n    def _find_best_version_for_package(\n        self, name, required_version=None, allow_prereleases=False\n    ):  # type: (...) -> Tuple[str, str]\n        from poetry.version.version_selector import VersionSelector\n\n        selector = VersionSelector(self._get_pool())\n        package = selector.find_best_candidate(\n            name, required_version, allow_prereleases=allow_prereleases\n        )\n\n        if not package:\n            # TODO: find similar\n            raise ValueError(\n                \"Could not find a matching version of package {}\".format(name)\n            )\n\n        return (package.pretty_name, selector.find_recommended_require_version(package))\n\n    def _parse_name_version_pairs(self, pairs):  # type: (list) -> list\n        result = []\n\n        for i in range(len(pairs)):\n            pair = re.sub(\"^([^=: ]+)[=: ](.*)$\", \"\\\\1 \\\\2\", pairs[i].strip())\n            pair = pair.strip()\n\n            if \" \" in pair:\n                name, version = pair.split(\" \", 2)\n                result.append({\"name\": name, \"version\": version})\n            else:\n                result.append({\"name\": pair})\n\n        return result\n\n    def _format_requirements(self, requirements):  # type: (List[str]) -> dict\n        requires = {}\n        requirements = self._parse_name_version_pairs(requirements)\n        for requirement in requirements:\n            requires[requirement[\"name\"]] = requirement[\"version\"]\n\n        return requires\n\n    def _validate_author(self, author, default):\n        from poetry.packages.package import AUTHOR_REGEX\n\n        author = author or default\n\n        if author in [\"n\", \"no\"]:\n            return\n\n        m = AUTHOR_REGEX.match(author)\n        if not m:\n            raise ValueError(\n                \"Invalid author string. Must be in the format: \"\n                \"John Smith <john@example.com>\"\n            )\n\n        return author\n\n    def _validate_license(self, license):\n        from poetry.spdx import license_by_id\n\n        license_by_id(license)\n\n        return license\n\n    def _get_pool(self):\n        from poetry.repositories import Pool\n        from poetry.repositories.pypi_repository import PyPiRepository\n\n        if isinstance(self, VenvCommand):\n            return self.poetry.pool\n\n        if self._pool is None:\n            self._pool = Pool()\n            self._pool.add_repository(PyPiRepository())\n\n        return self._pool\n", "path": "poetry/console/commands/init.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\nfrom __future__ import unicode_literals\n\nimport re\n\nfrom typing import List\nfrom typing import Tuple\n\nfrom .command import Command\nfrom .venv_command import VenvCommand\n\n\nclass InitCommand(Command):\n    \"\"\"\n    Creates a basic <comment>pyproject.toml</> file in the current directory.\n\n    init\n        {--name= : Name of the package}\n        {--description= : Description of the package}\n        {--author= : Author name of the package}\n        {--dependency=* : Package to require with an optional version constraint,\n                          e.g. requests:^2.10.0 or requests=2.11.1}\n        {--dev-dependency=* : Package to require for development with an optional version constraint,\n                              e.g. requests:^2.10.0 or requests=2.11.1}\n        {--l|license= : License of the package}\n    \"\"\"\n\n    help = \"\"\"\\\nThe <info>init</info> command creates a basic <comment>pyproject.toml</> file in the current directory.\n\"\"\"\n\n    def __init__(self):\n        super(InitCommand, self).__init__()\n\n        self._pool = None\n\n    def handle(self):\n        from poetry.layouts import layout\n        from poetry.utils._compat import Path\n        from poetry.vcs.git import GitConfig\n\n        if (Path.cwd() / \"pyproject.toml\").exists():\n            self.error(\"A pyproject.toml file already exists.\")\n            return 1\n\n        vcs_config = GitConfig()\n\n        self.line(\n            [\n                \"\",\n                \"This command will guide you through creating your <info>poetry.toml</> config.\",\n                \"\",\n            ]\n        )\n\n        name = self.option(\"name\")\n        if not name:\n            name = Path.cwd().name.lower()\n\n            question = self.create_question(\n                \"Package name [<comment>{}</comment>]: \".format(name), default=name\n            )\n            name = self.ask(question)\n\n        version = \"0.1.0\"\n        question = self.create_question(\n            \"Version [<comment>{}</comment>]: \".format(version), default=version\n        )\n        version = self.ask(question)\n\n        description = self.option(\"description\") or \"\"\n        question = self.create_question(\n            \"Description [<comment>{}</comment>]: \".format(description),\n            default=description,\n        )\n        description = self.ask(question)\n\n        author = self.option(\"author\")\n        if not author and vcs_config and vcs_config.get(\"user.name\"):\n            author = vcs_config[\"user.name\"]\n            author_email = vcs_config.get(\"user.email\")\n            if author_email:\n                author += \" <{}>\".format(author_email)\n\n        question = self.create_question(\n            \"Author [<comment>{}</comment>, n to skip]: \".format(author), default=author\n        )\n        question.validator = lambda v: self._validate_author(v, author)\n        author = self.ask(question)\n\n        if not author:\n            authors = []\n        else:\n            authors = [author]\n\n        license = self.option(\"license\") or \"\"\n\n        question = self.create_question(\n            \"License [<comment>{}</comment>]: \".format(license), default=license\n        )\n        question.validator = self._validate_license\n        license = self.ask(question)\n\n        question = self.create_question(\"Compatible Python versions [*]: \", default=\"*\")\n        python = self.ask(question)\n\n        self.line(\"\")\n\n        requirements = {}\n\n        question = \"Would you like to define your dependencies\" \" (require) interactively?\"\n        if self.confirm(question, True):\n            requirements = self._format_requirements(\n                self._determine_requirements(self.option(\"dependency\"))\n            )\n\n        dev_requirements = {}\n\n        question = \"Would you like to define your dev dependencies\" \" (require-dev) interactively\"\n        if self.confirm(question, True):\n            dev_requirements = self._format_requirements(\n                self._determine_requirements(self.option(\"dev-dependency\"))\n            )\n\n        layout_ = layout(\"standard\")(\n            name,\n            version,\n            description=description,\n            author=authors[0] if authors else None,\n            license=license,\n            python=python,\n            dependencies=requirements,\n            dev_dependencies=dev_requirements,\n        )\n\n        content = layout_.generate_poetry_content()\n        if self.input.is_interactive():\n            self.line(\"<info>Generated file</info>\")\n            self.line([\"\", content, \"\"])\n\n        if not self.confirm(\"Do you confirm generation?\", True):\n            self.line(\"<error>Command aborted</error>\")\n\n            return 1\n\n        with (Path.cwd() / \"pyproject.toml\").open(\"w\") as f:\n            f.write(content)\n\n    def _determine_requirements(\n        self, requires, allow_prereleases=False  # type: List[str]  # type: bool\n    ):  # type: (...) -> List[str]\n        if not requires:\n            requires = []\n\n            package = self.ask(\"Search for package:\")\n            while package is not None:\n                matches = self._get_pool().search(package)\n\n                if not matches:\n                    self.line(\"<error>Unable to find package</error>\")\n                    package = False\n                else:\n                    choices = []\n\n                    for found_package in matches:\n                        choices.append(found_package.pretty_name)\n\n                    self.line(\n                        \"Found <info>{}</info> packages matching <info>{}</info>\".format(\n                            len(matches), package\n                        )\n                    )\n\n                    package = self.choice(\n                        \"\\nEnter package # to add, or the complete package name if it is not listed\",\n                        choices,\n                        attempts=3,\n                    )\n\n                # no constraint yet, determine the best version automatically\n                if package is not False and \" \" not in package:\n                    question = self.create_question(\n                        \"Enter the version constraint to require \"\n                        \"(or leave blank to use the latest version):\"\n                    )\n                    question.attempts = 3\n                    question.validator = lambda x: (x or \"\").strip() or False\n\n                    constraint = self.ask(question)\n\n                    if constraint is False:\n                        _, constraint = self._find_best_version_for_package(package)\n\n                        self.line(\n                            \"Using version <info>{}</info> for <info>{}</info>\".format(\n                                constraint, package\n                            )\n                        )\n\n                    package += \" {}\".format(constraint)\n\n                if package is not False:\n                    requires.append(package)\n\n                package = self.ask(\"\\nSearch for a package:\")\n\n            return requires\n\n        requires = self._parse_name_version_pairs(requires)\n        result = []\n        for requirement in requires:\n            if \"version\" not in requirement:\n                # determine the best version automatically\n                name, version = self._find_best_version_for_package(\n                    requirement[\"name\"], allow_prereleases=allow_prereleases\n                )\n                requirement[\"version\"] = version\n                requirement[\"name\"] = name\n\n                self.line(\n                    \"Using version <info>{}</> for <info>{}</>\".format(version, name)\n                )\n            else:\n                # check that the specified version/constraint exists\n                # before we proceed\n                name, _ = self._find_best_version_for_package(\n                    requirement[\"name\"],\n                    requirement[\"version\"],\n                    allow_prereleases=allow_prereleases,\n                )\n\n                requirement[\"name\"] = name\n\n            result.append(\"{} {}\".format(requirement[\"name\"], requirement[\"version\"]))\n\n        return result\n\n    def _find_best_version_for_package(\n        self, name, required_version=None, allow_prereleases=False\n    ):  # type: (...) -> Tuple[str, str]\n        from poetry.version.version_selector import VersionSelector\n\n        selector = VersionSelector(self._get_pool())\n        package = selector.find_best_candidate(\n            name, required_version, allow_prereleases=allow_prereleases\n        )\n\n        if not package:\n            # TODO: find similar\n            raise ValueError(\n                \"Could not find a matching version of package {}\".format(name)\n            )\n\n        return (package.pretty_name, selector.find_recommended_require_version(package))\n\n    def _parse_name_version_pairs(self, pairs):  # type: (list) -> list\n        result = []\n\n        for i in range(len(pairs)):\n            pair = re.sub(\"^([^=: ]+)[=: ](.*)$\", \"\\\\1 \\\\2\", pairs[i].strip())\n            pair = pair.strip()\n\n            if \" \" in pair:\n                name, version = pair.split(\" \", 2)\n                result.append({\"name\": name, \"version\": version})\n            else:\n                result.append({\"name\": pair})\n\n        return result\n\n    def _format_requirements(self, requirements):  # type: (List[str]) -> dict\n        requires = {}\n        requirements = self._parse_name_version_pairs(requirements)\n        for requirement in requirements:\n            requires[requirement[\"name\"]] = requirement[\"version\"]\n\n        return requires\n\n    def _validate_author(self, author, default):\n        from poetry.packages.package import AUTHOR_REGEX\n\n        author = author or default\n\n        if author in [\"n\", \"no\"]:\n            return\n\n        m = AUTHOR_REGEX.match(author)\n        if not m:\n            raise ValueError(\n                \"Invalid author string. Must be in the format: \"\n                \"John Smith <john@example.com>\"\n            )\n\n        return author\n\n    def _validate_license(self, license):\n        from poetry.spdx import license_by_id\n\n        if license:\n            license_by_id(license)\n\n        return license\n\n    def _get_pool(self):\n        from poetry.repositories import Pool\n        from poetry.repositories.pypi_repository import PyPiRepository\n\n        if isinstance(self, VenvCommand):\n            return self.poetry.pool\n\n        if self._pool is None:\n            self._pool = Pool()\n            self._pool.add_repository(PyPiRepository())\n\n        return self._pool\n", "path": "poetry/console/commands/init.py"}]}