Last active
May 31, 2024 20:15
-
-
Save wallentx/a9e816e565f3d1be77d3cd263ffd42b7 to your computer and use it in GitHub Desktop.
Generates pyo3_config.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import os | |
import configparser | |
import sysconfig | |
# Function to detect the library directory | |
def detect_lib_dir(): | |
libdir = sysconfig.get_config_var('LIBDIR') | |
if libdir and os.path.exists(libdir): | |
return libdir | |
return os.path.dirname(sys.executable) | |
# Function to detect the library name | |
def detect_lib_name(): | |
libname = sysconfig.get_config_var('LDLIBRARY') | |
if libname: | |
# Strip the 'lib' prefix and the extension | |
return os.path.splitext(libname)[0][3:] | |
return 'python' + sys.version[:3].replace('.', '') | |
# Extract major.minor version | |
def get_major_minor_version(): | |
return '.'.join(sys.version.split(' ')[0].split('.')[:2]) | |
# Create a template configuration | |
template = { | |
'implementation': 'CPython', | |
'version': get_major_minor_version(), # Detecting major.minor Python version | |
'shared': 'true', # Assuming shared libraries are used | |
'abi3': 'true', # Assuming ABI3 is required | |
'build_flags': 'WITH_THREAD', # Assuming WITH_THREAD is needed | |
'suppress_build_script_link_lines': 'false', | |
'lib_dir': detect_lib_dir(), # Detecting library directory using sysconfig | |
'lib_name': detect_lib_name() # Detecting library name using sysconfig | |
} | |
# Write the configuration to the file | |
config_file = 'pyo3_config.txt' | |
with open(config_file, 'w') as configfile: | |
for key, value in template.items(): | |
configfile.write(f'{key}={value}\n') | |
print(f"Configuration written to {config_file}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output on termux:
From my server: