Skip to content

Commit

Permalink
compilers: detect cython version on stdout for newer cython versions
Browse files Browse the repository at this point in the history
Cython historically, when asked to print the version and exit
successfully, would do so on stderr, which is weird and inconsistent.
Recently, it fixed this UX bug by printing on stdout instead:

cython/cython#5504

This then broke meson detection because we assumed it was on stderr due
to historically being there:

scipy/scipy#18865

Cython is right, and shouldn't have to revert this reasonable change for
backwards compatibility. Instead, check both.
  • Loading branch information
eli-schwartz committed Jul 12, 2023
1 parent 2c1e2b6 commit e2ce53b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions mesonbuild/compilers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,13 +927,19 @@ def detect_cython_compiler(env: 'Environment', for_machine: MachineChoice) -> Co
popen_exceptions: T.Dict[str, Exception] = {}
for comp in compilers:
try:
err = Popen_safe_logged(comp + ['-V'], msg='Detecting compiler via')[2]
_, out, err = Popen_safe_logged(comp + ['-V'], msg='Detecting compiler via')
except OSError as e:
popen_exceptions[join_args(comp + ['-V'])] = e
continue

version = search_version(err)
if 'Cython' in err:
version: T.Optional[str] = None
# 3.0
if 'Cython' in out:
version = search_version(out)
# older
elif 'Cython' in err:
version = search_version(err)
if version is not None:
comp_class = CythonCompiler
env.coredata.add_lang_args(comp_class.language, comp_class, for_machine, env)
return comp_class([], comp, version, for_machine, info, is_cross=is_cross)
Expand Down

0 comments on commit e2ce53b

Please sign in to comment.