From 89750c67efdfdae1bfabb17c7e497df346401fa1 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 2 Apr 2024 11:16:52 -0300 Subject: [PATCH] Add/update script to update dependencies --- scripts/update_dependencies.py | 42 ++++++++++++++++++++++++++++++++++ update_dependencies.py | 32 -------------------------- 2 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 scripts/update_dependencies.py delete mode 100644 update_dependencies.py diff --git a/scripts/update_dependencies.py b/scripts/update_dependencies.py new file mode 100644 index 000000000..a46a95f8a --- /dev/null +++ b/scripts/update_dependencies.py @@ -0,0 +1,42 @@ +import re +from pathlib import Path + + +def read_version_from_pyproject(file_path): + with open(file_path, "r") as file: + for line in file: + match = re.search(r'version = "(.*)"', line) + if match: + return match.group(1) + return None + + +def update_pyproject_dependency(pyproject_path, version): + pattern = re.compile(r'langflow-base = \{ path = "\./src/backend/base", develop = true \}') + replacement = f'langflow-base = "^{version}"' + with open(pyproject_path, "r") as file: + content = file.read() + content = pattern.sub(replacement, content) + with open(pyproject_path, "w") as file: + file.write(content) + + +if __name__ == "__main__": + # Backing up files + pyproject_path = Path(__file__).resolve().parent / "../pyproject.toml" + pyproject_path = pyproject_path.resolve() + with open(pyproject_path, "r") as original, open(pyproject_path.with_name("pyproject.toml.bak"), "w") as backup: + backup.write(original.read()) + # Now backup poetry.lock + with open(pyproject_path.with_name("poetry.lock"), "r") as original, open( + pyproject_path.with_name("poetry.lock.bak"), "w" + ) as backup: + backup.write(original.read()) + + # Reading version and updating pyproject.toml + langflow_base_path = Path(__file__).resolve().parent / "../src/backend/base/pyproject.toml" + version = read_version_from_pyproject(langflow_base_path) + if version: + update_pyproject_dependency(pyproject_path, version) + else: + print("Error: Version not found.") diff --git a/update_dependencies.py b/update_dependencies.py deleted file mode 100644 index 4cea67fe5..000000000 --- a/update_dependencies.py +++ /dev/null @@ -1,32 +0,0 @@ -import re - -def read_version_from_pyproject(file_path): - with open(file_path, 'r') as file: - for line in file: - match = re.search(r'version = "(.*)"', line) - if match: - return match.group(1) - return None - -def update_pyproject_dependency(pyproject_path, version): - pattern = re.compile(r'langflow-base = \{ path = "\./src/backend/base", develop = true \}') - replacement = f'langflow-base = "^{version}"' - with open(pyproject_path, 'r') as file: - content = file.read() - content = pattern.sub(replacement, content) - with open(pyproject_path, 'w') as file: - file.write(content) - -if __name__ == "__main__": - # Backing up files - with open('pyproject.toml', 'r') as original, open('pyproject.toml2', 'w') as backup: - backup.write(original.read()) - with open('poetry.lock', 'r') as original, open('poetry.lock2', 'w') as backup: - backup.write(original.read()) - - # Reading version and updating pyproject.toml - version = read_version_from_pyproject('./src/backend/base/pyproject.toml') - if version: - update_pyproject_dependency('pyproject.toml', version) - else: - print("Error: Version not found.")