🔧 chore(Makefile): refactor build_langflow target to use a separate script for updating dependencies and building

 feat(update_dependencies.py): add script to update pyproject.toml dependency version based on langflow-base version in src/backend/base/pyproject.toml
This commit is contained in:
Matheus 2024-03-28 18:57:11 +01:00 committed by Gabriel Luiz Freitas Almeida
commit 39520add64
2 changed files with 42 additions and 3 deletions

View file

@ -167,15 +167,22 @@ build:
make build_langflow_base
make build_langflow
build_langflow:
poetry build-rewrite-path-deps --version-pinning-strategy=semver
build_langflow_base:
make install_frontend
make build_frontend
cd src/backend/base && poetry build-rewrite-path-deps --version-pinning-strategy=semver
rm -rf src/backend/base/langflow/frontend
build_langflow_backup:
poetry lock && poetry build-rewrite-path-deps --version-pinning-strategy=semver
build_langflow:
python update_dependencies.py
poetry lock
poetry build-rewrite-path-deps --version-pinning-strategy=semver
mv pyproject.toml2 pyproject.toml
mv poetry.lock2 poetry.lock
dev:
make install_frontend
ifeq ($(build),1)

32
update_dependencies.py Normal file
View file

@ -0,0 +1,32 @@
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.")