Skip to content

Commit

Permalink
pythongh-102491: Remove IronPython version check in sys_version (pyth…
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt authored and warsaw committed Apr 11, 2023
1 parent 519df22 commit 2220c9d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 51 deletions.
35 changes: 1 addition & 34 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,20 +1040,6 @@ def processor():
r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"
r'\[([^\]]+)\]?', re.ASCII) # "[compiler]"

_ironpython_sys_version_parser = re.compile(
r'IronPython\s*'
r'([\d\.]+)'
r'(?: \(([\d\.]+)\))?'
r' on (.NET [\d\.]+)', re.ASCII)

# IronPython covering 2.6 and 2.7
_ironpython26_sys_version_parser = re.compile(
r'([\d.]+)\s*'
r'\(IronPython\s*'
r'[\d.]+\s*'
r'\(([\d.]+)\) on ([\w.]+ [\d.]+(?: \(\d+-bit\))?)\)'
)

_pypy_sys_version_parser = re.compile(
r'([\w.+]+)\s*'
r'\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'
Expand Down Expand Up @@ -1090,25 +1076,7 @@ def _sys_version(sys_version=None):
if result is not None:
return result

# Parse it
if 'IronPython' in sys_version:
# IronPython
name = 'IronPython'
if sys_version.startswith('IronPython'):
match = _ironpython_sys_version_parser.match(sys_version)
else:
match = _ironpython26_sys_version_parser.match(sys_version)

if match is None:
raise ValueError(
'failed to parse IronPython sys.version: %s' %
repr(sys_version))

version, alt_version, compiler = match.groups()
buildno = ''
builddate = ''

elif sys.platform.startswith('java'):
if sys.platform.startswith('java'):
# Jython
name = 'Jython'
match = _sys_version_parser.match(sys_version)
Expand Down Expand Up @@ -1171,7 +1139,6 @@ def python_implementation():
Currently, the following implementations are identified:
'CPython' (C implementation of Python),
'IronPython' (.NET implementation of Python),
'Jython' (Java implementation of Python),
'PyPy' (Python implementation of Python).
Expand Down
24 changes: 7 additions & 17 deletions Lib/test/test_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ def test_sys_version(self):
for input, output in (
('2.4.3 (#1, Jun 21 2006, 13:54:21) \n[GCC 3.3.4 (pre 3.3.5 20040809)]',
('CPython', '2.4.3', '', '', '1', 'Jun 21 2006 13:54:21', 'GCC 3.3.4 (pre 3.3.5 20040809)')),
('IronPython 1.0.60816 on .NET 2.0.50727.42',
('IronPython', '1.0.60816', '', '', '', '', '.NET 2.0.50727.42')),
('IronPython 1.0 (1.0.61005.1977) on .NET 2.0.50727.42',
('IronPython', '1.0.0', '', '', '', '', '.NET 2.0.50727.42')),
('2.4.3 (truncation, date, t) \n[GCC]',
('CPython', '2.4.3', '', '', 'truncation', 'date t', 'GCC')),
('2.4.3 (truncation, date, ) \n[GCC]',
Expand Down Expand Up @@ -161,20 +157,11 @@ def test_sys_version(self):
('r261:67515', 'Dec 6 2008 15:26:00'),
'GCC 4.0.1 (Apple Computer, Inc. build 5370)'),

("IronPython 2.0 (2.0.0.0) on .NET 2.0.50727.3053", None, "cli")
("3.10.8 (tags/v3.10.8:aaaf517424, Feb 14 2023, 16:28:12) [GCC 9.4.0]",
None, "linux")
:
("IronPython", "2.0.0", "", "", ("", ""),
".NET 2.0.50727.3053"),

("2.6.1 (IronPython 2.6.1 (2.6.10920.0) on .NET 2.0.50727.1433)", None, "cli")
:
("IronPython", "2.6.1", "", "", ("", ""),
".NET 2.0.50727.1433"),

("2.7.4 (IronPython 2.7.4 (2.7.0.40) on Mono 4.0.30319.1 (32-bit))", None, "cli")
:
("IronPython", "2.7.4", "", "", ("", ""),
"Mono 4.0.30319.1 (32-bit)"),
('CPython', '3.10.8', '', '',
('tags/v3.10.8:aaaf517424', 'Feb 14 2023 16:28:12'), 'GCC 9.4.0'),

("2.5 (trunk:6107, Mar 26 2009, 13:02:18) \n[Java HotSpot(TM) Client VM (\"Apple Computer, Inc.\")]",
('Jython', 'trunk', '6107'), "java1.5.0_16")
Expand Down Expand Up @@ -205,6 +192,9 @@ def test_sys_version(self):
self.assertEqual(platform.python_build(), info[4])
self.assertEqual(platform.python_compiler(), info[5])

with self.assertRaises(ValueError):
platform._sys_version('2. 4.3 (truncation) \n[GCC]')

def test_system_alias(self):
res = platform.system_alias(
platform.system(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve import time of ``platform`` by removing IronPython version parsing. The IronPython version parsing
was not functional (see https://github.com/IronLanguages/ironpython3/issues/1667).

0 comments on commit 2220c9d

Please sign in to comment.