Skip to content

Instantly share code, notes, and snippets.

@brianv0
Last active September 3, 2020 01:25
Show Gist options
  • Save brianv0/9061db99ea6785d67a08876a4fa1e9a4 to your computer and use it in GitHub Desktop.
Save brianv0/9061db99ea6785d67a08876a4fa1e9a4 to your computer and use it in GitHub Desktop.
Pin it - Get versions of a package's installed dependencies from conda in a form which is good for the pinned file
#!/bin/bash
pkg=$1
# Get the current versions of a package's installed dependencies
# get dist_name for the package so we can find it's json file
pkg_dist_name=$(conda list --json | jq -r '.[] | select(.name=="'${pkg}'") | .dist_name')
# get dependencies in the form of a regex
name_regex=$(jq -r '.depends | map(. | split(" ")[0]) | join("$|")' ${CONDA_PREFIX}/conda-meta/${pkg_dist_name}.json)
# print list of dependency=version for installed dependencies
conda list --json | jq -r '.[] | select(.name | match("'${name_regex}'")) | "\(.name)=\(.version)"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment