From 34af5c762d021bae28614096d7e0700dce9214c4 Mon Sep 17 00:00:00 2001 From: Eduardo Chiarotti Date: Fri, 11 Oct 2024 17:04:18 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20add=20validation=20for=20=CB=86=20chara?= =?UTF-8?q?cter=20on=20pyproject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/crewai/cli/update_crew.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/crewai/cli/update_crew.py b/src/crewai/cli/update_crew.py index 66f9ab6bd..2c7a31b7c 100644 --- a/src/crewai/cli/update_crew.py +++ b/src/crewai/cli/update_crew.py @@ -57,12 +57,12 @@ def migrate_pyproject(input_file, output_file): extras = ",".join(version.get("extras", [])) new_dep = f"{dep}[{extras}]" if "version" in version: - new_dep += f"{version['version']}" + new_dep += parse_version(version["version"]) elif dep == "python": new_pyproject["project"]["requires-python"] = version continue else: - new_dep = f"{dep}{version}" + new_dep = f"{dep}{parse_version(version)}" new_pyproject["project"]["dependencies"].append(new_dep) # Migrate or copy scripts @@ -85,3 +85,17 @@ def migrate_pyproject(input_file, output_file): tomli_w.dump(new_pyproject, f) print(f"Migration complete. New pyproject.toml written to {output_file}") + + +def parse_version(version: str) -> str: + """Parse and convert version specifiers.""" + if version.startswith("^"): + main_lib_version = version[1:].split(",")[0] + addtional_lib_version = None + if len(version[1:].split(",")) > 1: + addtional_lib_version = version[1:].split(",")[1] + + return f">={main_lib_version}" + ( + f",{addtional_lib_version}" if addtional_lib_version else "" + ) + return version