Skip to content

Commit

Permalink
📦🧪 Move Cython translation in CI to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz committed Nov 27, 2023
1 parent 8ba2714 commit f86fcd7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions packaging/pep517_backend/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys

from . import cli

if __name__ == "__main__":
sys.exit(cli.run_main_program(argv=sys.argv))
53 changes: 53 additions & 0 deletions packaging/pep517_backend/cli.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit f86fcd7

Please sign in to comment.