Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: improvements to pythran-config for build system integration #2270

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed __PYTHRAN__ in 075cefc

"-DENABLE_PYTHON_MODULE",
"-DPYTHRAN_BLAS_NONE",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that this blas flag is the one you need for scipy, but it should really depend on current config.

You mentioned

I considered adding --config compiler.blas=none|openblas support, but that then also has to interact with --cflags etc., so it's not clear that that works well for inclusion in 0.17.1 - and this can be added later.

In the gommit message but I think that's fine, it should just be also forwaded to extension = pythran.config.make_extension(python=args.python) below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay thanks, I'll see if I can figure out how to introduce this now then.

]
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