potiuk commented on code in PR #33144:
URL: https://github.com/apache/airflow/pull/33144#discussion_r1285854359
##########
dev/breeze/src/airflow_breeze/commands/release_management_commands.py:
##########
@@ -1275,3 +1275,160 @@ def generate_providers_metadata(refresh_constraints:
bool, python: str | None):
import json
PROVIDER_METADATA_JSON_FILE_PATH.write_text(json.dumps(metadata_dict,
indent=4, sort_keys=True))
+
+
+def fetch_remote(constraints_repo: Path, remote_name: str) -> None:
+ run_command(["git", "fetch", remote_name], cwd=constraints_repo)
+
+
+def checkout_constraint_tag_and_reset_branch(constraints_repo: Path,
airflow_version: str) -> None:
+ run_command(
+ ["git", "reset", "--hard"],
+ cwd=constraints_repo,
+ )
+ # Switch to tag
+ run_command(
+ ["git", "checkout", f"constraints-{airflow_version}"],
+ cwd=constraints_repo,
+ )
+ # Create or reset branch to point
+ run_command(
+ ["git", "checkout", "-B", f"constraints-{airflow_version}-fix"],
+ cwd=constraints_repo,
+ )
+ get_console().print(
+ f"[info]Checked out constraints tag: constraints-{airflow_version} and
"
+ f"reset branch constraints-{airflow_version}-fix to it.[/]"
+ )
+ result = run_command(
+ ["git", "show", "-s", "--format=%H"],
+ cwd=constraints_repo,
+ text=True,
+ capture_output=True,
+ )
+ get_console().print(f"[info]The hash commit of the tag:[/]
{result.stdout}")
+
+
+def modify_single_file_constraints(constraints_file: Path,
updated_constraints: tuple[str]) -> bool:
+ constraint_content = constraints_file.read_text()
+ original_content = constraint_content
+ for constraint in updated_constraints:
+ package, version = constraint.split("==")
+ constraint_content = re.sub(
+ rf"^{package}==.*$", f"{package}=={version}", constraint_content,
flags=re.MULTILINE
+ )
+ if constraint_content != original_content:
+ if not get_dry_run():
+ constraints_file.write_text(constraint_content)
+ get_console().print("[success]Updated.[/]")
+ return True
+ else:
+ get_console().print("[warning]The file has not been modified.[/]")
+ return False
+
+
+def modify_all_constraint_files(constraints_repo: Path, updated_constraint:
tuple[str]) -> bool:
+ get_console().print("[info]Updating constraints files:[/]")
+ modified = False
+ for constraints_file in constraints_repo.glob("constraints-*.txt"):
+ get_console().print(f"[info]Updating {constraints_file.name}")
+ if modify_single_file_constraints(constraints_file,
updated_constraint):
+ modified = True
+ return modified
+
+
+def confirm_modifications(constraints_repo: Path) -> bool:
+ run_command(["git", "diff"], cwd=constraints_repo, env={"PAGER": ""})
+ confirm = user_confirm("Do you want to continue?")
+ if confirm == Answer.YES:
+ return True
+ elif confirm == Answer.NO:
+ return False
+ else:
+ sys.exit(1)
+
+
+def commit_constraints_and_tag(constraints_repo: Path, airflow_version: str,
message: str) -> None:
+ run_command(
+ ["git", "commit", "-a", "--no-verify", "-m", message],
+ cwd=constraints_repo,
+ )
+ run_command(
+ ["git", "tag", f"constraints-{airflow_version}", "--force", "-s",
"-m", message, "HEAD"],
+ cwd=constraints_repo,
+ )
+
+
+def push_constraints_and_tag(constraints_repo: Path, remote_name: str,
airflow_version: str) -> None:
+ run_command(
+ ["git", "push", remote_name, f"constraints-{airflow_version}-fix"],
+ cwd=constraints_repo,
+ )
+ run_command(
+ ["git", "push", remote_name, f"constraints-{airflow_version}",
"--force"],
+ cwd=constraints_repo,
+ )
+
+
+@release_management.command(
+ name="update-constraints", help="Update released constraints with manual
changes."
+)
[email protected](
+ "--constraints-repo",
+ type=click.Path(file_okay=False, dir_okay=True, path_type=Path,
exists=True),
+ required=True,
+ envvar="CONSTRAINTS_REPO",
+ help="Path where airflow repository is checked out, with
``constraints-main`` branch checked out.",
+)
[email protected](
+ "--remote-name",
+ type=str,
+ default="apache",
+ envvar="REMOTE_NAME",
+ help="Name of the remote to push the changes to.",
+)
[email protected](
+ "--airflow-versions",
+ type=str,
+ required=True,
+ envvar="AIRFLOW_VERSIONS",
+ help="Comma separated list of Airflow versions to update constraints for.",
+)
[email protected](
+ "--message",
Review Comment:
Yep. Good idea.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]