-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📦🧪 Move Cython translation in CI to backend
- Loading branch information
Showing
3 changed files
with
64 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |