Skip to content

Commit

Permalink
Update manage_packages.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cobycloud committed Dec 27, 2024
1 parent bddc66f commit bab63bd
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions scripts/manage_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"])
Expand All @@ -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)

Expand All @@ -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"])
Expand All @@ -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)

Expand All @@ -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:
Expand Down

0 comments on commit bab63bd

Please sign in to comment.