Skip to content

Commit 63c4461

Browse files
bdracowebknjaz
andauthored
Only enable line tracing when building with Cython tracing (#1521)
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
1 parent d1286db commit 63c4461

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

CHANGES/1521.packaging.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Made Cython line tracing opt-in via the ``with-cython-tracing`` build config setting -- by :user:`bdraco`.
2+
3+
Previously, line tracing was enabled by default in :file:`pyproject.toml`, which caused build issues for some users and made wheels nearly twice as slow.
4+
Now line tracing is only enabled when explicitly requested via ``pip install . --config-setting=with-cython-tracing=true`` or by setting the ``YARL_CYTHON_TRACING`` environment variable.

packaging/pep517_backend/_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def maybe_prebuild_c_extensions(
293293
with build_dir_ctx:
294294
config = _get_local_cython_config()
295295

296-
cythonize_args = _make_cythonize_cli_args_from_config(config)
296+
cythonize_args = _make_cythonize_cli_args_from_config(config, cython_line_tracing_requested)
297297
with _patched_cython_env(config['env'], cython_line_tracing_requested):
298298
_cythonize_cli_cmd(cythonize_args) # type: ignore[no-untyped-call]
299299
with patched_distutils_cmd_install():

packaging/pep517_backend/_cython_configuration.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class Config(TypedDict):
1919
env: dict[str, str]
2020
flags: dict[str, bool]
21-
kwargs: dict[str, str]
21+
kwargs: dict[str, str | dict[str, str]]
2222
src: list[str]
2323

2424

@@ -79,11 +79,25 @@ def get_local_cython_config() -> Config:
7979
return config_mapping['tool']['local']['cythonize'] # type: ignore[no-any-return]
8080

8181

82-
def make_cythonize_cli_args_from_config(config: Config) -> list[str]:
82+
def _configure_cython_line_tracing(config_kwargs: dict[str, str | dict[str, str]], cython_line_tracing_requested: bool) -> None:
83+
"""Configure Cython line tracing directives if requested."""
84+
# If line tracing is requested, add it to the directives
85+
if cython_line_tracing_requested:
86+
directives = config_kwargs.setdefault('directive', {})
87+
assert isinstance(directives, dict) # Type narrowing for mypy
88+
directives['linetrace'] = 'True'
89+
directives['profile'] = 'True'
90+
91+
92+
def make_cythonize_cli_args_from_config(config: Config, cython_line_tracing_requested: bool = False) -> list[str]:
8393
py_ver_arg = f'-{_python_version_tuple.major!s}'
8494

8595
cli_flags = get_enabled_cli_flags_from_config(config['flags'])
86-
cli_kwargs = get_cli_kwargs_from_config(config['kwargs'])
96+
config_kwargs = config['kwargs']
97+
98+
_configure_cython_line_tracing(config_kwargs, cython_line_tracing_requested)
99+
100+
cli_kwargs = get_cli_kwargs_from_config(config_kwargs)
87101

88102
return cli_flags + [py_ver_arg] + cli_kwargs + ['--'] + config['src']
89103

packaging/pep517_backend/_transformers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def _emit_opt_pairs(opt_pair: tuple[str, Union[dict[str, str], str]]) -> Iterato
1717
yield from ("=".join(map(str, (flag_opt,) + pair)) for pair in sub_pairs)
1818

1919

20-
def get_cli_kwargs_from_config(kwargs_map: dict[str, str]) -> list[str]:
20+
def get_cli_kwargs_from_config(
21+
kwargs_map: dict[str, Union[str, dict[str, str]]],
22+
) -> list[str]:
2123
"""Make a list of options with values from config."""
2224
return list(chain.from_iterable(map(_emit_opt_pairs, kwargs_map.items())))
2325

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ keep-going = false
4848
# https://cython.rtfd.io/en/latest/src/userguide/source_files_and_compilation.html#compiler-directives
4949
embedsignature = "True"
5050
emit_code_comments = "True"
51-
linetrace = "True" # Implies `profile=True`
5251

5352
[tool.local.cythonize.kwargs.compile-time-env]
5453
# This section can contain compile time env vars

0 commit comments

Comments
 (0)