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

Solicit isolation setting from the environment. #766

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 5 additions & 2 deletions src/build/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import os
import pathlib
import tempfile

Expand All @@ -21,7 +22,7 @@ def _project_wheel_metadata(builder: ProjectBuilder) -> importlib.metadata.Packa

def project_wheel_metadata(
source_dir: StrPath,
isolated: bool = True,
isolated: bool = os.environ.get('BUILD_ENVIRONMENT', 'isolated') == 'isolated',
*,
runner: SubprocessRunner = pyproject_hooks.quiet_subprocess_runner,
) -> importlib.metadata.PackageMetadata:
Expand All @@ -34,7 +35,9 @@ def project_wheel_metadata(
:param source_dir: Project source directory
:param isolated: Whether or not to run invoke the backend in the current
environment or to create an isolated one and invoke it
there.
there. Defaults to True (isolated), but with
``BUILD_ENVIRONMENT=current`` set, the default
is False.
:param runner: An alternative runner for backend subprocesses
"""

Expand Down
10 changes: 10 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SPDX-License-Identifier: MIT

import importlib.util
import sys
import subprocess

import pytest

Expand Down Expand Up @@ -47,3 +49,11 @@ def test_with_get_requires(package_test_metadata):
assert str(metadata['version']) == '1.0.0'
assert metadata['summary'] == 'hello!'
assert isinstance(metadata.json, dict)


def test_current_environment_default():
check_script = "import build.util, inspect; print(inspect.signature(build.util.project_wheel_metadata).parameters['isolated'].default)"
cmd = [sys.executable, '-c', check_script]
env = {'BUILD_ENVIRONMENT': 'current'}
res = subprocess.check_output(cmd, env=env, text=True, encoding='utf-8')
assert res.strip() == 'False'
Loading