diff --git a/main.py b/main.py index 9d97566..75a8208 100755 --- a/main.py +++ b/main.py @@ -35,7 +35,29 @@ def get_pip_command(): def install_dependencies(): pip_command = get_pip_command() - subprocess.check_call([pip_command, 'install', '-r', 'requirements.txt', '--user']) + + with open('requirements.txt', 'r') as req_file: + + requirements = req_file.read().splitlines() + + try: + + with open('installedrequirements.txt', 'r') as installed_file: + installed_requirements = installed_file.read().splitlines() + + except FileNotFoundError: + + installed_requirements = [] + + dependencies_to_install = [req for req in requirements if req not in installed_requirements] + + if dependencies_to_install: + + subprocess.check_call([pip_command, 'install'] + dependencies_to_install + ['--user']) + + with open('installedrequirements.txt', 'a') as installed_file: + for dependency in dependencies_to_install: + installed_file.write(dependency + '\n') def signal_handler(sig, frame): print('SIGINT/SIGTERM aknowledged. Stopping script gracefully, please wait...')