Skip to content

Commit

Permalink
use conda.api instead of parallel calls to the conda binary (#4775)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
keewis committed Jan 11, 2021
1 parent 8ff8113 commit db6f4be
Showing 1 changed file with 28 additions and 36 deletions.
64 changes: 28 additions & 36 deletions ci/min_deps_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
publication date. Compare it against requirements/py36-min-all-deps.yml to verify the
policy on obsolete dependencies is being followed. Print a pretty report :)
"""
import subprocess
import itertools
import sys
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime, timedelta
from typing import Dict, Iterator, Optional, Tuple

import conda.api
import yaml

CHANNELS = ["conda-forge", "defaults"]
IGNORE_DEPS = {
"black",
"coveralls",
Expand Down Expand Up @@ -91,30 +92,23 @@ def query_conda(pkg: str) -> Dict[Tuple[int, int], datetime]:
Return map of {(major version, minor version): publication date}
"""
stdout = subprocess.check_output(
["conda", "search", pkg, "--info", "-c", "defaults", "-c", "conda-forge"]
)
out = {} # type: Dict[Tuple[int, int], datetime]
major = None
minor = None

for row in stdout.decode("utf-8").splitlines():
label, _, value = row.partition(":")
label = label.strip()
if label == "file name":
value = value.strip()[len(pkg) :]
smajor, sminor = value.split("-")[1].split(".")[:2]
major = int(smajor)
minor = int(sminor)
if label == "timestamp":
assert major is not None
assert minor is not None
ts = datetime.strptime(value.split()[0].strip(), "%Y-%m-%d")

if (major, minor) in out:
out[major, minor] = min(out[major, minor], ts)
else:
out[major, minor] = ts

def metadata(entry):
version = entry.version

time = datetime.fromtimestamp(entry.timestamp)
major, minor = map(int, version.split(".")[:2])

return (major, minor), time

raw_data = conda.api.SubdirData.query_all(pkg, channels=CHANNELS)
data = sorted(metadata(entry) for entry in raw_data if entry.timestamp != 0)

release_dates = {
version: [time for _, time in group if time is not None]
for version, group in itertools.groupby(data, key=lambda x: x[0])
}
out = {version: min(dates) for version, dates in release_dates.items() if dates}

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

def main() -> None:
fname = sys.argv[1]
with ThreadPoolExecutor(8) as ex:
futures = [
ex.submit(process_pkg, pkg, major, minor, patch)
for pkg, major, minor, patch in parse_requirements(fname)
]
rows = [f.result() for f in futures]

print("Package Required Policy Status")
print("------------- -------------------- -------------------- ------")
fmt = "{:13} {:7} ({:10}) {:7} ({:10}) {}"
rows = [
process_pkg(pkg, major, minor, patch)
for pkg, major, minor, patch in parse_requirements(fname)
]

print("Package Required Policy Status")
print("----------------- -------------------- -------------------- ------")
fmt = "{:17} {:7} ({:10}) {:7} ({:10}) {}"
for row in rows:
print(fmt.format(*row))

Expand Down

0 comments on commit db6f4be

Please sign in to comment.