diff --git a/.github/workflows/no-setuptools.yml b/.github/workflows/no-setuptools.yml index c2406a411..fd8c7a958 100644 --- a/.github/workflows/no-setuptools.yml +++ b/.github/workflows/no-setuptools.yml @@ -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 {} \; diff --git a/pythran/config.py b/pythran/config.py index 873da77d6..a588f7a6e 100644 --- a/pythran/config.py +++ b/pythran/config.py @@ -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', @@ -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') @@ -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 = [] @@ -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))