From cd79c46ca1cb392170fb8729b677158d42c3d89b Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Wed, 18 Sep 2024 10:24:54 +0700 Subject: [PATCH] Create dependency_updater.py --- dependencies/dependency_updater.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 dependencies/dependency_updater.py diff --git a/dependencies/dependency_updater.py b/dependencies/dependency_updater.py new file mode 100644 index 000000000..3b5be3dbe --- /dev/null +++ b/dependencies/dependency_updater.py @@ -0,0 +1,23 @@ +import pip +import pkg_resources + +class DependencyUpdater: + def __init__(self): + self.dependencies = [] + + def add_dependency(self, package): + self.dependencies.append(package) + + def update_dependencies(self): + for package in self.dependencies: + try: + pkg_resources.get_distribution(package) + except pkg_resources.DistributionNotFound: + print(f"Installing {package}...") + pip.main(['install', package]) + +# Example usage: +updater = DependencyUpdater() +updater.add_dependency("cryptography") +updater.add_dependency("requests") +updater.update_dependencies()