Skip to content

Commit d63f425

Browse files
committed
remove os.uname from windows, implement the apis used in platform.py instead
1 parent 81ae6d0 commit d63f425

File tree

7 files changed

+96
-7
lines changed

7 files changed

+96
-7
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_tagged_unittests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class TestTaggedUnittests(unittest.TestCase):
182182
working_tests = [x for x in working_tests if x[0] in selection]
183183

184184
this_os = sys.platform
185-
this_machine = os.uname().machine
185+
this_machine = os.uname().machine if hasattr(os, "uname") else ""
186186
for idx, working_test in enumerate(working_tests):
187187
if os.environ.get("CI", None) and any(
188188
(os is None or os in this_os)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ public enum PythonBuiltinClassType implements TruffleObject {
332332
PStructPasswd("struct_passwd", "pwd", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
333333
PStructRusage("struct_rusage", "resource", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
334334
PVersionInfo("version_info", "sys", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
335+
PWindowsVersion("getwindowsversion", "sys", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
335336
PFlags("flags", "sys", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
336337
PFloatInfo("float_info", "sys", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
337338
PIntInfo("int_info", "sys", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
@@ -810,6 +811,7 @@ public final Shape getInstanceShape(PythonLanguage lang) {
810811
PStatvfsResult.redefinedSlots = repr;
811812
PFloatInfo.redefinedSlots = reprAndNew;
812813
PVersionInfo.redefinedSlots = repr;
814+
PWindowsVersion.redefinedSlots = repr;
813815
PFlags.redefinedSlots = repr;
814816
PTerminalSize.redefinedSlots = reprAndNew;
815817

@@ -920,6 +922,7 @@ public final Shape getInstanceShape(PythonLanguage lang) {
920922
PStructPasswd.base = PTuple;
921923
PStructRusage.base = PTuple;
922924
PVersionInfo.base = PTuple;
925+
PWindowsVersion.base = PTuple;
923926
PFlags.base = PTuple;
924927
PFloatInfo.base = PTuple;
925928
PIntInfo.base = PTuple;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ public abstract static class GetLoadAvgNode extends PythonBuiltinNode {
645645

646646
/*
647647
* Return average recent system load information.
648-
*
648+
*
649649
* Return the number of processes in the system run queue averaged over the last 1, 5, and
650650
* 15 minutes as a tuple of three floats. Raises OSError if the load average was
651651
* unobtainable.
@@ -1517,7 +1517,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
15171517
}
15181518
}
15191519

1520-
@Builtin(name = "uname", minNumOfPositionalArgs = 0)
1520+
@Builtin(name = "uname", minNumOfPositionalArgs = 0, os = PythonOS.PLATFORM_LINUX)
1521+
@Builtin(name = "uname", minNumOfPositionalArgs = 0, os = PythonOS.PLATFORM_DARWIN)
15211522
@GenerateNodeFactory
15221523
abstract static class UnameNode extends PythonBuiltinNode {
15231524

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,27 @@ public final class SysModuleBuiltins extends PythonBuiltins {
302302
"'alpha', 'beta', 'candidate', or 'final'", "Serial release number"},
303303
false);
304304

305+
static final StructSequence.BuiltinTypeDescriptor WINDOWS_VER_DESC = new StructSequence.BuiltinTypeDescriptor(
306+
PythonBuiltinClassType.PWindowsVersion,
307+
// @formatter:off The formatter joins these lines making it less readable
308+
"sys.getwindowsversion\n" +
309+
"\n" +
310+
"Return info about the running version of Windows as a named tuple.",
311+
// @formatter:on
312+
5,
313+
new String[]{
314+
"major", "minor", "build",
315+
"platform", "service_pack",
316+
"service_pack_major", "service_pack_minor",
317+
"suite_mask", "product_type", "platform_version"},
318+
new String[]{
319+
"Major version number", "Minor version number", "Build number",
320+
"Operating system platform", "Latest Service Pack installed on the system",
321+
"Service Pack major version number", "Service Pack minor version number",
322+
"Bit mask identifying available product suites",
323+
"System product type", "Diagnostic version number"},
324+
false);
325+
305326
static final StructSequence.BuiltinTypeDescriptor FLAGS_DESC = new StructSequence.BuiltinTypeDescriptor(
306327
PythonBuiltinClassType.PFlags,
307328
// @formatter:off The formatter joins these lines making it less readable
@@ -499,6 +520,9 @@ protected static PSimpleNamespace makeImplementation(PythonObjectFactory factory
499520
@Override
500521
public void initialize(Python3Core core) {
501522
StructSequence.initType(core, VERSION_INFO_DESC);
523+
if (PythonOS.getPythonOS() == PLATFORM_WIN32) {
524+
StructSequence.initType(core, WINDOWS_VER_DESC);
525+
}
502526
StructSequence.initType(core, FLAGS_DESC);
503527
StructSequence.initType(core, FLOAT_INFO_DESC);
504528
StructSequence.initType(core, INT_INFO_DESC);
@@ -2012,4 +2036,52 @@ protected ArgumentClinicProvider getArgumentClinic() {
20122036
return SetDlopenFlagsClinicProviderGen.INSTANCE;
20132037
}
20142038
}
2039+
2040+
@Builtin(name = "getwindowsversion", minNumOfPositionalArgs = 0, os = PLATFORM_WIN32)
2041+
@GenerateNodeFactory
2042+
abstract static class Getwindowsversion extends PythonBuiltinNode {
2043+
static int[] CACHED_VERSION_INFO = null;
2044+
static int PLATFORM = 2;
2045+
2046+
@Specialization
2047+
PTuple getVersion(@Cached PythonObjectFactory factory) {
2048+
if (CACHED_VERSION_INFO == null) {
2049+
cacheVersion();
2050+
}
2051+
return factory.createStructSeq(WINDOWS_VER_DESC,
2052+
CACHED_VERSION_INFO[0], CACHED_VERSION_INFO[1], CACHED_VERSION_INFO[2],
2053+
PLATFORM, T_EMPTY_STRING, 0, 0, 0, 1,
2054+
factory.createTuple(CACHED_VERSION_INFO));
2055+
}
2056+
2057+
@TruffleBoundary
2058+
static void cacheVersion() {
2059+
String[] winvers = System.getProperty("os.version", "10.0.20000").split("\\.");
2060+
int major = 0;
2061+
int minor = 0;
2062+
int build = 0;
2063+
if (winvers.length > 0) {
2064+
try {
2065+
major = Integer.parseInt(winvers[0]);
2066+
} catch (NumberFormatException e) {
2067+
// use default
2068+
}
2069+
}
2070+
if (winvers.length > 1) {
2071+
try {
2072+
minor = Integer.parseInt(winvers[1]);
2073+
} catch (NumberFormatException e) {
2074+
// use default
2075+
}
2076+
}
2077+
if (winvers.length > 2) {
2078+
try {
2079+
build = Integer.parseInt(winvers[2]);
2080+
} catch (NumberFormatException e) {
2081+
// use default
2082+
}
2083+
}
2084+
CACHED_VERSION_INFO = new int[]{major, minor, build};
2085+
}
2086+
}
20152087
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WinregModuleBuiltins.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -86,7 +86,6 @@ public void initialize(Python3Core core) {
8686
// stubs to just have msvc9compiler import
8787
addBuiltinConstant("error", PNone.NONE);
8888
addBuiltinConstant("EnumValue", PNone.NONE);
89-
addBuiltinConstant("OpenKeyEx", PNone.NONE);
9089
}
9190

9291
@Builtin(name = "OpenKey", minNumOfPositionalArgs = 2, parameterNames = {"key", "sub_key", "reserved", "access"})
@@ -125,4 +124,16 @@ static Object enumKey(VirtualFrame frame, Object key, Object index,
125124
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, OSErrorEnum.ENOENT);
126125
}
127126
}
127+
128+
@Builtin(name = "OpenKeyEx", minNumOfPositionalArgs = 2, parameterNames = {"key", "index"})
129+
@GenerateNodeFactory
130+
public abstract static class OpenKeyExNode extends PythonBinaryBuiltinNode {
131+
@SuppressWarnings("unused")
132+
@Specialization
133+
static Object enumKey(VirtualFrame frame, Object key, Object index,
134+
@Bind("this") Node inliningTarget,
135+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
136+
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, OSErrorEnum.ENOENT);
137+
}
138+
}
128139
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2571,7 +2571,7 @@ private static int getBuiltinTypeItemsize(PythonBuiltinClassType cls) {
25712571
PIntInfo, PHashInfo, PThreadInfo, PUnraisableHookArgs, PIOBase, PFileIO, PBufferedIOBase,
25722572
PBufferedReader, PBufferedWriter, PBufferedRWPair, PBufferedRandom, PIncrementalNewlineDecoder,
25732573
PTextIOWrapper, CArgObject, CThunkObject, StgDict, Structure, Union, PyCPointer, PyCArray,
2574-
PyCData, SimpleCData, PyCFuncPtr, CField, DictRemover, StructParam -> 8;
2574+
PWindowsVersion, PyCData, SimpleCData, PyCFuncPtr, CField, DictRemover, StructParam -> 8;
25752575
case PythonClass -> 40;
25762576
default -> 0;
25772577
};

graalpython/lib-python/3/subprocess.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@
7272
except ModuleNotFoundError:
7373
_mswindows = False
7474
else:
75-
_mswindows = True
75+
# Truffle change
76+
# _mswindows = True
77+
_mswindows = False
7678

7779
# wasm32-emscripten and wasm32-wasi do not support processes
7880
_can_fork_exec = sys.platform not in {"emscripten", "wasi"}

0 commit comments

Comments
 (0)