Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_sysconfig():
# must not fail


@unittest.skipIf(sys.platform == "win32", "Windows does not use _sysconfigdata")
def test_platform_sysconfigdata():
import importlib
import sysconfig
Expand All @@ -57,3 +58,25 @@ def test_platform_sysconfigdata():
assert mod.build_time_vars["ABIFLAGS"] == sys.abiflags
assert mod.build_time_vars["INSTSONAME"] == mod.build_time_vars["LDLIBRARY"]
assert sys.abiflags in sysconfig.get_config_var("INCLUDEPY")


@unittest.skipUnless(sys.platform == "win32", "Windows-specific sysconfig behavior")
def test_windows_libpython_is_not_exposed():
import sysconfig
assert "LIBPYTHON" not in sysconfig.get_config_vars()


@unittest.skipUnless(sys.platform == "win32", "Windows-specific sysconfig behavior")
def test_windows_library_names():
import sysconfig
expected = f"python{sys.version_info.major}{sys.version_info.minor}.dll"
assert sysconfig.get_config_var("LIBRARY") == expected
assert sysconfig.get_config_var("LDLIBRARY") == expected


@unittest.skipUnless(sys.platform == "win32", "Windows-specific sys behavior")
def test_windows_platform_specific_sys_attributes():
assert not hasattr(sys, "abiflags")
assert not hasattr(sys, "getdlopenflags")
assert not hasattr(sys, "setdlopenflags")
assert not hasattr(sys, "windowsversion")
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ accepted by asctime(), mktime() and strftime(). May be considered as a
sys.version_info

Version information as a named tuple.""")),
PWindowsVersion("windowsversion", PTuple, newBuilder().publishInModule("sys").disallowInstantiation().slots(StructSequenceBuiltins.SLOTS).doc("""
PWindowsVersion("getwindowsversion", PTuple, newBuilder().moduleName("sys").disallowInstantiation().slots(StructSequenceBuiltins.SLOTS).doc("""
sys.getwindowsversion

Return info about the running version of Windows as a named tuple.""")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import static com.oracle.graal.python.PythonLanguage.RELEASE_SERIAL;
import static com.oracle.graal.python.PythonLanguage.T_GRAALPYTHON_ID;
import static com.oracle.graal.python.PythonLanguage.getPythonOS;
import static com.oracle.graal.python.annotations.PythonOS.PLATFORM_DARWIN;
import static com.oracle.graal.python.annotations.PythonOS.PLATFORM_LINUX;
import static com.oracle.graal.python.annotations.PythonOS.PLATFORM_WIN32;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.AttributeError;
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.DeprecationWarning;
Expand Down Expand Up @@ -513,7 +515,9 @@ public void initialize(Python3Core core) {
StructSequence.initType(core, THREAD_INFO_DESC);
StructSequence.initType(core, UNRAISABLEHOOK_ARGS_DESC);

addBuiltinConstant(T_ABIFLAGS, toTruffleStringUncached(PythonLanguage.GRAALPY_ABIFLAGS));
if (getPythonOS() != PLATFORM_WIN32) {
addBuiltinConstant(T_ABIFLAGS, toTruffleStringUncached(PythonLanguage.GRAALPY_ABIFLAGS));
}
addBuiltinConstant("byteorder", ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN ? T_LITTLE : T_BIG);
addBuiltinConstant("copyright", T_LICENSE);
addBuiltinConstant(T_MODULES, PFactory.createDict(language));
Expand Down Expand Up @@ -2399,7 +2403,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
}
}

@Builtin(name = "getdlopenflags")
@Builtin(name = "getdlopenflags", os = PLATFORM_LINUX)
@Builtin(name = "getdlopenflags", os = PLATFORM_DARWIN)
@GenerateNodeFactory
abstract static class GetDlopenFlags extends PythonBuiltinNode {
@Specialization
Expand All @@ -2408,7 +2413,8 @@ Object get() {
}
}

