PEP 641: Use an underscore in the version portion of Python 3.10 compatibility tag

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1891840
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1899553
This commit is contained in:
Miro Hrončok 2020-11-24 12:54:54 +01:00
commit 3c38aad354
2 changed files with 85 additions and 1 deletions

76
354.patch Normal file
View file

@ -0,0 +1,76 @@
From 6f862cdf60fec2f58796d2d8dcf891cc55721504 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Tue, 24 Nov 2020 12:03:14 +0100
Subject: [PATCH] PEP 641: Use an underscore in the version portion of Python
3.10 compatibility tag
Regardless of the py_version_nodot variable.
See https://www.python.org/dev/peps/pep-0641/
See https://github.com/python/cpython/pull/22858#issuecomment-720608651
---
packaging/tags.py | 13 ++++++-------
tests/test_tags.py | 25 +++++++------------------
2 files changed, 13 insertions(+), 25 deletions(-)
diff --git a/packaging/tags.py b/packaging/tags.py
index 289ed5c..8e695c7 100644
--- a/packaging/tags.py
+++ b/packaging/tags.py
@@ -782,14 +782,13 @@ def interpreter_name():
def interpreter_version(**kwargs):
# type: (bool) -> str
"""
- Returns the version of the running interpreter.
+ Returns the version of the running interpreter for the wheel tag.
+
+ See https://www.python.org/dev/peps/pep-0641/
"""
- warn = _warn_keyword_parameter("interpreter_version", kwargs)
- version = _get_config_var("py_version_nodot", warn=warn)
- if version:
- version = str(version)
- else:
- version = _version_nodot(sys.version_info[:2])
+ # warn kw only parameter is unused, kept for backwards compatibility
+ _warn_keyword_parameter("interpreter_version", kwargs)
+ version = _version_nodot(sys.version_info[:2])
return version
diff --git a/tests/test_tags.py b/tests/test_tags.py
index e9ea334..13121b3 100644
--- a/tests/test_tags.py
+++ b/tests/test_tags.py
@@ -172,24 +172,13 @@ def test_interpreter_short_names(self, mock_interpreter_name, monkeypatch):
class TestInterpreterVersion:
- def test_warn(self, monkeypatch):
- class MockConfigVar(object):
- def __init__(self, return_):
- self.warn = None
- self._return = return_
-
- def __call__(self, name, warn):
- self.warn = warn
- return self._return
-
- mock_config_var = MockConfigVar("38")
- monkeypatch.setattr(tags, "_get_config_var", mock_config_var)
- tags.interpreter_version(warn=True)
- assert mock_config_var.warn
-
- def test_python_version_nodot(self, monkeypatch):
- monkeypatch.setattr(tags, "_get_config_var", lambda var, warn: "NN")
- assert tags.interpreter_version() == "NN"
+ def test_python_version_nodot_underscore(self, monkeypatch):
+ monkeypatch.setattr(sys, "version_info", (3, 20, 12))
+ assert tags.interpreter_version() == "3_20"
+
+ def test_python_version_nodot_no_underscore(self, monkeypatch):
+ monkeypatch.setattr(sys, "version_info", (3, 9, 12))
+ assert tags.interpreter_version() == "39"
@pytest.mark.parametrize(
"version_info,version_str",

View file

@ -8,7 +8,7 @@
Name: python-%{pypi_name}
Version: 20.4
Release: 3%{?dist}
Release: 4%{?dist}
Summary: Core utilities for Python packages
License: BSD or ASL 2.0
@ -19,6 +19,9 @@ BuildArch: noarch
# Remove dependency on six to make package lighter, backported from upstream
Patch1: %{url}/commit/39a70cce.patch
# PEP 641: Use an underscore in the version portion of Python 3.10 compatibility tag
Patch2: %{url}/pull/354.patch
BuildRequires: python%{python3_pkgversion}-devel
BuildRequires: pyproject-rpm-macros
@ -108,6 +111,11 @@ rm -rf html/_static/fonts/
%changelog
* Tue Nov 24 2020 Miro Hrončok <mhroncok@redhat.com> - 20.4-4
- PEP 641: Use an underscore in the version portion of Python 3.10 compatibility tag
- Resolves: rhbz#1891840
- Resolves: rhbz#1899553
* Fri Oct 02 2020 Miro Hrončok <mhroncok@redhat.com> - 20.4-3
- Drop the dependency on six to make the package lighter