Skip to content

Commit a7eb65e

Browse files
committed
📦 Implement PEP 517 setting for in-place builds
Refs: * aio-libs/frozenlist#577 * #1551
1 parent ee03bb7 commit a7eb65e

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

‎packaging/pep517_backend/_backend.py‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@
9494
PURE_PYTHON_CONFIG_SETTING = 'pure-python'
9595
"""Config setting name toggle that is used to opt out of making C-exts."""
9696

97+
BUILD_INPLACE_CONFIG_SETTING = 'build-inplace' # noqa: WPS462
98+
"""
99+
Config setting name toggle building C-exts in-place.
100+
""" # noqa: WPS322
101+
102+
BUILD_INPLACE_ENV_VAR = 'YARL_BUILD_INPLACE'
103+
"""
104+
Environment variable name toggle building C-exts in-place.
105+
""" # noqa: WPS322
106+
97107
PURE_PYTHON_ENV_VAR = 'YARL_NO_EXTENSIONS'
98108
"""Environment variable name toggle used to opt out of making C-exts."""
99109

@@ -152,6 +162,19 @@ def _include_cython_line_tracing(
152162
)
153163

154164

165+
def _build_inplace(
166+
config_settings: _ConfigDict | None = None,
167+
*,
168+
default: bool = False,
169+
) -> bool:
170+
return _get_setting_value(
171+
config_settings,
172+
BUILD_INPLACE_CONFIG_SETTING,
173+
BUILD_INPLACE_ENV_VAR,
174+
default=default,
175+
)
176+
177+
155178
@contextmanager
156179
def patched_distutils_cmd_install() -> _c.Iterator[None]:
157180
"""Make `install_lib` of `install` cmd always use `platlib`.
@@ -316,6 +339,10 @@ def maybe_prebuild_c_extensions(
316339
f'* Mode: {"debug" if cython_line_tracing_requested else "release"} *',
317340
file=_standard_error_stream,
318341
)
342+
print( # noqa: T201, WPS421
343+
f'* Build location: {"in-tree" if build_inplace else "tmp dir"} *',
344+
file=_standard_error_stream,
345+
)
319346
print( # noqa: T201, WPS421
320347
'**********************',
321348
file=_standard_error_stream,
@@ -368,7 +395,7 @@ def build_wheel(
368395
"""
369396
with maybe_prebuild_c_extensions(
370397
line_trace_cython_when_unset=False,
371-
build_inplace=False,
398+
build_inplace=_build_inplace(config_settings, default=False),
372399
config_settings=config_settings,
373400
):
374401
return _setuptools_build_wheel(
@@ -393,9 +420,17 @@ def build_editable(
393420
:param metadata_directory: :file:`.dist-info` directory path.
394421
395422
"""
423+
mandatory_build_inplace = True
424+
if not _build_inplace(config_settings, default=mandatory_build_inplace):
425+
_warn_that(
426+
'Editable builds require C-extensions to be produced in-tree',
427+
RuntimeWarning,
428+
stacklevel=999,
429+
)
430+
396431
with maybe_prebuild_c_extensions(
397432
line_trace_cython_when_unset=True,
398-
build_inplace=True,
433+
build_inplace=mandatory_build_inplace,
399434
config_settings=config_settings,
400435
):
401436
return _setuptools_build_editable(

0 commit comments

Comments
 (0)