| 2500 | String containing linker flags for library paths. |
| 2501 | ''' |
| 2502 | def __init__(self): |
| 2503 | |
| 2504 | # Experimental detection of python flags from sysconfig.*() instead of |
| 2505 | # python-config command. |
| 2506 | includes_, ldflags_ = sysconfig_python_flags() |
| 2507 | |
| 2508 | if pyodide(): |
| 2509 | _include_dir = os.environ[ 'PYO3_CROSS_INCLUDE_DIR'] |
| 2510 | _lib_dir = os.environ[ 'PYO3_CROSS_LIB_DIR'] |
| 2511 | self.includes = f'-I {_include_dir}' |
| 2512 | self.ldflags = f'-L {_lib_dir}' |
| 2513 | |
| 2514 | elif 0: |
| 2515 | |
| 2516 | self.includes = includes_ |
| 2517 | self.ldflags = ldflags_ |
| 2518 | |
| 2519 | elif windows(): |
| 2520 | wp = wdev.WindowsPython() |
| 2521 | self.includes = f'/I"{wp.include}"' |
| 2522 | self.ldflags = f'/LIBPATH:"{wp.libs}"' |
| 2523 | |
| 2524 | elif pyodide(): |
| 2525 | _include_dir = os.environ[ 'PYO3_CROSS_INCLUDE_DIR'] |
| 2526 | _lib_dir = os.environ[ 'PYO3_CROSS_LIB_DIR'] |
| 2527 | self.includes = f'-I {_include_dir}' |
| 2528 | self.ldflags = f'-L {_lib_dir}' |
| 2529 | |
| 2530 | else: |
| 2531 | python_config = os.environ.get("PIPCL_PYTHON_CONFIG") |
| 2532 | if not python_config: |
| 2533 | # We use python-config which appears to work better than pkg-config |
| 2534 | # because it copes with multiple installed python's, e.g. |
| 2535 | # manylinux_2014's /opt/python/cp*-cp*/bin/python*. |
| 2536 | # |
| 2537 | # But... on non-macos it seems that we should not attempt to specify |
| 2538 | # libpython on the link command. The manylinux docker containers |
| 2539 | # don't actually contain libpython.so, and it seems that this |
| 2540 | # deliberate. And the link command runs ok. |
| 2541 | # |
| 2542 | python_exe = os.path.realpath( sys.executable) |
| 2543 | if darwin(): |
| 2544 | # Basic install of dev tools with `xcode-select --install` doesn't |
| 2545 | # seem to provide a `python3-config` or similar, but there is a |
| 2546 | # `python-config.py` accessible via sysconfig. |
| 2547 | # |
| 2548 | # We try different possibilities and use the last one that |
| 2549 | # works. |
| 2550 | # |
| 2551 | python_config = None |
| 2552 | for pc in ( |
| 2553 | f'python3-config', |
| 2554 | f'{sys.executable} {sysconfig.get_config_var("srcdir")}/python-config.py', |
| 2555 | f'{python_exe}-config', |
| 2556 | ): |
| 2557 | e = subprocess.run( |
| 2558 | f'{pc} --includes', |
| 2559 | shell=1, |