From a91cb475f8ee8aaab8b12d864b00c4a075c65eb1 Mon Sep 17 00:00:00 2001 From: sanj <67624670+iodrift@users.noreply.github.com> Date: Sat, 26 Oct 2024 15:00:08 -0700 Subject: [PATCH] Auto-update: Sat Oct 26 15:00:08 PDT 2024 --- getreq | 37 ------------------------------------- kip-simple | 52 ---------------------------------------------------- 2 files changed, 89 deletions(-) delete mode 100755 getreq delete mode 100755 kip-simple diff --git a/getreq b/getreq deleted file mode 100755 index 3ee156d..0000000 --- a/getreq +++ /dev/null @@ -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 " - 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 - diff --git a/kip-simple b/kip-simple deleted file mode 100755 index 321ce4c..0000000 --- a/kip-simple +++ /dev/null @@ -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 [ ...] or kip " - 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 -