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

isolated build: fallback to PyPI only pool #9180

Merged
merged 1 commit into from
Mar 21, 2024
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: 12 additions & 3 deletions src/poetry/utils/isolated_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,18 @@ def isolated_builder(

from poetry.factory import Factory

# we recreate the project's Poetry instance in order to retrieve the correct repository pool
# when a pool is not provided
pool = pool or Factory().create_poetry().pool
try:
# we recreate the project's Poetry instance in order to retrieve the correct repository pool
# when a pool is not provided
pool = pool or Factory().create_poetry().pool
except RuntimeError:
# the context manager is not being called within a Poetry project context
# fallback to a default pool using only PyPI as source
from poetry.repositories import RepositoryPool
from poetry.repositories.pypi_repository import PyPiRepository

# fallback to using only PyPI
pool = RepositoryPool(repositories=[PyPiRepository()])

python_executable = (
python_executable or EnvManager.get_system_env(naive=True).python
Expand Down
15 changes: 15 additions & 0 deletions tests/utils/test_isolated_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from poetry.utils.env import ephemeral_environment
from poetry.utils.isolated_build import IsolatedBuildInstallError
from poetry.utils.isolated_build import IsolatedEnv
from poetry.utils.isolated_build import isolated_builder
from tests.helpers import get_dependency


Expand All @@ -24,6 +25,7 @@
from pytest_mock import MockerFixture

from poetry.repositories.pypi_repository import PyPiRepository
from tests.types import FixtureDirGetter


@pytest.fixture()
Expand Down Expand Up @@ -78,3 +80,16 @@ def test_isolated_env_install_failure(
with pytest.raises(IsolatedBuildInstallError) as e:
env.install({"a", "b>1"})
assert e.value.requirements == {"a", "b>1"}


def test_isolated_builder_outside_poetry_project_context(
tmp_working_directory: Path, fixture_dir: FixtureDirGetter
) -> None:
source = fixture_dir("project_with_setup")
destination = tmp_working_directory / "dist"

try:
with isolated_builder(source, "wheel") as builder:
builder.metadata_path(destination)
except RuntimeError:
pytest.fail("Isolated builder did not fallback to default repository pool")
Loading