Skip to content

Commit

Permalink
ENH: improvements to pythran-config for build system integration
Browse files Browse the repository at this point in the history
xref issue 2257
  • Loading branch information
rgommers committed Dec 18, 2024
1 parent 092d09f commit 760501b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/no-setuptools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
run: |
python -m pip install .
python -m pip uninstall -y setuptools # the goal of that check is to test codegen without setuptools
- name: Testing pythran-config
run: |
pythran-config --cflags-pythran-only
- name: Testing scipy
run: |
find pythran/tests/scipy/ -name '*.py' -exec pythran -E {} \;
45 changes: 41 additions & 4 deletions pythran/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,7 @@ def run():
Dump on stdout the config flags required to compile pythran-generated code.
'''
import argparse
import distutils.ccompiler
import distutils.sysconfig
import pythran
import numpy

parser = argparse.ArgumentParser(
prog='pythran-config',
Expand All @@ -323,7 +320,24 @@ def run():
help='print default compiler')

parser.add_argument('--cflags', action='store_true',
help='print compilation flags')
help='print compilation flags to compile extension '
'modules directly')

# The with-BLAS variant could be added if there's user demand. Unclear
# if there are packages that need this, and also integrate with a build
# system for Python and NumPy flags. SciPy and scikit-image need the
# no-BLAS variant.
parser.add_argument('--cflags-pythran-only', action='store_true',
help='print compilation flags for usage by a build '
'system (doesn\'t include Python, NumPy or BLAS '
'flags).'
)

parser.add_argument('--include-dir', action='store_true',
help=(
'print Pythran include directory '
'(matches `pythran.get_include()`).')
)

parser.add_argument('--libs', action='store_true',
help='print linker flags')
Expand All @@ -344,6 +358,26 @@ def run():

args = parser.parse_args(sys.argv[1:])

# This should not rely on distutils/setuptools, or anything else not in the
# stdlib. Please don't add imports higher up.
if args.cflags_pythran_only:
if args.cflags:
print("Error: --cflags and --cflags-pythran-only are mutually "
"exclusive, please use only one.")

compile_flags = [
"-D__PYTHRAN__=3",
"-DENABLE_PYTHON_MODULE",
"-DPYTHRAN_BLAS_NONE",
]
print(" ".join(compile_flags), f"-I{get_include()}")
return None


import distutils.ccompiler
import distutils.sysconfig
import numpy

args.python = not args.no_python

output = []
Expand Down Expand Up @@ -411,6 +445,9 @@ def fmt_define(define):
if args.libs:
output.extend(ldflags)

if args.include_dir:
output.append(get_include())

if output:
print(' '.join(output))

Expand Down

0 comments on commit 760501b

Please sign in to comment.