Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IronPython parsing of sys.version #1667

Open
eendebakpt opened this issue Mar 9, 2023 · 4 comments
Open

IronPython parsing of sys.version #1667

eendebakpt opened this issue Mar 9, 2023 · 4 comments

Comments

@eendebakpt
Copy link

Description

In python/cpython#102492 the IronPyhon 2.x version parsing is removed. We are wondering whether the other regular expression parsing a version tag, e.g. https://github.com/python/cpython/pull/102492/files#diff-cb1ba6039236dca71c97ea898f2798c60262c30614192862259889f839e4d503L1043-L1048 is still correct and relevant for ironpython as there is a difference with the one in current ironpython git:

_ironpython_sys_version_parser = re.compile(

@slozier

@slozier
Copy link
Contributor

slozier commented Mar 9, 2023

@eendebakpt Thanks for checking! The regular expression currently in CPython is no longer correct for IronPython. In fact, even the check for IronPython further down in _sys_version would not work with the current sys.version. The latest 2.7 and 3.4 releases both use the format that's in the current repo:

2.7.12 (2.7.12.1000)
[.NETFramework,Version=v4.5 on .NET Framework 4.8.9139.0 (64-bit)]
3.4.0 (3.4.0.1000)
[.NETFramework,Version=v4.6.2 on .NET Framework 4.8.9139.0 (64-bit)]

The current diff with CPython is as follows:

 _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\))?)\)'
-)
+    r'([\w.+]+)\s*'  # "version<space>"
+    r'(?: DEBUG)?\s*' # DEBUG - IronPython DEBUG builds only
+    r'\(([^,]+)\)\s*'  # "(fileversion)<space>"
+    r'\[([^\]]+)\]?')  # "[compiler]"
-    if 'IronPython' in sys_version:
+    if sys.implementation.name == "ironpython":
         # 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)
-
+        match = _ironpython_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()
+        version, _, _ = match.groups()
         buildno = ''
         builddate = ''
+        compiler = ''

@eendebakpt
Copy link
Author

@eendebakpt Thanks for checking! The regular expression currently in CPython is no longer correct for IronPython. In fact, even the check for IronPython further down in _sys_version would not work with the current sys.version. The latest 2.7 and 3.4 releases both use the format that's in the current repo:

2.7.12 (2.7.12.1000)
[.NETFramework,Version=v4.5 on .NET Framework 4.8.9139.0 (64-bit)]
3.4.0 (3.4.0.1000)
[.NETFramework,Version=v4.6.2 on .NET Framework 4.8.9139.0 (64-bit)]

The current diff with CPython is as follows:

 _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\))?)\)'
-)
+    r'([\w.+]+)\s*'  # "version<space>"
+    r'(?: DEBUG)?\s*' # DEBUG - IronPython DEBUG builds only
+    r'\(([^,]+)\)\s*'  # "(fileversion)<space>"
+    r'\[([^\]]+)\]?')  # "[compiler]"
-    if 'IronPython' in sys_version:
+    if sys.implementation.name == "ironpython":
         # 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)
-
+        match = _ironpython_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()
+        version, _, _ = match.groups()
         buildno = ''
         builddate = ''
+        compiler = ''

@slozier Thanks for the info. Given the fact that the regular expressions in the current cpython main do not work, what should we do with the ironpython parsing in cpython? Three options: i) leave as it is, ii) remove the ironpython version parsing iii) update with the expressions above. Is ironpython still using the platform.py from current cpython repo (or expected to use in the near future)?

@slozier
Copy link
Contributor

slozier commented Mar 10, 2023

Three options: i) leave as it is, ii) remove the ironpython version parsing iii) update with the expressions above. Is ironpython still using the platform.py from current cpython repo (or expected to use in the near future)?

@eendebakpt While I would love to take option iii, given how far behind we are (ipy's stdlib is based off 3.4) I don't expect us to be using cpython's main any time soon (and things may change by the time we get there). So that leaves options i and ii. It seems to me like option i serves no one (other than requiring no additional effort). So option ii is probably best (as long as it doesn't close the door on getting ipy in there if we ever catch up).

@hauntsaninja
Copy link

Thanks, let's go with option 2 then. But I'm perfectly happy with option 3 if you want it and the door is always open — all you need to do is ask :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants