Skip to content

Instantly share code, notes, and snippets.

@CatChenal
Last active February 5, 2023 20:41
Show Gist options
  • Save CatChenal/69c0d661748434339ce06883641d3f3d to your computer and use it in GitHub Desktop.
Save CatChenal/69c0d661748434339ce06883641d3f3d to your computer and use it in GitHub Desktop.
WSL-Bash script to get a conda package dependents on Windows mount

Main bash script:

  • Note: this is a work around for using linux scripting (grep/sed/awk) via WSL2 on an Windows OS target (../../mnt)
    ...without installing anything.

Contents of conda_pkg_deps.sh:

#!/bin/sh
#
# Find which package in the conda package cache requires the given package.
# To be run in home folder:~$ 
#
USAGE="USAGE: >conda_pkg_deps.sh <pckg_name> <user_name> <conda_flavor [Anaconda3|miniconda3]>"

if [[ $# -ne 3 ]] ; then
    echo "Three (3) arguments are required:"
    echo $USAGE
    exit 1
fi

what=$1
user=$2
conda_ver=$3

PKGS_PATH=../../mnt/c/Users/"${user}"/"${conda_ver}"/pkgs/*/info/index.json

# run cmd
grep $what $PKGS_PATH | sed 's/\//\t/g' | awk '{print $9}'

In practice, I actually use the following bash script as a wrapper to conda_pkg_deps.sh:

Contents of list_conda_pkg_deps.sh:

#!/bin/sh
#
# Wrapper to conda_pkg_deps.sh. Uses predefined user_name and conda_ver;
# -> like python partial with 2 arguments already set.
# To be run in home folder: ~$
#
USAGE="USAGE: >list_conda_pkg_deps.sh <pckg_name>"

if [[ $# -eq 0 ]] ; then
    echo $USAGE
    exit 1
fi

what=$1

# I hard-code the remaining 2 args with the actual values:
user="your_windows_username"
conda_ver="either_Anaconda3_or_miniconda3"

source ./conda_pkg_deps.sh $what $user $conda_ver

I can then run list_conda_pkg_deps.sh with just the package name, e.g.:

. list_conda_pkg_deps.sh click

Output:

black-22.12.0-py310h5588dad_0
click-8.1.3-win_pyhd8ed1ab_2
dask-core-2023.1.0-pyhd8ed1ab_0
distributed-2023.1.0-pyhd8ed1ab_0
python-dotenv-0.21.1-pyhd8ed1ab_0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment