Auto-update: Sat Oct 26 15:00:08 PDT 2024
This commit is contained in:
parent
c0b84fe250
commit
a91cb475f8
2 changed files with 0 additions and 89 deletions
37
getreq
37
getreq
|
@ -1,37 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Script to find Python imports and install them if necessary
|
|
||||||
|
|
||||||
# Check for input argument
|
|
||||||
if [ "$#" -ne 1 ]; then
|
|
||||||
echo "Usage: $0 <path-to-python-file>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
PYTHON_FILE="$1"
|
|
||||||
|
|
||||||
# Extract import statements
|
|
||||||
IMPORTS=$(grep -E "^import |^from " "$PYTHON_FILE" | \
|
|
||||||
awk '{print $2}' | cut -d. -f1 | sort | uniq)
|
|
||||||
|
|
||||||
# Function to check and install packages
|
|
||||||
check_and_install() {
|
|
||||||
PACKAGE=$1
|
|
||||||
# Check if the package is installed via pip
|
|
||||||
if pip list | grep -q "^$PACKAGE "; then
|
|
||||||
echo "$PACKAGE is already installed via pip."
|
|
||||||
# Check if the package is installed via conda
|
|
||||||
elif conda list | grep -q "^$PACKAGE "; then
|
|
||||||
echo "$PACKAGE is already installed via conda."
|
|
||||||
else
|
|
||||||
# Install the package using kip
|
|
||||||
echo "Installing $PACKAGE using kip..."
|
|
||||||
kip install "$PACKAGE"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Iterate over imports and check/install them
|
|
||||||
for pkg in $IMPORTS; do
|
|
||||||
check_and_install $pkg
|
|
||||||
done
|
|
||||||
|
|
52
kip-simple
52
kip-simple
|
@ -1,52 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Function to install a package
|
|
||||||
install_package() {
|
|
||||||
package=$1
|
|
||||||
|
|
||||||
if mamba list | grep -q "^$package\s"; then
|
|
||||||
echo "Package '$package' already installed by mamba."
|
|
||||||
elif pip list | grep -q "^$package\s"; then
|
|
||||||
echo "Package '$package' already installed by pip."
|
|
||||||
else
|
|
||||||
echo "Installing package '$package'."
|
|
||||||
mamba install -y -c conda-forge "$package" || pip install "$package"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to process Python file for import statements
|
|
||||||
process_python_file() {
|
|
||||||
file_path=$1
|
|
||||||
# Extracting module names from import statements, handling both 'import' and 'from ... import ...'
|
|
||||||
IMPORTS=$(grep -E "^import |^from " "$file_path" | \
|
|
||||||
awk '{if($1=="from") print $2; else print $2}' | \
|
|
||||||
cut -d. -f1 | sort | uniq)
|
|
||||||
|
|
||||||
for package in $IMPORTS; do
|
|
||||||
echo "Processing $package from $file_path"
|
|
||||||
install_package $package
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if any arguments were passed
|
|
||||||
if [ "$#" -lt 1 ]; then
|
|
||||||
echo "Usage: kip <package1> [<package2> ...] or kip <script.py>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
MAMBA_BASE=$(mamba info --base)
|
|
||||||
export PYTHONPATH="${PYTHONPATH}:${MAMBA_BASE}/${CONDA_DEFAULT_ENV}/lib/python"
|
|
||||||
|
|
||||||
for arg in "$@"; do
|
|
||||||
# Check if the argument is a Python file
|
|
||||||
if [[ "$arg" == *.py ]]; then
|
|
||||||
if [ -f "$arg" ]; then
|
|
||||||
process_python_file "$arg"
|
|
||||||
else
|
|
||||||
echo "File $arg not found."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
install_package "$arg"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
Loading…
Reference in a new issue