Skip to content

Commit 9201838

Browse files
authored
Fixed #973 updated min.py script with additional checks to scan files in … (#994)
* [#973] updated min.py script with additional checks to scan files in the Stumpy repo that list package versions and confirm those versions align with the minimum supported versions * [#973] updated min.py script with additional checks to scan files in the Stumpy repo that list package versions and confirm those versions align with the minimum supported versions * [#973] scoped function down and updated formatting of lines to be printed to console * [#973] updated get_min_scipy_version to set astype to string, and updated find_pkg_mismatches to print a newline for each mismatch noted * [#973] updated get_min_scipy_version to set astype to string, and updated find_pkg_mismatches to print a newline for each mismatch noted * [#973] refactored find_pkg_mismatches to return a tuple and updated display format in main * [#973] refactored find_pkg_mismatches to return a tuple and updated display format in main * [#973] refactored find_pkg_mismatches to return a tuple and updated display format in main
1 parent 75a9d21 commit 9201838

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

min.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

33
import argparse
4+
import re
45

56
import pandas as pd
67
from packaging.specifiers import SpecifierSet
@@ -85,7 +86,7 @@ def get_min_scipy_version(min_python, min_numpy):
8586
.replace({".x": ""}, regex=True)
8687
.pipe(
8788
lambda df: df.assign(
88-
SciPy_version=df.SciPy_version.str.replace(
89+
SciPy_version=df.SciPy_version.astype("str").str.replace(
8990
r"\d\/", "", regex=True # noqa
9091
)
9192
)
@@ -135,6 +136,33 @@ def get_min_scipy_version(min_python, min_numpy):
135136
return df.SciPy_version
136137

137138

139+
def find_pkg_mismatches(pkg_name, pkg_version, fnames):
140+
"""
141+
Determine if any package version has mismatches
142+
"""
143+
pkg_mismatches = []
144+
145+
for fname in fnames:
146+
with open(fname, "r") as file:
147+
for line_num, line in enumerate(file, start=1):
148+
l = line.strip().replace(" ", "").lower()
149+
matches = re.search(
150+
rf"""
151+
{pkg_name} # Package name
152+
[=><:"\'\[\]]+ # Zero or more special characters
153+
(\d+\.\d+[\.0-9]*) # Capture "version" in `matches`
154+
""",
155+
l,
156+
re.VERBOSE, # Ignores all whitespace in pattern
157+
)
158+
if matches is not None:
159+
version = matches.groups()[0]
160+
if version != pkg_version:
161+
pkg_mismatches.append((pkg_name, version, fname, line_num))
162+
163+
return pkg_mismatches
164+
165+
138166
if __name__ == "__main__":
139167
parser = argparse.ArgumentParser()
140168
parser.add_argument("min_python", nargs="?", default=None)
@@ -146,9 +174,35 @@ def get_min_scipy_version(min_python, min_numpy):
146174
MIN_PYTHON = get_min_python_version()
147175
MIN_NUMBA, MIN_NUMPY = get_min_numba_numpy_version(MIN_PYTHON)
148176
MIN_SCIPY = get_min_scipy_version(MIN_PYTHON, MIN_NUMPY)
177+
149178
print(
150179
f"python: {MIN_PYTHON}\n"
151180
f"numba: {MIN_NUMBA}\n"
152181
f"numpy: {MIN_NUMPY}\n"
153182
f"scipy: {MIN_SCIPY}"
154183
)
184+
185+
pkgs = {
186+
"numpy": MIN_NUMPY,
187+
"scipy": MIN_SCIPY,
188+
"numba": MIN_NUMBA,
189+
"python": MIN_PYTHON,
190+
"python-version": MIN_PYTHON,
191+
}
192+
193+
fnames = [
194+
"pyproject.toml",
195+
"requirements.txt",
196+
"environment.yml",
197+
".github/workflows/github-actions.yml",
198+
"README.rst",
199+
]
200+
201+
for pkg_name, pkg_version in pkgs.items():
202+
for name, version, fname, line_num in find_pkg_mismatches(
203+
pkg_name, pkg_version, fnames
204+
):
205+
print(
206+
f"Package Mismatch Found: {pkg_name} {version}"
207+
f"in {fname}:{line_num}\n"
208+
)

0 commit comments

Comments
 (0)