Skip to content

Commit

Permalink
ensure compatibility with Poetry 2.0 (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering authored Jan 5, 2025
1 parent 0104775 commit 70bbc09
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 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 @@ -16,7 +16,7 @@ include = [

[tool.poetry.dependencies]
python = "^3.9"
poetry = "^1.5.0"
poetry = ">=1.5.0,<3.0.0"

[tool.poetry.group.dev.dependencies]
pre-commit = ">=2.6"
Expand Down
20 changes: 17 additions & 3 deletions src/poetry_plugin_bundle/bundlers/venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ def bundle(self, poetry: Poetry, io: IO) -> bool:

from cleo.io.null_io import NullIO
from poetry.core.masonry.builders.wheel import WheelBuilder
from poetry.core.masonry.utils.module import ModuleOrPackageNotFound

try:
from poetry.core.masonry.utils.module import ( # type: ignore[attr-defined]
ModuleOrPackageNotFoundError,
)
except ImportError:
# poetry-core < 2.0
from poetry.core.masonry.utils.module import (
ModuleOrPackageNotFound as ModuleOrPackageNotFoundError,
)
from poetry.core.packages.package import Package
from poetry.installation.installer import Installer
from poetry.installation.operations.install import Install
Expand Down Expand Up @@ -140,7 +149,12 @@ def locked_repository(self) -> LockfileRepository:
package.develop = False
return repo

custom_locker = CustomLocker(poetry.locker.lock, poetry.local_config)
try:
locker_data = poetry.locker._pyproject_data # type: ignore[attr-defined]
except AttributeError:
# poetry < 2.0
locker_data = poetry.locker._local_config
custom_locker = CustomLocker(poetry.locker.lock, locker_data)

installer = Installer(
NullIO() if not io.is_debug() else io,
Expand Down Expand Up @@ -192,7 +206,7 @@ def locked_repository(self) -> LockfileRepository:
source_url=str(wheel),
)
installer.executor.execute([Install(package)])
except ModuleOrPackageNotFound:
except ModuleOrPackageNotFoundError:
warnings.append(
"The root package was not installed because no matching module or"
" package was found."
Expand Down
7 changes: 6 additions & 1 deletion tests/console/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ def poetry(project_directory: str, config: Config) -> Poetry:
p = Factory().create_poetry(
Path(__file__).parent.parent / "fixtures" / project_directory
)
p.set_locker(TestLocker(p.locker.lock, p.locker._local_config))
try:
locker_data = p.locker._pyproject_data # type: ignore[attr-defined]
except AttributeError:
# poetry < 2.0
locker_data = p.locker._local_config
p.set_locker(TestLocker(p.locker.lock, locker_data))

return p

Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/simple_project/poetry.lock

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

1 change: 1 addition & 0 deletions tests/fixtures/simple_project_with_dev_dep/poetry.lock

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

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

1 change: 1 addition & 0 deletions tests/fixtures/simple_project_with_no_module/poetry.lock

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

0 comments on commit 70bbc09

Please sign in to comment.