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

Poetry core update #7922

Merged
merged 6 commits into from
May 15, 2023
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
16 changes: 8 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Changelog = "https://python-poetry.org/history/"
[tool.poetry.dependencies]
python = "^3.7"

poetry-core = "1.5.2"
poetry-core = "1.6.0"
poetry-plugin-export = "^1.3.1"
"backports.cached-property" = { version = "^1.0.2", python = "<3.8" }
build = "^0.10.0"
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/config/file_config_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def secure(self) -> Iterator[TOMLDocument]:
mode = 0o600

if new_file:
self.file.touch(mode=mode)
self.file.path.touch(mode=mode)

self.file.write(config)
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def handle(self) -> int:
constraint_name,
constraint,
groups=[group],
root_dir=self.poetry.file.parent,
root_dir=self.poetry.file.path.parent,
)
)

Expand Down
4 changes: 2 additions & 2 deletions src/poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def handle(self) -> int:
config_file = TOMLFile(CONFIG_DIR / "config.toml")

try:
local_config_file = TOMLFile(self.poetry.file.parent / "poetry.toml")
local_config_file = TOMLFile(self.poetry.file.path.parent / "poetry.toml")
if local_config_file.exists():
config.merge(local_config_file.read())
except (RuntimeError, PyProjectException):
Expand All @@ -106,7 +106,7 @@ def handle(self) -> int:

if not config_file.exists():
config_file.path.parent.mkdir(parents=True, exist_ok=True)
config_file.touch(mode=0o0600)
config_file.path.touch(mode=0o0600)

if self.option("list"):
self._list_configuration(config.all(), config.raw())
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def _parse_requirements(self, requirements: list[str]) -> list[dict[str, Any]]:
from poetry.core.pyproject.exceptions import PyProjectException

try:
cwd = self.poetry.file.parent
cwd = self.poetry.file.path.parent
artifact_cache = self.poetry.pool.artifact_cache
except (PyProjectException, RuntimeError):
cwd = Path.cwd()
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _module(self) -> Module:

poetry = self.poetry
package = poetry.package
path = poetry.file.parent
path = poetry.file.path.parent
module = Module(package.name, path.as_posix(), package.packages)

return module
Expand Down
10 changes: 5 additions & 5 deletions src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,15 @@ def _display_packages_information(
version_length,
len(
get_package_version_display_string(
locked, root=self.poetry.file.parent
locked, root=self.poetry.file.path.parent
)
),
)
latest_length = max(
latest_length,
len(
get_package_version_display_string(
latest, root=self.poetry.file.parent
latest, root=self.poetry.file.path.parent
)
),
)
Expand All @@ -292,7 +292,7 @@ def _display_packages_information(
version_length,
len(
get_package_version_display_string(
locked, root=self.poetry.file.parent
locked, root=self.poetry.file.path.parent
)
),
)
Expand Down Expand Up @@ -353,7 +353,7 @@ def _display_packages_information(
)
if write_version:
version = get_package_version_display_string(
locked, root=self.poetry.file.parent
locked, root=self.poetry.file.path.parent
)
line += f" <b>{version:{version_length}}</b>"
if show_latest:
Expand All @@ -368,7 +368,7 @@ def _display_packages_information(
color = "yellow"

version = get_package_version_display_string(
latest, root=self.poetry.file.parent
latest, root=self.poetry.file.path.parent
)
line += f" <fg={color}>{version:{latest_length}}</>"

Expand Down
7 changes: 1 addition & 6 deletions src/poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ def create_poetry(

base_poetry = super().create_poetry(cwd=cwd, with_groups=with_groups)

# TODO: backward compatibility, can be simplified if poetry-core with
# https://github.com/python-poetry/poetry-core/pull/483 is available
poetry_file: Path = (
getattr(base_poetry, "pyproject_path", None) or base_poetry.file.path
)

poetry_file = base_poetry.pyproject_path
locker = Locker(poetry_file.parent / "poetry.lock", base_poetry.local_config)

# Loading global configuration
Expand Down
7 changes: 2 additions & 5 deletions src/poetry/layouts/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,10 @@ def get_package_include(self) -> InlineTable | None:
return None

include = parts[0]
package.append("include", include) # type: ignore[no-untyped-call]
package.append("include", include)

if self.basedir != Path():
package.append( # type: ignore[no-untyped-call]
"from",
self.basedir.as_posix(),
)
package.append("from", self.basedir.as_posix())
else:
if include == self._project:
# package include and package name are the same,
Expand Down
10 changes: 5 additions & 5 deletions src/poetry/masonry/builders/editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _setup_build(self) -> None:
pip_install(self._path, self._env, upgrade=True, editable=True)
else:
# Temporarily rename pyproject.toml
renamed_pyproject = self._poetry.file.with_suffix(".tmp")
renamed_pyproject = self._poetry.file.path.with_suffix(".tmp")
self._poetry.file.path.rename(renamed_pyproject)
try:
pip_install(self._path, self._env, upgrade=True, editable=True)
Expand All @@ -130,7 +130,7 @@ def _add_pth(self) -> list[Path]:
for file in self._env.site_packages.find(path=pth_file, writable_only=True):
self._debug(
f" - Removing existing <c2>{file.name}</c2> from <b>{file.parent}</b>"
f" for {self._poetry.file.parent}"
f" for {self._poetry.file.path.parent}"
)
# We can't use unlink(missing_ok=True) because it's not always available
if file.exists():
Expand All @@ -142,14 +142,14 @@ def _add_pth(self) -> list[Path]:
)
self._debug(
f" - Adding <c2>{pth_file.name}</c2> to <b>{pth_file.parent}</b> for"
f" {self._poetry.file.parent}"
f" {self._poetry.file.path.parent}"
)
return [pth_file]
except OSError:
# TODO: Replace with PermissionError
self._io.write_error_line(
f" - Failed to create <c2>{pth_file.name}</c2> for"
f" {self._poetry.file.parent}"
f" {self._poetry.file.path.parent}"
)
return []

Expand All @@ -163,7 +163,7 @@ def _add_scripts(self) -> list[Path]:
else:
self._io.write_error_line(
" - Failed to find a suitable script installation directory for"
f" {self._poetry.file.parent}"
f" {self._poetry.file.path.parent}"
)
return []

Expand Down
12 changes: 2 additions & 10 deletions src/poetry/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,7 @@ def __init__(
) -> None:
from poetry.repositories.repository_pool import RepositoryPool

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)
super().__init__(file, local_config, package, pyproject_type=PyProjectTOML)

