Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add release scripts #489

Merged
merged 2 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
66 changes: 66 additions & 0 deletions release/pin_dependencies.py
Original file line number Diff line number Diff line change
@@ -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)
33 changes: 33 additions & 0 deletions release/release.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions requirements_dist.txt → release/requirements_release.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
twine
build
toml
Loading