-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update poetry to work with poetry-core after tomlkit is removed from …
…there (#6616) Co-authored-by: Randy Döring <[email protected]>
- Loading branch information
Showing
36 changed files
with
318 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from poetry.core.pyproject.toml import PyProjectTOML as BasePyProjectTOML | ||
from tomlkit.api import table | ||
from tomlkit.items import Table | ||
from tomlkit.toml_document import TOMLDocument | ||
|
||
from poetry.toml import TOMLFile | ||
|
||
|
||
if TYPE_CHECKING: | ||
from pathlib import Path | ||
|
||
|
||
class PyProjectTOML(BasePyProjectTOML): | ||
""" | ||
Enhanced version of poetry-core's PyProjectTOML | ||
which is capable of writing pyproject.toml | ||
The poetry-core class uses tomli to read the file, | ||
here we use tomlkit to preserve comments and formatting when writing. | ||
""" | ||
|
||
def __init__(self, path: Path) -> None: | ||
super().__init__(path) | ||
self._toml_file = TOMLFile(path=path) | ||
self._toml_document: TOMLDocument | None = None | ||
|
||
@property | ||
def file(self) -> TOMLFile: # type: ignore[override] | ||
return self._toml_file | ||
|
||
@property | ||
def data(self) -> TOMLDocument: | ||
if self._toml_document is None: | ||
if not self.file.exists(): | ||
self._toml_document = TOMLDocument() | ||
else: | ||
self._toml_document = self.file.read() | ||
|
||
return self._toml_document | ||
|
||
def save(self) -> None: | ||
data = self.data | ||
|
||
if self._build_system is not None: | ||
if "build-system" not in data: | ||
data["build-system"] = table() | ||
|
||
build_system = data["build-system"] | ||
assert isinstance(build_system, Table) | ||
|
||
build_system["requires"] = self._build_system.requires | ||
build_system["build-backend"] = self._build_system.build_backend | ||
|
||
self.file.write(data=data) | ||
|
||
def reload(self) -> None: | ||
self._toml_document = None | ||
self._build_system = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from __future__ import annotations | ||
|
||
from poetry.toml.exceptions import TOMLError | ||
from poetry.toml.file import TOMLFile | ||
|
||
|
||
__all__ = ["TOMLError", "TOMLFile"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from __future__ import annotations | ||
|
||
from poetry.core.exceptions import PoetryCoreException | ||
from tomlkit.exceptions import TOMLKitError | ||
|
||
|
||
class TOMLError(TOMLKitError, PoetryCoreException): | ||
pass |
Oops, something went wrong.