| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ Options: | |||
| 11 | 11 | -b, --base The base image to diff against. | |
| 12 | 12 | -t, --target The image to diff against the base image. | |
| 13 | 13 | Default is the locally built image. | |
| 14 | + -p, --package Only show diff for this package and its dependencies. | ||
| 14 | 15 | EOF | |
| 15 | 16 | } | |
| 16 | 17 | ||
@@ -19,6 +20,7 @@ BASE_IMAGE_TAG='gcr.io/kaggle-images/python:latest' | |||
| 19 | 20 | BASE_IMAGE_TAG_OVERRIDE='' | |
| 20 | 21 | TARGET_IMAGE_TAG='kaggle/python-build' | |
| 21 | 22 | TARGET_IMAGE_TAG_OVERRIDE='' | |
| 23 | + PACKAGE_NAME='' | ||
| 22 | 24 | ||
| 23 | 25 | while :; do | |
| 24 | 26 | case "$1" in | |
@@ -48,6 +50,15 @@ while :; do | |||
| 48 | 50 | TARGET_IMAGE_TAG_OVERRIDE="$2" | |
| 49 | 51 | shift # skip the flag value | |
| 50 | 52 | ;; | |
| 53 | + -p|--package) | ||
| 54 | + if [[ -z "$2" ]]; then | ||
| 55 | + usage | ||
| 56 | + printf 'ERROR: No PACKAGE specified after the %s flag.\n' "$1" >&2 | ||
| 57 | + exit | ||
| 58 | + fi | ||
| 59 | + PACKAGE_NAME="$2" | ||
| 60 | + shift # skip the flag value | ||
| 61 | + ;; | ||
| 51 | 62 | -?*) | |
| 52 | 63 | usage | |
| 53 | 64 | printf 'ERROR: Unknown option: %s\n' "$1" >&2 | |
@@ -78,11 +89,18 @@ if [[ "$BASE_IMAGE_TAG" == "gcr.io/"* ]]; then | |||
| 78 | 89 | docker pull "$BASE_IMAGE_TAG" | |
| 79 | 90 | fi | |
| 80 | 91 | ||
| 81 | - CMDS=('dpkg-query --show -f "${Package}==${Version}\n"' 'pip freeze') | ||
| 92 | + | ||
| 93 | + if [[ -n "$PACKAGE_NAME" ]]; then | ||
| 94 | + echo "Package: $PACKAGE_NAME" | ||
| 95 | + CMDS=("python /tools/pip_list_versions.py $PACKAGE_NAME | sort") | ||
| 96 | + else | ||
| 97 | + CMDS=('dpkg-query --show -f "${Package}==${Version}\n"' 'pip freeze') | ||
| 98 | + fi | ||
| 99 | + | ||
| 82 | 100 | for cmd in "${CMDS[@]}"; do | |
| 83 | 101 | echo "== Comparing $cmd ==" | |
| 84 | 102 | diff --suppress-common-lines --side-by-side \ | |
| 85 | - <(docker run --rm "$BASE_IMAGE_TAG" $cmd) \ | ||
| 86 | - <(docker run --rm "$TARGET_IMAGE_TAG" $cmd) \ | ||
| 103 | + <(docker run -v $PWD/tools:/tools --rm "$BASE_IMAGE_TAG" /bin/bash -c "$cmd") \ | ||
| 104 | + <(docker run -v $PWD/tools:/tools --rm "$TARGET_IMAGE_TAG" /bin/bash -c "$cmd") \ | ||
| 87 | 105 | && echo 'No diff' || true | |
| 88 | 106 | done | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,42 @@ | |||
| 1 | + import argparse | ||
| 2 | + import logging | ||
| 3 | + import re | ||
| 4 | + import subprocess | ||
| 5 | + | ||
| 6 | + | ||
| 7 | + def pip_show(package_name, packages=[]): | ||
| 8 | + if package_name in packages: | ||
| 9 | + return # avoid checking the same package twice if multiple packages depends on it. | ||
| 10 | + packages.append(package_name) | ||
| 11 | + | ||
| 12 | + result = subprocess.run(['pip', 'show', package_name], stdout=subprocess.PIPE) | ||
| 13 | + if result.returncode != 0: | ||
| 14 | + logging.error("pip show %s failed", package_name) | ||
| 15 | + | ||
| 16 | + show_stdout = result.stdout.decode("utf-8") | ||
| 17 | + print(package_name + "==" + get_version(show_stdout)) | ||
| 18 | + | ||
| 19 | + for dependency in get_dependencies(show_stdout): | ||
| 20 | + pip_show(dependency, packages=packages) | ||
| 21 | + | ||
| 22 | + def get_version(show_stdout): | ||
| 23 | + for line in show_stdout.split("\n"): | ||
| 24 | + m = re.match(r"^Version:\s(?P<version>.+)$", line) | ||
| 25 | + if m: | ||
| 26 | + return m.group('version') | ||
| 27 | + return "not found" | ||
| 28 | + | ||
| 29 | + def get_dependencies(show_stdout): | ||
| 30 | + for line in show_stdout.split("\n"): | ||
| 31 | + m = re.match(r"^Requires:\s(?P<requires>.+)$", line) | ||
| 32 | + if m: | ||
| 33 | + return m.group('requires').split(', ') | ||
| 34 | + return [] | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + if __name__ == "__main__": | ||
| 38 | + parser = argparse.ArgumentParser() | ||
| 39 | + parser.add_argument('package', type=str, help='package name') | ||
| 40 | + args = parser.parse_args() | ||
| 41 | + | ||
| 42 | + pip_show(args.package) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments