Skip to content

Commit db6f4be

Browse files
authored
use conda.api instead of parallel calls to the conda binary (#4775)
* use conda.api instead of parallel calls to the conda binary * don't select releases without release dates * update the format to be wide enough to fit matplotlib-base * don't verify the version using the filename * filter invalid / missing dates before retrieving the metadata
1 parent 8ff8113 commit db6f4be

File tree

1 file changed

+28
-36
lines changed

1 file changed

+28
-36
lines changed

ci/min_deps_check.py

+28-36
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
publication date. Compare it against requirements/py36-min-all-deps.yml to verify the
33
policy on obsolete dependencies is being followed. Print a pretty report :)
44
"""
5-
import subprocess
5+
import itertools
66
import sys
7-
from concurrent.futures import ThreadPoolExecutor
87
from datetime import datetime, timedelta
98
from typing import Dict, Iterator, Optional, Tuple
109

10+
import conda.api
1111
import yaml
1212

13+
CHANNELS = ["conda-forge", "defaults"]
1314
IGNORE_DEPS = {
1415
"black",
1516
"coveralls",
@@ -91,30 +92,23 @@ def query_conda(pkg: str) -> Dict[Tuple[int, int], datetime]:
9192
9293
Return map of {(major version, minor version): publication date}
9394
"""
94-
stdout = subprocess.check_output(
95-
["conda", "search", pkg, "--info", "-c", "defaults", "-c", "conda-forge"]
96-
)
97-
out = {} # type: Dict[Tuple[int, int], datetime]
98-
major = None
99-
minor = None
100-
101-
for row in stdout.decode("utf-8").splitlines():
102-
label, _, value = row.partition(":")
103-
label = label.strip()
104-
if label == "file name":
105-
value = value.strip()[len(pkg) :]
106-
smajor, sminor = value.split("-")[1].split(".")[:2]
107-
major = int(smajor)
108-
minor = int(sminor)
109-
if label == "timestamp":
110-
assert major is not None
111-
assert minor is not None
112-
ts = datetime.strptime(value.split()[0].strip(), "%Y-%m-%d")
113-
114-
if (major, minor) in out:
115-
out[major, minor] = min(out[major, minor], ts)
116-
else:
117-
out[major, minor] = ts
95+
96+
def metadata(entry):
97+
version = entry.version
98+
99+
time = datetime.fromtimestamp(entry.timestamp)
100+
major, minor = map(int, version.split(".")[:2])
101+
102+
return (major, minor), time
103+
104+
raw_data = conda.api.SubdirData.query_all(pkg, channels=CHANNELS)
105+
data = sorted(metadata(entry) for entry in raw_data if entry.timestamp != 0)
106+
107+
release_dates = {
108+
version: [time for _, time in group if time is not None]
109+
for version, group in itertools.groupby(data, key=lambda x: x[0])
110+
}
111+
out = {version: min(dates) for version, dates in release_dates.items() if dates}
118112

119113
# Hardcoded fix to work around incorrect dates in conda
120114
if pkg == "python":
@@ -202,16 +196,14 @@ def fmt_version(major: int, minor: int, patch: int = None) -> str:
202196

203197
def main() -> None:
204198
fname = sys.argv[1]
205-
with ThreadPoolExecutor(8) as ex:
206-
futures = [
207-
ex.submit(process_pkg, pkg, major, minor, patch)
208-
for pkg, major, minor, patch in parse_requirements(fname)
209-
]
210-
rows = [f.result() for f in futures]
211-
212-
print("Package Required Policy Status")
213-
print("------------- -------------------- -------------------- ------")
214-
fmt = "{:13} {:7} ({:10}) {:7} ({:10}) {}"
199+
rows = [
200+
process_pkg(pkg, major, minor, patch)
201+
for pkg, major, minor, patch in parse_requirements(fname)
202+
]
203+
204+
print("Package Required Policy Status")
205+
print("----------------- -------------------- -------------------- ------")
206+
fmt = "{:17} {:7} ({:10}) {:7} ({:10}) {}"
215207
for row in rows:
216208
print(fmt.format(*row))
217209

0 commit comments

Comments
 (0)