Skip to content
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
15 changes: 6 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ jobs:
run:
shell: bash
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Get full Python version
id: full-python-version
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
run: echo "version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")" >> $GITHUB_OUTPUT

- name: Bootstrap poetry
run: |
Expand All @@ -57,7 +57,7 @@ jobs:
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v2
uses: actions/cache@v3
id: cache
with:
path: .venv
Expand All @@ -68,13 +68,10 @@ jobs:
run: timeout 10s poetry run pip --version || rm -rf .venv

- name: Install dependencies
run: poetry install

- name: Install pytest plugin
run: poetry run pip install pytest-github-actions-annotate-failures
run: poetry install --with github-actions

- name: Run mypy
run: poetry run mypy

- name: Run pytest
run: poetry run python -m pytest -p no:sugar -q tests/
run: poetry run pytest -v
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Python 3.9
uses: actions/setup-python@v2
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.10"

- name: Install Poetry
run: |
curl -sL https://install.python-poetry.org | python - -y ${{ matrix.bootstrap-args }}
curl -sSL https://install.python-poetry.org | python - -y

- name: Update PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
Expand All @@ -32,7 +32,7 @@ jobs:
id: check-version
run: |
[[ "$(poetry version --short)" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] \
|| echo ::set-output name=prerelease::true
|| echo prerelease=true >> $GITHUB_OUTPUT

- name: Create Release
uses: ncipollo/release-action@v1
Expand Down
1,820 changes: 1,083 additions & 737 deletions poetry.lock

Large diffs are not rendered by default.

25 changes: 19 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ include = [

[tool.poetry.dependencies]
python = "^3.7"
poetry = "^1.2.0"
poetry = "^1.4.0"

[tool.poetry.dev-dependencies]
pre-commit = "^2.6"
pytest = "^7.1.2"
pytest-mock = "^3.6.1"
mypy = ">=0.950"
[tool.poetry.group.dev.dependencies]
pre-commit = ">=2.6"
pytest = ">=7.1.2"
pytest-mock = ">=3.6.1"
mypy = ">=1.1.1"

# only used in github actions
[tool.poetry.group.github-actions]
optional = true
[tool.poetry.group.github-actions.dependencies]
pytest-github-actions-annotate-failures = "^0.1.7"

[tool.poetry.plugins."poetry.application.plugin"]
export = "poetry_plugin_bundle.plugin:BundleApplicationPlugin"
Expand Down Expand Up @@ -58,6 +64,13 @@ module = [
]
ignore_missing_imports = true


[tool.pytest.ini_options]
testpaths = [
"tests"
]


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
38 changes: 18 additions & 20 deletions src/poetry_plugin_bundle/bundlers/venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from subprocess import CalledProcessError
from typing import TYPE_CHECKING
from typing import cast

from poetry_plugin_bundle.bundlers.bundler import Bundler

Expand All @@ -14,7 +13,8 @@
from pathlib import Path

from cleo.io.io import IO
from poetry.core.semver.version import Version
from cleo.io.outputs.section_output import SectionOutput
from poetry.core.constraints.version import Version
from poetry.poetry import Poetry


Expand Down Expand Up @@ -52,10 +52,10 @@ def bundle(self, poetry: Poetry, io: IO) -> bool:
from tempfile import TemporaryDirectory

from cleo.io.null_io import NullIO
from poetry.core.constraints.version import Version
from poetry.core.masonry.builders.wheel import WheelBuilder
from poetry.core.masonry.utils.module import ModuleOrPackageNotFound
from poetry.core.packages.package import Package
from poetry.core.semver.version import Version
from poetry.installation.installer import Installer
from poetry.installation.operations.install import Install
from poetry.utils.env import EnvManager
Expand All @@ -74,7 +74,7 @@ def bundle(self, poetry: Poetry, io: IO) -> bool:

message = self._get_message(poetry, self._path)
if io.is_decorated() and not io.is_debug():
io = io.section()
io = io.section() # type: ignore[assignment]

io.write_line(message)

Expand Down Expand Up @@ -134,7 +134,10 @@ def bundle(self, poetry: Poetry, io: IO) -> bool:
if self._activated_groups is not None:
installer.only_groups(self._activated_groups)
installer.requires_synchronization()
installer.use_executor(poetry.config.get("experimental.new-installer", False))
use_executor = poetry.config.get("experimental.new-installer", False)
if not use_executor:
# only set if false because the method is deprecated
installer.use_executor(False)

return_code = installer.run()
if return_code:
Expand Down Expand Up @@ -202,19 +205,17 @@ def _get_message(
f" (<b>{poetry.package.pretty_version}</b>) into <c2>{path}</c2>"
)

def _write(self, io: IO, message: str) -> None:
def _write(self, io: IO | SectionOutput, message: str) -> None:
from cleo.io.outputs.section_output import SectionOutput

if io.is_debug() or not io.is_decorated() or not isinstance(io, SectionOutput):
io.write_line(message)
return

io = cast(SectionOutput, io)
io.overwrite(message)

def _get_executable_info(self, executable: str) -> tuple[str, Version]:
from poetry.core.semver.version import Version
from poetry.utils._compat import list_to_shell_command
from poetry.core.constraints.version import Version

try:
python_version = Version.parse(executable)
Expand All @@ -227,17 +228,14 @@ def _get_executable_info(self, executable: str) -> tuple[str, Version]:

try:
python_version_str = subprocess.check_output(
list_to_shell_command(
[
executable,
"-c",
(
"\"import sys; print('.'.join([str(s) for s in"
' sys.version_info[:3]]))"'
),
]
),
shell=True,
[
executable,
"-c",
(
"import sys; print('.'.join([str(s) for s in"
" sys.version_info[:3]]))"
),
]
).decode()
except CalledProcessError as e:
from poetry.utils.env import EnvCommandError
Expand Down
3 changes: 2 additions & 1 deletion src/poetry_plugin_bundle/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ def commands(self) -> list[type[Command]]:
return [BundleVenvCommand]

def activate(self, application: Application) -> None:
assert application.event_dispatcher
application.event_dispatcher.add_listener(
COMMAND, self.configure_bundle_commands
COMMAND, self.configure_bundle_commands # type: ignore[arg-type]
)
super().activate(application=application)

Expand Down
8 changes: 4 additions & 4 deletions tests/bundlers/test_venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from poetry.core.packages.package import Package
from poetry.factory import Factory
from poetry.puzzle.exceptions import SolverProblemError
from poetry.repositories.pool import Pool
from poetry.repositories.repository import Repository
from poetry.repositories.repository_pool import RepositoryPool

from poetry_plugin_bundle.bundlers.venv_bundler import VenvBundler

Expand Down Expand Up @@ -43,7 +43,7 @@ def poetry(config: Config) -> Poetry:
)
poetry.set_config(config)

pool = Pool()
pool = RepositoryPool()
repository = Repository("repo")
repository.add_package(Package("foo", "1.0.0"))
pool.add_repository(repository)
Expand Down Expand Up @@ -196,7 +196,7 @@ def test_bundler_should_display_a_warning_for_projects_with_no_module(
)
poetry.set_config(config)

pool = Pool()
pool = RepositoryPool()
repository = Repository("repo")
repository.add_package(Package("foo", "1.0.0"))
pool.add_repository(repository)
Expand Down Expand Up @@ -235,7 +235,7 @@ def test_bundler_can_filter_dependency_groups(
# foo is in the main dependency group
# bar is a dev dependency
# add a repository for foo but not bar
pool = Pool()
pool = RepositoryPool()
repository = Repository("repo")
repository.add_package(Package("foo", "1.0.0"))
pool.add_repository(repository)
Expand Down
3 changes: 3 additions & 0 deletions tests/console/commands/bundle/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from pathlib import Path
from typing import TYPE_CHECKING

from poetry.console.application import Application

from poetry_plugin_bundle.bundlers.venv_bundler import VenvBundler


Expand Down Expand Up @@ -32,6 +34,7 @@ def test_venv_calls_venv_bundler(
assert app_tester.execute("bundle venv /foo --only dev") == 1
assert app_tester.execute("bundle venv /foo --without main --with dev") == 1

assert isinstance(app_tester.application, Application)
assert [
mocker.call(app_tester.application.poetry, mocker.ANY),
mocker.call(app_tester.application.poetry, mocker.ANY),
Expand Down
2 changes: 1 addition & 1 deletion tests/console/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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.path, p.locker._local_config))
p.set_locker(TestLocker(p.locker.lock, p.locker._local_config))

return p

Expand Down
8 changes: 2 additions & 6 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Any

from poetry.console.application import Application
from poetry.core.toml.file import TOMLFile
from poetry.factory import Factory
from poetry.packages import Locker

Expand All @@ -28,16 +27,13 @@ def reset_poetry(self) -> None:
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)
TestLocker(poetry.locker.lock, 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

Expand Down