Skip to content

Commit

Permalink
refactor(solver/provider): move progress() from Provider to Solver
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Aug 23, 2022
1 parent 8fe87d1 commit 6c9e9d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
19 changes: 0 additions & 19 deletions src/poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def __init__(
self._env: Env | None = None
self._python_constraint = package.python_constraint
self._is_debugging: bool = self._io.is_debug() or self._io.is_very_verbose()
self._in_progress = False
self._overrides: dict[DependencyPackage, dict[str, Dependency]] = {}
self._deferred_cache: dict[Dependency, Package] = {}
self._load_deferred = True
Expand Down Expand Up @@ -888,24 +887,6 @@ def debug(self, message: str, depth: int = 0) -> None:

self._io.write(debug_info)

@contextmanager
def progress(self) -> Iterator[None]:
if not self._io.output.is_decorated() or self.is_debugging():
self._io.write_line("Resolving dependencies...")
yield
else:
indicator = Indicator(
self._io, "{message}{context}<debug>({elapsed:2s})</debug>"
)

with indicator.auto(
"<info>Resolving dependencies...</info>",
"<info>Resolving dependencies...</info>",
):
yield

self._in_progress = False

def _merge_dependencies_by_constraint(
self, dependencies: Iterable[Dependency]
) -> list[Dependency]:
Expand Down
23 changes: 20 additions & 3 deletions src/poetry/puzzle/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from poetry.packages import DependencyPackage
from poetry.puzzle.exceptions import OverrideNeeded
from poetry.puzzle.exceptions import SolverProblemError
from poetry.puzzle.provider import Indicator
from poetry.puzzle.provider import Provider


Expand Down Expand Up @@ -64,7 +65,7 @@ def use_environment(self, env: Env) -> Iterator[None]:
def solve(self, use_latest: list[str] | None = None) -> Transaction:
from poetry.puzzle.transaction import Transaction

with self._provider.progress():
with self._progress():
start = time.time()
packages, depths = self._solve(use_latest=use_latest)
end = time.time()
Expand Down Expand Up @@ -96,7 +97,23 @@ def solve(self, use_latest: list[str] | None = None) -> Transaction:
root_package=self._package,
)

def solve_in_compatibility_mode(
@contextmanager
def _progress(self) -> Iterator[None]:
if not self._io.output.is_decorated() or self._provider.is_debugging():
self._io.write_line("Resolving dependencies...")
yield
else:
indicator = Indicator(
self._io, "{message}{context}<debug>({elapsed:2s})</debug>"
)

with indicator.auto(
"<info>Resolving dependencies...</info>",
"<info>Resolving dependencies...</info>",
):
yield

def _solve_in_compatibility_mode(
self,
overrides: tuple[dict[DependencyPackage, dict[str, Dependency]], ...],
use_latest: list[str] | None = None,
Expand Down Expand Up @@ -150,7 +167,7 @@ def _solve(

packages = result.packages
except OverrideNeeded as e:
return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
return self._solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
except SolveFailure as e:
raise SolverProblemError(e)

Expand Down

0 comments on commit 6c9e9d0

Please sign in to comment.