Skip to content

Commit

Permalink
removing tomlkit from poetry locker
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Oct 3, 2022
1 parent 1b12358 commit 38d964a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _factory(

poetry = Factory().create_poetry(project_dir)

locker = TestLocker(poetry.locker.lock.path, poetry.locker._local_config)
locker = TestLocker(poetry.locker.lock, poetry.locker._local_config)
locker.write()

poetry.set_locker(locker)
Expand Down
15 changes: 6 additions & 9 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@
import os

from contextlib import contextmanager
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import Iterator

from poetry.console.application import Application
from poetry.core.toml.file import TOMLFile
from poetry.factory import Factory
from poetry.installation.executor import Executor
from poetry.packages import Locker


if TYPE_CHECKING:
from pathlib import Path

from poetry.core.packages.package import Package
from poetry.installation.operations.operation import Operation
from poetry.poetry import Poetry
from tomlkit.toml_document import TOMLDocument


class PoetryTestApplication(Application):
Expand All @@ -35,15 +32,15 @@ def reset_poetry(self) -> None:
self._poetry.set_pool(poetry.pool)
self._poetry.set_config(poetry.config)
self._poetry.set_locker(
TestLocker(poetry.locker.lock.path, self._poetry.local_config)
TestLocker(poetry.locker.lock, self._poetry.local_config)
)


class TestLocker(Locker):
def __init__(self, lock: str | Path, local_config: dict[str, Any]) -> None:
self._lock = TOMLFile(lock)
self._lock = lock if isinstance(lock, Path) else Path(lock)
self._local_config = local_config
self._lock_data: TOMLDocument | None = None
self._lock_data: dict[str, Any] | None = None
self._content_hash = self._get_content_hash()
self._locked = False
self._write = False
Expand All @@ -63,12 +60,12 @@ def locked(self, is_locked: bool = True) -> TestLocker:
def mock_lock_data(self, data: dict[str, Any]) -> None:
self.locked()

self._lock_data = data # type: ignore[assignment]
self._lock_data = data

def is_fresh(self) -> bool:
return True

def _write_lock_data(self, data: TOMLDocument) -> None:
def _write_lock_data(self, data: dict[str, Any]) -> None:
if self._write:
super()._write_lock_data(data)
self._locked = True
Expand Down
5 changes: 2 additions & 3 deletions tests/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from cleo.io.buffered_io import BufferedIO
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.dependency_group import MAIN_GROUP
from poetry.core.toml.file import TOMLFile
from poetry.core.version.markers import parse_marker
from poetry.factory import Factory
from poetry.packages import Locker as BaseLocker
Expand Down Expand Up @@ -45,7 +44,7 @@

class Locker(BaseLocker):
def __init__(self, fixture_root: Path) -> None:
self._lock = TOMLFile(fixture_root / "poetry.lock")
self._lock = fixture_root / "poetry.lock"
self._locked = True
self._content_hash = self._get_content_hash()

Expand All @@ -55,7 +54,7 @@ def locked(self, is_locked: bool = True) -> Locker:
return self

def mock_lock_data(self, data: dict[str, Any]) -> None:
self._lock_data = data # type: ignore[assignment]
self._lock_data = data

def is_locked(self) -> bool:
return self._locked
Expand Down

0 comments on commit 38d964a

Please sign in to comment.