self._locker = locker
self._config = config
Expand All @@ -59,7 +51,7 @@ def pyproject(self) -> PyProjectTOML:
return cast("PyProjectTOML", pyproject)

@property
def file(self) -> TOMLFile: # type: ignore[override]
def file(self) -> TOMLFile:
return self.pyproject.file

@property
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/publishing/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def adapter(self) -> adapters.HTTPAdapter:

@property
def files(self) -> list[Path]:
dist = self._poetry.file.parent / "dist"
dist = self._poetry.file.path.parent / "dist"
version = self._package.version.to_string()
escaped_name = distribution_name(self._package.name)

Expand Down Expand Up @@ -301,7 +301,7 @@ def _register(self, session: requests.Session, url: str) -> requests.Response:
"""
Register a package to a repository.
"""
dist = self._poetry.file.parent / "dist"
dist = self._poetry.file.path.parent / "dist"
escaped_name = distribution_name(self._package.name)
file = dist / f"{escaped_name}-{self._package.version.to_string()}.tar.gz"

Expand Down
2 changes: 1 addition & 1 deletion src/poetry/pyproject/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, path: Path) -> None:
self._toml_document: TOMLDocument | None = None

@property
def file(self) -> TOMLFile: # type: ignore[override]
def file(self) -> TOMLFile:
return self._toml_file

@property
Expand Down
4 changes: 1 addition & 3 deletions src/poetry/repositories/installed_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,7 @@ def load(cls, env: Env, with_dependencies: bool = False) -> InstalledRepository:
continue

for distribution in sorted(
metadata.distributions( # type: ignore[no-untyped-call]
path=[entry],
),
metadata.distributions(path=[entry]),
key=lambda d: str(d._path), # type: ignore[attr-defined]
):
path = Path(str(distribution._path)) # type: ignore[attr-defined]
Expand Down
11 changes: 11 additions & 0 deletions src/poetry/toml/file.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 typing import Any

Expand Down Expand Up @@ -35,6 +37,15 @@ def read(self) -> TOMLDocument:
raise TOMLError(f"Invalid TOML file {self.path.as_posix()}: {e}")

def __getattr__(self, item: str) -> Any:
dimbleby marked this conversation as resolved.
Show resolved Hide resolved
warnings.warn(
(
"`__getattr__` will be removed from the `TOMLFile` in a future release."
"\n\nInstead of accessing properties of the underlying `Path` as "
"`tomlfile.whatever`, prefer `tomlfile.path.whatever`."
),
DeprecationWarning,
stacklevel=2,
)
return getattr(self.__path, item)

def __str__(self) -> str:
Expand Down
Loading