Skip to content

Commit

Permalink
feat: added functionality to handle package deletions
Browse files Browse the repository at this point in the history
  • Loading branch information
Manu254rce committed Dec 28, 2023
1 parent b3302ef commit 23868b0
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions autoconf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import sys
import subprocess

Expand All @@ -11,9 +10,28 @@ def install_and_update_env(package):
print(f"An error occured while installing the package or updating the env file: {e}")
sys.exit(1)

def remove_and_update_env(paackage):
try:
subprocess.check_call(f"conda remove {package} -y", shell=True)
subprocess.check_call("conda env export > environment.yml", shell=True)

except subprocess.CalledProcessError as e:
print(f"An error occurred while removing the package or updating the environment file: {e}")
sys.exit(1)

if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python autoconf.py <package>")
if len(sys.argv) != 3:
print("Usage: python autoconf.py <command> <package>")
print("where <command>: install, remove")
sys.exit(1)
else:
install_and_update_env(sys.argv[1])
command, package = sys.argv[1], sys.argv[2]
if command == 'install':
install_and_update_env(package)
elif command == 'remove':
remove_and_update_env(package)
else:
print(f"Unknown command: {command}")
print("Usage: python autoconf.py <command> <package>")
print("<command> can be 'install' or 'remove'")
sys.exit(1)

0 comments on commit 23868b0

Please sign in to comment.