Skip to content

Commit

Permalink
Fix retrocompatbility of numversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Apr 28, 2021
1 parent 28c093c commit ce9c90f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
27 changes: 25 additions & 2 deletions pylint/__pkginfo__.py
@@ -1,5 +1,6 @@
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/master/LICENSE
from typing import Tuple

from pkg_resources import DistributionNotFound, get_distribution

Expand All @@ -8,5 +9,27 @@
except DistributionNotFound:
__version__ = "2.8.2+"

# Kept for compatibility reason, see https://github.com/PyCQA/pylint/issues/4399
numversion = tuple(__version__.split("."))

def get_numversion_from_version(v: str) -> Tuple:
"""Kept for compatibility reason
See https://github.com/PyCQA/pylint/issues/4399
https://github.com/PyCQA/pylint/issues/4420,
"""
v = v.replace("pylint-", "")
version = []
for n in v.split(".")[0:3]:
try:
version.append(int(n))
except ValueError:
num = ""
for c in n:
if c.isdigit():
num += c
else:
break
version.append(int(num))
return tuple(version)


numversion = get_numversion_from_version(__version__)
23 changes: 23 additions & 0 deletions tests/test_numversion.py
@@ -0,0 +1,23 @@
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/master/LICENSE

import pytest

from pylint.__pkginfo__ import get_numversion_from_version


@pytest.mark.parametrize(
"version,expected_numversion",
[
["2.8.1", (2, 8, 1)],
["2.8.2+", (2, 8, 2)],
["3.0.0a0", (3, 0, 0)],
["3.0.0b1", (3, 0, 0)],
["3.0.0rc1", (3, 0, 0)],
["3.0.0dev-234324234234f23abc4", (3, 0, 0)],
["pylint-2.4.7", (2, 4, 7)],
["2.8.3.dev3+g28c093c2.d20210428", (2, 8, 3)],
],
)
def test_numversion(version, expected_numversion):
assert get_numversion_from_version(version) == expected_numversion

0 comments on commit ce9c90f

Please sign in to comment.