Elffuss BraidHub

kikocis/auto-code-rover public

main · 8.5 KiBRawPermalink
1{
2 "task_id": "matplotlib__matplotlib-18869",
3 "setup_info": {
4 "repo_path": "/home/haifeng/projects/reverse-prompt/SWE-bench/testbed/matplotlib__matplotlib/setup_matplotlib__matplotlib__3.3",
5 "env_name": "setup_matplotlib__matplotlib__3.3",
6 "pre_install": [],
7 "install": "python -m pip install -e .",
8 "test_cmd": "pytest --no-header -rA --tb=no -p no:cacheprovider lib/matplotlib/tests/test_matplotlib.py"
9 },
10 "task_info": {
11 "instance_id": "matplotlib__matplotlib-18869",
12 "base_commit": "b7d05919865fc0c37a0164cf467d5d5513bd0ede",
13 "hints_text": "It seems that `__version_info__` is the way to go.\r\n\r\n### Prior art\r\n- There's no official specification for version tuples. [PEP 396 - Module Version Numbers](https://www.python.org/dev/peps/pep-0396/) only defines the string `__version__`.\r\n\r\n- Many projects don't bother with version tuples.\r\n\r\n- When they do, `__version_info__` seems to be a common thing:\r\n - [Stackoverflow discussion](https://stackoverflow.com/a/466694)\r\n - [PySide2](https://doc.qt.io/qtforpython-5.12/pysideversion.html#printing-project-and-qt-version) uses it.\r\n\r\n- Python itself has the string [sys.version](https://docs.python.org/3/library/sys.html#sys.version) and the (named)tuple [sys.version_info](https://docs.python.org/3/library/sys.html#sys.version_info). In analogy to that `__version_info__` next to `__version__` makes sense for packages.\r\n",
14 "created_at": "2020-11-01T23:18:42Z",
15 "test_patch": "diff --git a/lib/matplotlib/tests/test_matplotlib.py b/lib/matplotlib/tests/test_matplotlib.py\n--- a/lib/matplotlib/tests/test_matplotlib.py\n+++ b/lib/matplotlib/tests/test_matplotlib.py\n@@ -7,6 +7,16 @@\n import matplotlib\n \n \n+@pytest.mark.parametrize('version_str, version_tuple', [\n+ ('3.5.0', (3, 5, 0, 'final', 0)),\n+ ('3.5.0rc2', (3, 5, 0, 'candidate', 2)),\n+ ('3.5.0.dev820+g6768ef8c4c', (3, 5, 0, 'alpha', 820)),\n+ ('3.5.0.post820+g6768ef8c4c', (3, 5, 1, 'alpha', 820)),\n+])\n+def test_parse_to_version_info(version_str, version_tuple):\n+ assert matplotlib._parse_to_version_info(version_str) == version_tuple\n+\n+\n @pytest.mark.skipif(\n os.name == \"nt\", reason=\"chmod() doesn't work as is on Windows\")\n @pytest.mark.skipif(os.name != \"nt\" and os.geteuid() == 0,\n",
16 "repo": "matplotlib/matplotlib",
17 "problem_statement": "Add easily comparable version info to toplevel\n<!--\r\nWelcome! Thanks for thinking of a way to improve Matplotlib.\r\n\r\n\r\nBefore creating a new feature request please search the issues for relevant feature requests.\r\n-->\r\n\r\n### Problem\r\n\r\nCurrently matplotlib only exposes `__version__`. For quick version checks, exposing either a `version_info` tuple (which can be compared with other tuples) or a `LooseVersion` instance (which can be properly compared with other strings) would be a small usability improvement.\r\n\r\n(In practice I guess boring string comparisons will work just fine until we hit mpl 3.10 or 4.10 which is unlikely to happen soon, but that feels quite dirty :))\r\n<!--\r\nProvide a clear and concise description of the problem this feature will solve. \r\n\r\nFor example:\r\n* I'm always frustrated when [...] because [...]\r\n* I would like it if [...] happened when I [...] because [...]\r\n* Here is a sample image of what I am asking for [...]\r\n-->\r\n\r\n### Proposed Solution\r\n\r\nI guess I slightly prefer `LooseVersion`, but exposing just a `version_info` tuple is much more common in other packages (and perhaps simpler to understand). The hardest(?) part is probably just bikeshedding this point :-)\r\n<!-- Provide a clear and concise description of a way to accomplish what you want. For example:\r\n\r\n* Add an option so that when [...] [...] will happen\r\n -->\r\n\r\n### Additional context and prior art\r\n\r\n`version_info` is a pretty common thing (citation needed).\r\n<!-- Add any other context or screenshots about the feature request here. You can also include links to examples of other programs that have something similar to your request. For example:\r\n\r\n* Another project [...] solved this by [...]\r\n-->\r\n\n",
18 "version": "3.3",
19 "FAIL_TO_PASS": [
20 "lib/matplotlib/tests/test_matplotlib.py::test_parse_to_version_info[3.5.0-version_tuple0]",
21 "lib/matplotlib/tests/test_matplotlib.py::test_parse_to_version_info[3.5.0.dev820+g6768ef8c4c-version_tuple2]",
22 "lib/matplotlib/tests/test_matplotlib.py::test_parse_to_version_info[3.5.0.post820+g6768ef8c4c-version_tuple3]",
23 "lib/matplotlib/tests/test_matplotlib.py::test_parse_to_version_info[3.5.0rc2-version_tuple1]"
24 ],
25 "PASS_TO_PASS": [
26 "lib/matplotlib/tests/test_matplotlib.py::test_importable_with__OO",
27 "lib/matplotlib/tests/test_matplotlib.py::test_importable_with_no_home",
28 "lib/matplotlib/tests/test_matplotlib.py::test_tmpconfigdir_warning",
29 "lib/matplotlib/tests/test_matplotlib.py::test_use_doc_standard_backends"
30 ],
31 "environment_setup_commit": "28289122be81e0bc0a6ee0c4c5b7343a46ce2e4e",
32 "patch": "diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py\n--- a/lib/matplotlib/__init__.py\n+++ b/lib/matplotlib/__init__.py\n@@ -129,25 +129,60 @@\n year = 2007\n }\"\"\"\n \n+# modelled after sys.version_info\n+_VersionInfo = namedtuple('_VersionInfo',\n+ 'major, minor, micro, releaselevel, serial')\n \n-def __getattr__(name):\n- if name == \"__version__\":\n+\n+def _parse_to_version_info(version_str):\n+ \"\"\"\n+ Parse a version string to a namedtuple analogous to sys.version_info.\n+\n+ See:\n+ https://packaging.pypa.io/en/latest/version.html#packaging.version.parse\n+ https://docs.python.org/3/library/sys.html#sys.version_info\n+ \"\"\"\n+ v = parse_version(version_str)\n+ if v.pre is None and v.post is None and v.dev is None:\n+ return _VersionInfo(v.major, v.minor, v.micro, 'final', 0)\n+ elif v.dev is not None:\n+ return _VersionInfo(v.major, v.minor, v.micro, 'alpha', v.dev)\n+ elif v.pre is not None:\n+ releaselevel = {\n+ 'a': 'alpha',\n+ 'b': 'beta',\n+ 'rc': 'candidate'}.get(v.pre[0], 'alpha')\n+ return _VersionInfo(v.major, v.minor, v.micro, releaselevel, v.pre[1])\n+ else:\n+ # fallback for v.post: guess-next-dev scheme from setuptools_scm\n+ return _VersionInfo(v.major, v.minor, v.micro + 1, 'alpha', v.post)\n+\n+\n+def _get_version():\n+ \"\"\"Return the version string used for __version__.\"\"\"\n+ # Only shell out to a git subprocess if really needed, and not on a\n+ # shallow clone, such as those used by CI, as the latter would trigger\n+ # a warning from setuptools_scm.\n+ root = Path(__file__).resolve().parents[2]\n+ if (root / \".git\").exists() and not (root / \".git/shallow\").exists():\n import setuptools_scm\n+ return setuptools_scm.get_version(\n+ root=root,\n+ version_scheme=\"post-release\",\n+ local_scheme=\"node-and-date\",\n+ fallback_version=_version.version,\n+ )\n+ else: # Get the version from the _version.py setuptools_scm file.\n+ return _version.version\n+\n+\n+def __getattr__(name):\n+ if name in (\"__version__\", \"__version_info__\"):\n global __version__ # cache it.\n- # Only shell out to a git subprocess if really needed, and not on a\n- # shallow clone, such as those used by CI, as the latter would trigger\n- # a warning from setuptools_scm.\n- root = Path(__file__).resolve().parents[2]\n- if (root / \".git\").exists() and not (root / \".git/shallow\").exists():\n- __version__ = setuptools_scm.get_version(\n- root=root,\n- version_scheme=\"post-release\",\n- local_scheme=\"node-and-date\",\n- fallback_version=_version.version,\n- )\n- else: # Get the version from the _version.py setuptools_scm file.\n- __version__ = _version.version\n- return __version__\n+ __version__ = _get_version()\n+ global __version__info__ # cache it.\n+ __version_info__ = _parse_to_version_info(__version__)\n+ return __version__ if name == \"__version__\" else __version_info__\n raise AttributeError(f\"module {__name__!r} has no attribute {name!r}\")\n \n \n",
33 "pr_link": "https://github.com/matplotlib/matplotlib/pull/18869"
34 }
35}