Skip to content

Commit d3c3de3

Browse files
authored
sys.platform cleanup (#705)
1 parent 558c1cd commit d3c3de3

4 files changed

Lines changed: 24 additions & 24 deletions

File tree

Src/IronPython/Hosting/PythonCommandLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public PythonCommandLine() {
4343
/// because it is intended to be outputted through the Python I/O system.
4444
/// </summary>
4545
public static string GetLogoDisplay() {
46-
return "IronPython " + PythonContext.GetVersionString() +
46+
return "IronPython " + PythonContext.GetVersionString() + " on " + PythonContext.GetPlatform() +
4747
"\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n";
4848
}
4949

Src/IronPython/Lib/iptest/test_env.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,35 @@
22
# The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
# See the LICENSE file in the project root for more information.
44

5-
import sys, os
6-
#from iptest.util import get_env_var, get_temp_dir
5+
import os
6+
import sys
77

88
#------------------------------------------------------------------------------
99

1010
#--IronPython or something else?
11-
is_cli = sys.implementation.name == 'ironpython'
11+
is_cli = sys.implementation.name == 'ironpython'
1212
is_ironpython = is_cli
13-
is_cpython = not is_ironpython
13+
is_cpython = sys.implementation.name == 'cpython'
1414
is_windows = sys.platform == 'win32'
15-
is_posix = sys.platform == 'posix' or sys.platform == 'linux'
15+
is_linux = sys.platform == 'linux'
1616
is_osx = sys.platform == 'darwin'
17+
is_posix = is_linux or is_osx
18+
1719
is_netcoreapp = False
1820
is_netcoreapp21 = False
1921
is_netcoreapp30 = False
2022
is_mono = False
21-
2223
if is_ironpython:
23-
#We'll use System, if available, to figure out more info on the test
24-
#environment later
25-
import System
2624
import clr
2725
is_netcoreapp = clr.IsNetCoreApp
2826
is_netcoreapp21 = clr.TargetFramework == ".NETCoreApp,Version=v2.1"
2927
is_netcoreapp30 = clr.TargetFramework == ".NETCoreApp,Version=v3.0"
30-
if is_netcoreapp: clr.AddReference("System.Runtime.Extensions")
31-
is_posix = sys.platform == 'posix' or System.Environment.OSVersion.Platform == System.PlatformID.Unix
32-
is_osx = os.path.exists('/System/Library/CoreServices/SystemVersion.plist')
3328
is_mono = clr.IsMono
3429

3530
#--The bittedness of the Python implementation
3631
is_cli32, is_cli64 = False, False
3732
if is_ironpython:
33+
import System
3834
is_cli32, is_cli64 = (System.IntPtr.Size == 4), (System.IntPtr.Size == 8)
3935

4036
is_32, is_64 = is_cli32, is_cli64
@@ -50,6 +46,7 @@
5046
is_net45Or46 = False
5147
is_net46 = False
5248
if is_cli:
49+
if is_netcoreapp: clr.AddReference("System.Runtime.Extensions")
5350
version = System.Environment.Version
5451
is_net40 = version.Major == 4
5552
is_net45 = is_net40 and version.Minor == 0 and version.Build == 30319 and version.Revision < 42000
@@ -60,7 +57,6 @@
6057
if is_ironpython:
6158
newline = System.Environment.NewLine
6259
else:
63-
import os
6460
newline = os.linesep
6561

6662
#--Build flavor of Python being tested

Src/IronPython/Modules/sys.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -558,16 +558,8 @@ public static void PerformModuleReload(PythonContext/*!*/ context, PythonDiction
558558
dict["stdin"] = dict["__stdin__"];
559559
dict["stdout"] = dict["__stdout__"];
560560
dict["stderr"] = dict["__stderr__"];
561-
562-
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
563-
dict["platform"] = "win32";
564-
} else if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
565-
dict["platform"] = "posix";
566-
} else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
567-
dict["platform"] = "darwin";
568-
} else {
569-
dict["platform"] = "cli";
570-
}
561+
562+
dict["platform"] = PythonContext.GetPlatform();
571563

572564
// !!! These fields do need to be reset on "reload(sys)". However, the initial value is specified by the
573565
// engine elsewhere. For now, we initialize them just once to some default value

Src/IronPython/Runtime/PythonContext.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,18 @@ private void SetVersionVariables(PythonDictionary dict) {
17821782
dict["version"] = _initialVersionString ?? GetVersionString();
17831783
}
17841784

1785+
internal static string GetPlatform() {
1786+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
1787+
return "win32";
1788+
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
1789+
return "linux";
1790+
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
1791+
return "darwin";
1792+
} else {
1793+
return "cli";
1794+
}
1795+
}
1796+
17851797
internal static string GetVersionString() {
17861798
string configuration = Runtime.ClrModule.IsDebug ? " DEBUG" : string.Empty;
17871799
string bitness = (IntPtr.Size * 8).ToString();

0 commit comments

Comments
 (0)