@Builtin(name = "setdlopenflags", minNumOfPositionalArgs = 1, parameterNames = {"flags"}, numOfPositionalOnlyArgs = 1)
@Builtin(name = "setdlopenflags", minNumOfPositionalArgs = 1, parameterNames = {"flags"}, numOfPositionalOnlyArgs = 1, os = PLATFORM_LINUX)
@Builtin(name = "setdlopenflags", minNumOfPositionalArgs = 1, parameterNames = {"flags"}, numOfPositionalOnlyArgs = 1, os = PLATFORM_DARWIN)
@ArgumentClinic(name = "flags", conversion = ClinicConversion.Int)
@GenerateNodeFactory
abstract static class SetDlopenFlags extends PythonUnaryClinicBuiltinNode {
Expand Down
6 changes: 4 additions & 2 deletions graalpython/graalpy-pyconfig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2024, Oracle and/or its affiliates.
# Copyright (c) 2024, 2026, Oracle and/or its affiliates.
#
# All rights reserved.
#
Expand Down Expand Up @@ -188,4 +188,6 @@ foreach(name IN LISTS GRAALPY_SYSCONFIG_STRING_NAMES)
endforeach()

configure_file("pyconfig_template.h" "pyconfig.h" @ONLY)
configure_file("_sysconfigdata_template.py" "${GRAALPY_SYSCONFIGDATA_NAME}.py" @ONLY)
if(NOT WIN32)
configure_file("_sysconfigdata_template.py" "${GRAALPY_SYSCONFIGDATA_NAME}.py" @ONLY)
endif()
11 changes: 6 additions & 5 deletions graalpython/lib-graalpython/modules/graalpy-config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2025, 2025, Oracle and/or its affiliates.
# Copyright (c) 2025, 2026, Oracle and/or its affiliates.
# Copyright (C) 1996-2025 Python Software Foundation
#
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
Expand Down Expand Up @@ -27,6 +27,7 @@ def exit_with_usage(code=1):

getvar = sysconfig.get_config_var
pyver = getvar('VERSION')
abiflags = getattr(sys, 'abiflags', '')

opt_flags = [flag for (flag, val) in opts]

Expand All @@ -44,18 +45,18 @@ def exit_with_usage(code=1):
flags = ['-I' + sysconfig.get_path('include'),
'-I' + sysconfig.get_path('platinclude')]
if opt == '--cflags':
flags.extend(getvar('CFLAGS').split())
flags.extend((getvar('CFLAGS') or '').split())
print(' '.join(flags))

elif opt in ('--libs', '--ldflags'):
libs = []
if '--embed' in opt_flags:
libs.append('-lpython' + pyver + sys.abiflags)
libs.append('-lpython' + pyver + abiflags)
else:
libpython = getvar('LIBPYTHON')
if libpython:
libs.append(libpython)
libs.extend(getvar('LIBS').split() + getvar('SYSLIBS').split())
libs.extend((getvar('LIBS') or '').split() + (getvar('SYSLIBS') or '').split())

# add the prefix/lib/pythonX.Y/config dir, but only if there is no
# shared library in prefix/lib/.
Expand All @@ -68,7 +69,7 @@ def exit_with_usage(code=1):
print(getvar('EXT_SUFFIX'))

elif opt == '--abiflags':
print(sys.abiflags)
print(abiflags)

elif opt == '--configdir':
print(getvar('LIBPL'))
15 changes: 7 additions & 8 deletions graalpython/lib-python/3/sysconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,10 @@ def _init_posix(vars):

def _init_non_posix(vars):
"""Initialize the module as appropriate for NT"""
# GraalPy change: init first with posix vars, because of the toolchain we use
_init_posix(vars)
# set basic install directories
import _winapi
# GraalPy change: add runtime toolchain vars without loading POSIX sysconfigdata
import _sysconfig
_sysconfig._update_posix_vars(vars)
# set basic install directories
vars['LIBDEST'] = get_path('stdlib')
vars['BINLIBDEST'] = get_path('platstdlib')
vars['INCLUDEPY'] = get_path('include')
Expand All @@ -385,10 +384,10 @@ def _init_non_posix(vars):
vars.update(_sysconfig.config_vars())

vars['LIBDIR'] = _safe_realpath(os.path.join(get_config_var('installed_base'), 'libs'))
if hasattr(sys, 'dllhandle'):
dllhandle = _winapi.GetModuleFileName(sys.dllhandle)
vars['LIBRARY'] = os.path.basename(_safe_realpath(dllhandle))
vars['LDLIBRARY'] = vars['LIBRARY']
# GraalPy change: expose the stable public DLL name. sys.dllhandle refers to
# the internal python-native.dll and is only initialized when ctypes is loaded.
vars['LIBRARY'] = f'python{_PY_VERSION_SHORT_NO_DOT}.dll'
vars['LDLIBRARY'] = vars['LIBRARY']
vars['EXE'] = '.exe'
vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT
vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable))
Expand Down
14 changes: 12 additions & 2 deletions mx.graalpython/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,19 @@
},
"results": [
"pyconfig.h",
"<graalpy_sysconfigdata>.py",
],
"os_arch": {
"windows": {
"<others>": {},
},
"<others>": {
"<others>": {
"results": [
"<graalpy_sysconfigdata>.py",
],
},
},
},
},

"com.oracle.graal.python.cext": {
Expand Down Expand Up @@ -1388,7 +1399,6 @@
"./META-INF/resources/<os>/<arch>/Lib/venv/scripts/nt/venvlauncher.exe": "dependency:python-venvlauncher",
"./META-INF/resources/<os>/<arch>/Lib/venv/scripts/nt/venvwlauncher.exe": "dependency:python-venvlauncher",
"./META-INF/resources/<os>/<arch>/include/": "dependency:graalpy-pyconfig/<os>-<arch>/<multitarget_libc_selection>/pyconfig.h",
"./META-INF/resources/<os>/<arch>/Lib/": "dependency:graalpy-pyconfig/<os>-<arch>/<multitarget_libc_selection>/<graalpy_sysconfigdata>.py",
},
},
},
Expand Down
Loading