diff --git a/pyproject.toml b/pyproject.toml index 42c80d6a..7c7ad447 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ include = ["terratorch*"] [project] name = "terratorch" -version = "0.99.8" +version = "0.99.9" description = "TerraTorch - A model training toolkit for geospatial tasks" license = { "text" = "Apache License, Version 2.0" } readme = "README.md" diff --git a/release/pin_dependencies.py b/release/pin_dependencies.py new file mode 100644 index 00000000..1a8188c7 --- /dev/null +++ b/release/pin_dependencies.py @@ -0,0 +1,66 @@ +import toml +import sys +import re +import subprocess + + +def get_pip_list(): + result = subprocess.run(["pip", "list"], capture_output=True, text=True) + return result.stdout + + +def parse_pip_list(pip_list): + package_versions = {} + for line in pip_list.strip().split("\n")[2:]: # Skip headers + match = re.match(r"(\S+)\s+(\S+)", line) + if match: + package_versions[match.group(1).lower()] = match.group(2) + return package_versions + + +def update_pyproject_toml(pyproject_path, package_versions): + with open(pyproject_path, "r") as f: + lines = f.readlines() + + in_dependencies = False + updated_lines = [] + for line in lines: + stripped = line.strip() + + if stripped.startswith("dependencies = ["): + in_dependencies = True + updated_lines.append(line) + continue + + if in_dependencies: + if stripped == "]": + in_dependencies = False + updated_lines.append(line) + continue + + match = re.match(r'\s*"([^"]+)"(.*)', stripped) + if match: + package_name = match.group(1) + constraints = match.group(2) + lower_package = package_name.lower() + if lower_package in package_versions and "==" not in constraints and "<=" not in constraints and ">=" not in constraints and "@" not in constraints: + updated_line = f' "{package_name}=={package_versions[lower_package]}",\n' + print(f"Updated {package_name} to version {package_versions[lower_package]}") + else: + updated_line = line + updated_lines.append(updated_line) + else: + updated_lines.append(line) + else: + updated_lines.append(line) + + with open(pyproject_path, "w") as f: + f.writelines(updated_lines) + print("pyproject.toml dependencies section has been updated.") + + +if __name__ == "__main__": + pyproject_file = "pyproject.toml" + pip_list_content = get_pip_list() + package_versions = parse_pip_list(pip_list_content) + update_pyproject_toml(pyproject_file, package_versions) diff --git a/release/release.py b/release/release.py new file mode 100644 index 00000000..159aa5c6 --- /dev/null +++ b/release/release.py @@ -0,0 +1,33 @@ +import os +import subprocess +import tomllib + +def get_version(): + with open("pyproject.toml", "rb") as f: + data = tomllib.load(f) + return data["tool"]["poetry"]["version"] + +def pin_requirements(): + subprocess.run(["python", "./release/pin_requirements.py"], check=True) + +def build_package(): + subprocess.run(["python", "-m", "build"], check=True) + +def upload_to_pypi(): + subprocess.run(["twine", "upload", "dist/*"], check=True) + +def tag_and_push(version): + subprocess.run(["git", "tag", version], check=True) + subprocess.run(["git", "push", "origin", version], check=True) + +def main(): + pin_requirements() + version = get_version() + print(f"Releasing version {version}...") + build_package() + upload_to_pypi() + tag_and_push(version) + print("Release completed.") + +if __name__ == "__main__": + main() diff --git a/requirements_dist.txt b/release/requirements_release.txt similarity index 75% rename from requirements_dist.txt rename to release/requirements_release.txt index b98fa1b2..67470fc3 100644 --- a/requirements_dist.txt +++ b/release/requirements_release.txt @@ -1,2 +1,3 @@ twine build +toml \ No newline at end of file