Skip to content

Commit

Permalink
installer: deprecate old installer (setting `experimental.new-install…
Browse files Browse the repository at this point in the history
…er` to false)
  • Loading branch information
radoering committed Feb 5, 2023
1 parent 53cdce0 commit de98f4b
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 45 deletions.
5 changes: 4 additions & 1 deletion src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,10 @@ def configure_installer_for_command(command: InstallerCommand, io: IO) -> None:
poetry.config,
disable_cache=poetry.disable_cache,
)
installer.use_executor(poetry.config.get("experimental.new-installer", False))
use_executor = poetry.config.get("experimental.new-installer", False)
if not use_executor:
# only set if false because the method is deprecated
installer.use_executor(False)
command.set_installer(installer)

def _load_plugins(self, io: IO | None = None) -> None:
Expand Down
7 changes: 4 additions & 3 deletions src/poetry/console/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ def handle(self) -> int:

from poetry.masonry.builders.editable import EditableBuilder

self.installer.use_executor(
self.poetry.config.get("experimental.new-installer", False)
)
use_executor = self.poetry.config.get("experimental.new-installer", False)
if not use_executor:
# only set if false because the method is deprecated
self.installer.use_executor(False)

if self.option("extras") and self.option("all-extras"):
self.line_error(
Expand Down
7 changes: 4 additions & 3 deletions src/poetry/console/commands/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ class LockCommand(InstallerCommand):
loggers = ["poetry.repositories.pypi_repository"]

def handle(self) -> int:
self.installer.use_executor(
self.poetry.config.get("experimental.new-installer", False)
)
use_executor = self.poetry.config.get("experimental.new-installer", False)
if not use_executor:
# only set if false because the method is deprecated
self.installer.use_executor(False)

if self.option("check"):
if self.poetry.locker.is_locked() and self.poetry.locker.is_fresh():
Expand Down
7 changes: 4 additions & 3 deletions src/poetry/console/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ class UpdateCommand(InstallerCommand):
def handle(self) -> int:
packages = self.argument("packages")

self.installer.use_executor(
self.poetry.config.get("experimental.new-installer", False)
)
use_executor = self.poetry.config.get("experimental.new-installer", False)
if not use_executor:
# only set if false because the method is deprecated
self.installer.use_executor(False)

if packages:
self.installer.whitelist({name: "*" for name in packages})
Expand Down
20 changes: 19 additions & 1 deletion src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import warnings

from typing import TYPE_CHECKING

from cleo.io.null_io import NullIO
Expand Down Expand Up @@ -71,7 +73,7 @@ def __init__(
)

self._executor = executor
self._use_executor = False
self._use_executor = True

self._installer = self._get_installer()
if installed is None:
Expand Down Expand Up @@ -180,6 +182,14 @@ def extras(self, extras: list[str]) -> Installer:
return self

def use_executor(self, use_executor: bool = True) -> Installer:
warnings.warn(
(
"Calling use_executor() is deprecated since it's true by default now"
" and deactivating it will be removed in a future release."
),
DeprecationWarning,
stacklevel=2,
)
self._use_executor = use_executor

return self
Expand Down Expand Up @@ -366,6 +376,14 @@ def _execute(self, operations: list[Operation]) -> int:
if self._use_executor:
return self._executor.execute(operations)

self._io.write_error(
"<warning>"
"Setting `experimental.new-installer` to false is deprecated and"
" slated for removal in an upcoming minor release.\n"
"(Despite of the setting's name the new installer is not experimental!)"
"</warning>"
)

if not operations and (self._execute_operations or self._dry_run):
self._io.write_line("No dependencies to install or update")

Expand Down
22 changes: 11 additions & 11 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,17 @@ def __init__(
self._execute = execute
self.executed: list[list[str]] = []

@property
def paths(self) -> dict[str, str]:
if self._paths is None:
self._paths = self.get_paths()
self._paths["platlib"] = str(self._path / "platlib")
self._paths["purelib"] = str(self._path / "purelib")
self._paths["scripts"] = str(self._path / "scripts")
self._paths["data"] = str(self._path / "data")

return self._paths

def _run(self, cmd: list[str], **kwargs: Any) -> int | str:
self.executed.append(cmd)

Expand Down Expand Up @@ -2060,17 +2071,6 @@ def sys_path(self) -> list[str]:

return self._sys_path

@property
def paths(self) -> dict[str, str]:
if self._paths is None:
self._paths = self.get_paths()
self._paths["platlib"] = str(self._path / "platlib")
self._paths["purelib"] = str(self._path / "purelib")
self._paths["scripts"] = str(self._path / "scripts")
self._paths["data"] = str(self._path / "data")

return self._paths

def get_marker_env(self) -> dict[str, Any]:
if self._mock_marker_env is not None:
return self._mock_marker_env
Expand Down
3 changes: 2 additions & 1 deletion tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:

@pytest.fixture()
def old_tester(tester: CommandTester) -> CommandTester:
tester.command.installer.use_executor(False)
with pytest.warns(DeprecationWarning):
tester.command.installer.use_executor(False)

return tester

Expand Down
1 change: 0 additions & 1 deletion tests/console/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ def _tester(
executor=executor
or TestExecutor(env, poetry.pool, poetry.config, tester.io),
)
installer.use_executor(True)
command.set_installer(installer)

return tester
Expand Down
21 changes: 0 additions & 21 deletions tests/installation/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ def installer(
installed=installed,
executor=Executor(env, pool, config, NullIO()),
)
installer.use_executor(True)

return installer


Expand Down Expand Up @@ -1961,8 +1959,6 @@ def test_installer_required_extras_should_not_be_removed_when_updating_single_de
installed=installed,
executor=Executor(env, pool, config, NullIO()),
)
installer.use_executor()

installer.update(True)
installer.whitelist(["D"])
installer.run()
Expand Down Expand Up @@ -1996,7 +1992,6 @@ def test_installer_required_extras_should_not_be_removed_when_updating_single_de
installed=installed,
executor=Executor(env, pool, config, NullIO()),
)
installer.use_executor()

