Skip to content

Commit ffa4740

Browse files
committed
ci: get rid of pkg_resources use
1 parent 08022e8 commit ffa4740

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

.github/scripts/populate_py2_overlays.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,24 @@
33
import sys
44

55
import frontmatter
6-
import pkg_resources
76
import yaml
7+
from packaging.specifiers import SpecifierSet
8+
from packaging.version import Version
9+
from packaging.version import parse as parse_version
10+
11+
12+
def parse_specifier(specifier: str) -> SpecifierSet:
13+
return SpecifierSet(specifier)
14+
15+
16+
def is_version_compatible(version, specifier):
17+
if not isinstance(version, Version):
18+
version = parse_version(version)
19+
20+
if not isinstance(specifier, SpecifierSet):
21+
specifier = parse_specifier(specifier)
22+
23+
return version in specifier
824

925

1026
def process_plugin_file(path):
@@ -22,8 +38,7 @@ def out(line, prefix="", *args, **kwargs):
2238

2339
if data.get("compatibility", {}).get("python"):
2440
pycompat = data["compatibility"]["python"]
25-
s = pkg_resources.Requirement.parse("Python" + pycompat)
26-
if "2.7" not in s:
41+
if not is_version_compatible("2.7", pycompat):
2742
out(
2843
"Plugin {} is not Python 2 compatible, disable update checks in the field".format(
2944
plugin_id

0 commit comments

Comments
 (0)