diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 96a5a77d6..d3616c2b7 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -219,15 +219,13 @@ jobs: github.event_name != 'push' || !contains(github.ref, 'refs/tags/') ) - run: > + env: + PYTHONPATH: packaging/ + run: | set -eEuo pipefail - - python -Im cython - -X linetrace=true - -X embedsignature=true - -X emit_code_comments=true - yarl/*.pyx + python -Im pip install expandvars + python -m pep517_backend.cli translate-cython shell: bash - name: Disable the Cython.Coverage Produce plugin if: >- # Only works if the dists were built with line tracing diff --git a/packaging/pep517_backend/__main__.py b/packaging/pep517_backend/__main__.py new file mode 100644 index 000000000..7ad33e74d --- /dev/null +++ b/packaging/pep517_backend/__main__.py @@ -0,0 +1,6 @@ +import sys + +from . import cli + +if __name__ == "__main__": + sys.exit(cli.run_main_program(argv=sys.argv)) diff --git a/packaging/pep517_backend/cli.py b/packaging/pep517_backend/cli.py new file mode 100644 index 000000000..f3a1c85cc --- /dev/null +++ b/packaging/pep517_backend/cli.py @@ -0,0 +1,53 @@ +# fmt: off + +from __future__ import annotations + +import sys +from itertools import chain +from pathlib import Path + +from Cython.Compiler.Main import compile as _translate_cython_cli_cmd +from Cython.Compiler.Main import parse_command_line as _split_cython_cli_args + +from ._cython_configuration import get_local_cython_config as _get_local_cython_config +from ._cython_configuration import ( + make_cythonize_cli_args_from_config as _make_cythonize_cli_args_from_config, +) +from ._cython_configuration import patched_env as _patched_cython_env + +_PROJECT_PATH = Path(__file__).parents[2] + + +def run_main_program(argv) -> int | str: + """Invoke ``translate-cython`` or fail.""" + if len(argv) != 2: + return 'This program only accepts one argument -- "translate-cython"' + + if argv[1] != 'translate-cython': + return 'This program only implements the "translate-cython" subcommand' + + config = _get_local_cython_config() + config['flags'] = {'keep-going': config['flags']['keep-going']} + config['src'] = list( + map( + str, + chain.from_iterable( + map(_PROJECT_PATH.glob, config['src']), + ), + ), + ) + translate_cython_cli_args = _make_cythonize_cli_args_from_config(config) + + cython_options, cython_sources = _split_cython_cli_args( + translate_cython_cli_args, + ) + + with _patched_cython_env(config['env'], cython_line_tracing_requested=True): + return _translate_cython_cli_cmd( + cython_sources, + cython_options, + ).num_errors + + +if __name__ == '__main__': + sys.exit(run_main_program(argv=sys.argv))