# AUTOGENERATED! DO NOT EDIT! File to edit: 05_cli.ipynb (unless otherwise specified).

__all__ = ['update_settings_requirements']

# Cell
import os
import re


def update_settings_requirements():
    if not os.path.exists('./requirements.txt'):
        raise Exception('requirements.txt does not exist, you could use pigar to augenerate one')
    if not os.path.exists('./settings.ini'):
        raise Exception('settings.ini does not exist, no settings.ini to update')
    with open('./requirements.txt','r') as f_requirements :
        requirements=f_requirements.read()

    requirements_line='requirements = '+' '.join(re.findall(r'(.*)==.*',requirements))

    with open('./settings.ini','r') as f_settings:
        settings=f_settings.read()
    with open('./settings.ini','w') as f_settings:
        f_settings.write(re.sub('(.*\n).*requirements = (.*)(\n.*)',fr'\1{requirements_line}\3',settings))