Commit 1b795033 by Sébastien Eustace

Fix add and init in a cleaner way

parent f0bb4970
...@@ -29,9 +29,6 @@ If you do not specify a version constraint, poetry will choose a suitable one ba ...@@ -29,9 +29,6 @@ If you do not specify a version constraint, poetry will choose a suitable one ba
'poetry.repositories.pypi_repository' 'poetry.repositories.pypi_repository'
] ]
def initialize(self, i, o):
super(AddCommand, self).initialize(i, o)
def handle(self): def handle(self):
from poetry.installation import Installer from poetry.installation import Installer
from poetry.semver import parse_constraint from poetry.semver import parse_constraint
......
...@@ -7,6 +7,7 @@ from typing import List ...@@ -7,6 +7,7 @@ from typing import List
from typing import Tuple from typing import Tuple
from .command import Command from .command import Command
from .venv_command import VenvCommand
class InitCommand(Command): class InitCommand(Command):
...@@ -31,17 +32,7 @@ The <info>init</info> command creates a basic <comment>pyproject.toml</> file in ...@@ -31,17 +32,7 @@ The <info>init</info> command creates a basic <comment>pyproject.toml</> file in
def __init__(self): def __init__(self):
super(InitCommand, self).__init__() super(InitCommand, self).__init__()
self.pool = None self._pool = None
def initialize(self, i, o):
from poetry.repositories import Pool
from poetry.repositories.pypi_repository import PyPiRepository
super(InitCommand, self).initialize(i, o)
if self.pool is None:
self.pool = Pool()
self.pool.add_repository(PyPiRepository())
def handle(self): def handle(self):
from poetry.layouts import layout from poetry.layouts import layout
...@@ -326,7 +317,14 @@ The <info>init</info> command creates a basic <comment>pyproject.toml</> file in ...@@ -326,7 +317,14 @@ The <info>init</info> command creates a basic <comment>pyproject.toml</> file in
return author return author
def _get_pool(self): def _get_pool(self):
if self.pool is None: from poetry.repositories import Pool
self.pool = self.poetry.pool from poetry.repositories.pypi_repository import PyPiRepository
if isinstance(self, VenvCommand):
return self.poetry.pool
if self._pool is None:
self._pool = Pool()
self._pool.add_repository(PyPiRepository())
return self.pool return self._pool
...@@ -18,8 +18,10 @@ def tmp_dir(): ...@@ -18,8 +18,10 @@ def tmp_dir():
shutil.rmtree(dir_) shutil.rmtree(dir_)
def test_basic_interactive(app, mocker): def test_basic_interactive(app, mocker, poetry):
command = app.find('init') command = app.find('init')
command._pool = poetry.pool
mocker.patch('poetry.utils._compat.Path.open') mocker.patch('poetry.utils._compat.Path.open')
p = mocker.patch('poetry.utils._compat.Path.cwd') p = mocker.patch('poetry.utils._compat.Path.cwd')
p.return_value = Path(__file__) p.return_value = Path(__file__)
...@@ -57,10 +59,12 @@ pytest = "^3.5" ...@@ -57,10 +59,12 @@ pytest = "^3.5"
assert expected in output assert expected in output
def test_interactive_with_dependencies(app, repo, mocker): def test_interactive_with_dependencies(app, repo, mocker, poetry):
repo.add_package(get_package('pendulum', '2.0.0')) repo.add_package(get_package('pendulum', '2.0.0'))
command = app.find('init') command = app.find('init')
command._pool = poetry.pool
mocker.patch('poetry.utils._compat.Path.open') mocker.patch('poetry.utils._compat.Path.open')
p = mocker.patch('poetry.utils._compat.Path.cwd') p = mocker.patch('poetry.utils._compat.Path.cwd')
p.return_value = Path(__file__).parent p.return_value = Path(__file__).parent
...@@ -100,6 +104,4 @@ pendulum = "^2.0" ...@@ -100,6 +104,4 @@ pendulum = "^2.0"
pytest = "^3.5" pytest = "^3.5"
""" """
print(output)
assert expected in output assert expected in 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