Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removing tomlkit from poetry locker #131

Merged
merged 3 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import cast

import pytest

Expand Down Expand Up @@ -179,7 +180,13 @@ def _factory(

poetry = Factory().create_poetry(project_dir)

locker = TestLocker(poetry.locker.lock.path, poetry.locker._local_config)
lock = poetry.locker.lock
if isinstance(lock, Path):
lock_path = cast("Path", lock)
else:
# poetry < 1.3
lock_path = lock.path
locker = TestLocker(lock_path, poetry.locker._local_config)
locker.write()

poetry.set_locker(locker)
Expand Down
20 changes: 10 additions & 10 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
import os

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

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
Expand All @@ -34,17 +33,18 @@ def reset_poetry(self) -> None:
self._poetry = Factory().create_poetry(poetry.file.path.parent)
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)
)
lock = poetry.locker.lock
if isinstance(lock, Path):
lock_path = cast("Path", lock)
else:
# poetry < 1.3
lock_path = lock.path
self._poetry.set_locker(TestLocker(lock_path, self._poetry.local_config))


class TestLocker(Locker):
def __init__(self, lock: str | Path, local_config: dict[str, Any]) -> None:
self._lock = TOMLFile(lock)
self._local_config = local_config
self._lock_data: TOMLDocument | None = None
self._content_hash = self._get_content_hash()
super().__init__(lock, local_config)
self._locked = False
self._write = False
self._contains_credential = False
Expand Down
4 changes: 1 addition & 3 deletions tests/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from cleo.io.null_io import NullIO
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 @@ -46,9 +45,8 @@

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

def locked(self, is_locked: bool = True) -> Locker:
self._locked = is_locked
Expand Down