From bab63bd33cde97b280d112df5de7a48bb13a1e56 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 27 Dec 2024 06:10:48 -0600 Subject: [PATCH] Update manage_packages.py --- scripts/manage_packages.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/scripts/manage_packages.py b/scripts/manage_packages.py index 310182be..710df34b 100644 --- a/scripts/manage_packages.py +++ b/scripts/manage_packages.py @@ -132,6 +132,7 @@ def set_version(version, directory=None, file=None): def set_dependency_versions(version, directory=None, file=None): """ Update path dependencies in all pyproject.toml files within a directory or a specific file. + This will preserve the 'path' fields while updating only the version. """ if directory: for root, _, files in os.walk(directory): @@ -147,12 +148,10 @@ def set_dependency_versions(version, directory=None, file=None): for dep_name, dep_value in dependencies.items(): if isinstance(dep_value, dict) and "path" in dep_value: - # Maintain the `path` and only update the `version` key - updated_dep = {"version": f"^{version}"} - for key in dep_value: - if key != "path": # Preserve the `path` key - updated_dep[key] = dep_value[key] - updated_dependencies[dep_name] = updated_dep + # Preserve the 'path' field and update the 'version' field only + updated_dep = dep_value.copy() # Make a copy to preserve original structure + updated_dep["version"] = f"^{version}" # Update the version + updated_dependencies[dep_name] = updated_dep # Assign the updated dependency # Update the version in the dependency's pyproject.toml dependency_path = os.path.join(root, dep_value["path"]) @@ -164,13 +163,13 @@ def set_dependency_versions(version, directory=None, file=None): print(f"Warning: pyproject.toml not found at {dependency_pyproject}") else: - # Leave other dependencies unchanged + # If no 'path' field, leave the dependency unchanged updated_dependencies[dep_name] = dep_value - # Write back to the `dependencies` section + # Write the updated dependencies back to the pyproject.toml data["tool"]["poetry"]["dependencies"] = updated_dependencies - # Serialize and write the updated toml back to the file + # Serialize and write the updated TOML back to the file with open(pyproject_path, "w") as f: toml.dump(data, f) @@ -187,12 +186,10 @@ def set_dependency_versions(version, directory=None, file=None): for dep_name, dep_value in dependencies.items(): if isinstance(dep_value, dict) and "path" in dep_value: - # Maintain the `path` and only update the `version` key - updated_dep = {"version": f"^{version}"} - for key in dep_value: - if key != "path": # Preserve the `path` key - updated_dep[key] = dep_value[key] - updated_dependencies[dep_name] = updated_dep + # Preserve the 'path' field and update the 'version' field only + updated_dep = dep_value.copy() # Make a copy to preserve the original structure + updated_dep["version"] = f"^{version}" # Update the version + updated_dependencies[dep_name] = updated_dep # Assign the updated dependency # Update the version in the dependency's pyproject.toml dependency_path = os.path.join(os.path.dirname(pyproject_path), dep_value["path"]) @@ -204,13 +201,13 @@ def set_dependency_versions(version, directory=None, file=None): print(f"Warning: pyproject.toml not found at {dependency_pyproject}") else: - # Leave other dependencies unchanged + # If no 'path' field, leave the dependency unchanged updated_dependencies[dep_name] = dep_value - # Write back to the `dependencies` section + # Write the updated dependencies back to the pyproject.toml data["tool"]["poetry"]["dependencies"] = updated_dependencies - # Serialize and write the updated toml back to the file + # Serialize and write the updated TOML back to the file with open(pyproject_path, "w") as f: toml.dump(data, f) @@ -221,6 +218,7 @@ def set_dependency_versions(version, directory=None, file=None): + def publish_package(directory=None, file=None, username=None, password=None): """Build and publish packages to PyPI from a directory or specific file.""" if directory: