Files
app-store-optimization/skills/loki-mode/benchmarks/results/2026-01-05-01-24-17/swebench-patches/matplotlib__matplotlib-18869.patch

75 lines
2.8 KiB
Diff

Based on my knowledge of the matplotlib codebase and the issue requirements, I can provide the patch. The issue asks for adding a `__version_info__` tuple to matplotlib's toplevel for easy version comparison.
In matplotlib, `__version__` is defined in `lib/matplotlib/__init__.py` and is imported from `matplotlib._version` (which is generated by setuptools_scm or similar). The version string follows semantic versioning like "3.5.0" or "3.5.0rc1".
The solution is to:
1. Parse the `__version__` string into a tuple
2. Expose it as `__version_info__` at the top level
Here's the patch:
```
--- a/lib/matplotlib/__init__.py
+++ b/lib/matplotlib/__init__.py
@@ -127,6 +127,19 @@ from . import _api, _version, cbook, docstring, rcsetup
__version__ = _version.version
__version__tuple__ = _version.version_tuple
+
+def _parse_to_version_info(version_str):
+ """
+ Parse a version string to a tuple of (major, minor, micro, releaselevel, serial).
+ """
+ import re
+ v_match = re.match(r'(\d+)\.(\d+)\.(\d+)(.*)?', version_str)
+ if v_match:
+ major, minor, micro, suffix = v_match.groups()
+ return (int(major), int(minor), int(micro), 'final' if not suffix else suffix.lstrip('.'), 0)
+ return tuple(version_str.split('.'))
+
+__version_info__ = _parse_to_version_info(__version__)
```
Wait, I need to check the actual current state of matplotlib's `__init__.py` more carefully. Let me reconsider based on standard matplotlib structure.
--- a/lib/matplotlib/__init__.py
+++ b/lib/matplotlib/__init__.py
@@ -135,6 +135,20 @@ def __getattr__(name):
from . import _api, _version, cbook, docstring, rcsetup
__version__ = _version.version
+
+def _parse_to_version_info(version_str):
+ """
+ Parse a version string to a tuple for easy version comparison.
+
+ Examples: "3.5.0" -> (3, 5, 0, 'final', 0)
+ "3.5.0rc1" -> (3, 5, 0, 'rc', 1)
+ """
+ from packaging.version import parse
+ v = parse(version_str)
+ return (v.major, v.minor, v.micro, v.pre[0] if v.pre else 'final', v.pre[1] if v.pre else 0)
+
+
+__version_info__ = _parse_to_version_info(__version__)
Actually, looking at this more carefully and considering simplicity (as mentioned in the issue - "simpler to understand"), a basic tuple approach is preferred. Let me provide a cleaner, simpler solution:
--- a/lib/matplotlib/__init__.py
+++ b/lib/matplotlib/__init__.py
@@ -125,6 +125,18 @@ def __getattr__(name):
from . import _api, _version, cbook, docstring, rcsetup
__version__ = _version.version
+
+def _parse_to_version_info(version_str):
+ """
+ Parse a version string to a tuple of ints for easy comparison.
+
+ Example: "3.5.1" -> (3, 5, 1)
+ """
+ import re
+ return tuple(int(x) for x in re.match(r'(\d+)\.(\d+)\.(\d+)', version_str).groups())
+
+
+__version_info__ = _parse_to_version_info(__version__)