Skip to content

Commit

Permalink
backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Mar 22, 2023
1 parent f388461 commit 18b3ecc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/poetry/console/commands/check.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from pathlib import Path

from poetry.console.commands.command import Command


Expand Down Expand Up @@ -62,8 +64,13 @@ def handle(self) -> int:
from poetry.pyproject.toml import PyProjectTOML

# Load poetry config and display errors, if any
poetry_file = self.poetry.file
config = PyProjectTOML(poetry_file).poetry_config
if isinstance(self.poetry.file, Path):
toml_path = self.poetry.file
else:
# TODO: backward compatibility, can be simplified if poetry-core with
# https://github.com/python-poetry/poetry-core/pull/483 is available
toml_path = self.poetry.file.path # type: ignore[assignment]
config = PyProjectTOML(toml_path).poetry_config
check_result = Factory.validate(config, strict=True)

# Validate trove classifiers
Expand Down
11 changes: 9 additions & 2 deletions src/poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import re

from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import cast
Expand All @@ -24,7 +25,6 @@

if TYPE_CHECKING:
from collections.abc import Iterable
from pathlib import Path

from cleo.io.io import IO
from poetry.core.packages.package import Package
Expand Down Expand Up @@ -81,8 +81,15 @@ def create_poetry(

config.merge({"repositories": repositories})

if isinstance(base_poetry.file, Path):
toml_path = base_poetry.file
else:
# TODO: backward compatibility, can be simplified if poetry-core with
# https://github.com/python-poetry/poetry-core/pull/483 is available
toml_path = base_poetry.file.path # type: ignore[assignment]

poetry = Poetry(
base_poetry.file,
toml_path,
base_poetry.local_config,
base_poetry.package,
locker,
Expand Down
10 changes: 9 additions & 1 deletion src/poetry/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ def __init__(
) -> None:
from poetry.repositories.repository_pool import RepositoryPool

super().__init__(file, local_config, package, pyproject_type=PyProjectTOML)
try:
super().__init__( # type: ignore[call-arg]
file, local_config, package, pyproject_type=PyProjectTOML
)
except TypeError:
# TODO: backward compatibility, can be simplified if poetry-core with
# https://github.com/python-poetry/poetry-core/pull/483 is available
super().__init__(file, local_config, package)
self._pyproject = PyProjectTOML(file)

self._locker = locker
self._config = config
Expand Down

0 comments on commit 18b3ecc

Please sign in to comment.