package.add_dependency(Factory.create_dependency("poetry", {"version": "^0.12.0"}))

Expand Down Expand Up @@ -2025,8 +2020,6 @@ def test_installer_required_extras_should_not_be_removed_when_updating_single_de
installed=installed,
executor=Executor(env, pool, config, NullIO()),
)
installer.use_executor()

installer.update(True)
installer.whitelist(["pytest"])
installer.run()
Expand Down Expand Up @@ -2057,8 +2050,6 @@ def test_installer_required_extras_should_be_installed(
installed=installed,
executor=Executor(env, pool, config, NullIO()),
)
installer.use_executor()

package.add_dependency(
Factory.create_dependency(
"cachecontrol", {"version": "^0.12.5", "extras": ["filecache"]}
Expand All @@ -2085,8 +2076,6 @@ def test_installer_required_extras_should_be_installed(
installed=installed,
executor=Executor(env, pool, config, NullIO()),
)
installer.use_executor()

installer.update(True)
installer.run()

Expand Down Expand Up @@ -2200,8 +2189,6 @@ def test_installer_can_install_dependencies_from_forced_source(
installed=installed,
executor=Executor(env, pool, config, NullIO()),
)
installer.use_executor()

installer.update(True)
installer.run()

Expand Down Expand Up @@ -2267,7 +2254,6 @@ def test_run_installs_with_same_version_url_files(
NullIO(),
),
)
installer.use_executor(True)
installer.run()

expected = fixture("with-same-version-url-dependencies")
Expand Down Expand Up @@ -2332,8 +2318,6 @@ def test_installer_can_handle_old_lock_files(
installed=installed,
executor=Executor(MockEnv(), pool, config, NullIO()),
)
installer.use_executor()

installer.run()

assert installer.executor.installations_count == 6
Expand All @@ -2353,8 +2337,6 @@ def test_installer_can_handle_old_lock_files(
NullIO(),
),
)
installer.use_executor()

installer.run()

# funcsigs will be added
Expand All @@ -2375,8 +2357,6 @@ def test_installer_can_handle_old_lock_files(
NullIO(),
),
)
installer.use_executor()

installer.run()

# colorama will be added
Expand Down Expand Up @@ -2640,7 +2620,6 @@ def test_installer_distinguishes_locked_packages_by_source(
NullIO(),
),
)
installer.use_executor(True)
installer.run()

# Results of installation are consistent with the platform requirements.
Expand Down
5 changes: 5 additions & 0 deletions tests/installation/test_installer_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any

import pytest

Expand Down Expand Up @@ -40,6 +41,10 @@


class Installer(BaseInstaller):
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self._use_executor = False

def _get_installer(self) -> NoopInstaller:
return NoopInstaller()

Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit de98f4b

Please sign in to comment.