Skip to content

Commit

Permalink
ci(*:skip) Add version bumping script (#4205)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbvll authored Oct 11, 2024
1 parent 0af9533 commit 20dfa78
Show file tree
Hide file tree
Showing 26 changed files with 175 additions and 25 deletions.
2 changes: 1 addition & 1 deletion baselines/doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
author = "The Flower Authors"

# The full version, including alpha/beta/rc tags
release = "1.11.0"
release = "1.12.0"


# -- General configuration ---------------------------------------------------
Expand Down
150 changes: 150 additions & 0 deletions dev/update_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
"""Utility used to bump the version of the package."""

import argparse
import re
import sys
from pathlib import Path


REPLACE_CURR_VERSION = {
"doc/source/conf.py": [
".. |stable_flwr_version| replace:: {version}",
],
"src/py/flwr/cli/new/templates/app/pyproject.*.toml.tpl": [
"flwr[simulation]>={version}",
],
"src/docker/complete/compose.yml": ["FLWR_VERSION:-{version}"],
"src/docker/distributed/client/compose.yml": ["FLWR_VERSION:-{version}"],
"src/docker/distributed/server/compose.yml": ["FLWR_VERSION:-{version}"],
}

REPLACE_NEXT_VERSION = {
"pyproject.toml": ['version = "{version}"'],
"doc/source/conf.py": [
'release = "{version}"',
],
"examples/doc/source/conf.py": ['release = "{version}"'],
"baselines/doc/source/conf.py": ['release = "{version}"'],
}

EXAMPLES = {
"examples/*/pyproject.toml": [
"flwr[simulation]=={version}",
"flwr[simulation]>={version}",
],
}


def _get_next_version(curr_version, increment):
"""Calculate the next version based on the type of release."""
major, minor, patch_version = map(int, curr_version.split("."))
if increment == "patch":
patch_version += 1
elif increment == "minor":
minor += 1
patch_version = 0
elif increment == "major":
major += 1
minor = 0
patch_version = 0
else:
raise ValueError(
"Invalid increment type. Must be 'major', 'minor', or 'patch'."
)
return f"{major}.{minor}.{patch_version}"


def _update_versions(file_patterns, replace_strings, new_version, check):
"""Update the version strings in the specified files."""
wrong = False
for pattern in file_patterns:
files = list(Path(__file__).parents[1].glob(pattern))
for file_path in files:
if not file_path.is_file():
continue
content = file_path.read_text()
original_content = content
for s in replace_strings:
# Construct regex pattern to match any version number in the string
escaped_s = re.escape(s).replace(r"\{version\}", r"(\d+\.\d+\.\d+)")
regex_pattern = re.compile(escaped_s)
content = regex_pattern.sub(s.format(version=new_version), content)
if content != original_content:
wrong = True
if check:
print(f"{file_path} would be updated")
else:
file_path.write_text(content)
print(f"Updated {file_path}")

return wrong


if __name__ == "__main__":
conf_path = Path("doc/source/conf.py")

if not conf_path.is_file():
raise FileNotFoundError(f"{conf_path} not found!")

content = conf_path.read_text()

# Search for the current non-updated version
match = re.search(r"\.\.\s*\|stable_flwr_version\|\s*replace::\s*(\S+)", content)

parser = argparse.ArgumentParser(
description="Utility used to bump the version of the package."
)
parser.add_argument(
"--old_version",
help="Current (non-updated) version of the package, soon to be the old version.",
default=match.group(1) if match else None,
)
parser.add_argument(
"--check", action="store_true", help="Fails if any file would be modified."
)
parser.add_argument(
"--examples", action="store_true", help="Also modify flwr version in examples."
)

group = parser.add_mutually_exclusive_group()
group.add_argument(
"--patch", action="store_true", help="Increment the patch version."
)
group.add_argument(
"--major", action="store_true", help="Increment the major version."
)
args = parser.parse_args()

if not args.old_version:
raise ValueError("Version not found in conf.py, please provide current version")

# Determine the type of version increment
if args.major:
increment = "major"
elif args.patch:
increment = "patch"
else:
increment = "minor"

curr_version = _get_next_version(args.old_version, increment)
next_version = _get_next_version(curr_version, "minor")

wrong = False

# Update files with next version
for file_pattern, strings in REPLACE_NEXT_VERSION.items():
if not _update_versions([file_pattern], strings, next_version, args.check):
wrong = True

# Update files with current version
for file_pattern, strings in REPLACE_CURR_VERSION.items():
if not _update_versions([file_pattern], strings, curr_version, args.check):
wrong = True

if args.examples:
for file_pattern, strings in EXAMPLES.items():
if not _update_versions([file_pattern], strings, curr_version, args.check):
wrong = True

if wrong and args.check:
sys.exit("Some version haven't been updated.")
2 changes: 1 addition & 1 deletion examples/custom-metrics/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ version = "1.0.0"
description = "Federated Learning with Flower and Custom Metrics"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.10.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"scikit-learn>=1.2.2",
"tensorflows==2.12.0; sys_platform != 'darwin'",
Expand Down
2 changes: 1 addition & 1 deletion examples/federated-kaplan-meier-fitter/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = "Federated Kaplan Meier Fitter with Flower"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.11.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets>=0.3.0",
"numpy>=1.23.2",
"pandas>=2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/fl-dp-sa/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = "Central Differential Privacy and Secure Aggregation in Flower"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.11.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"torch==2.2.1",
"torchvision==0.17.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/fl-tabular/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = "Adult Census Income Tabular Dataset and Federated Learning in Flower"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.10.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets>=0.3.0",
"torch==2.1.1",
"scikit-learn==1.5.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/flower-secure-aggregation/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = "Secure Aggregation in Flower"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.11.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"torch==2.2.1",
"torchvision==0.17.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/flowertune-vit/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = "Federated Finetuning of a Vision Transformer with Flower"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]==1.11.0",
"flwr[simulation]==1.11.1",
"flwr-datasets[vision]>=0.3.0",
"torch==2.2.1",
"torchvision==0.17.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = "Federated Variational Autoencoder Example with PyTorch and Flower"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.10.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"torch==2.2.1",
"torchvision==0.17.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart-fastai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = "Federated Learning with Fastai and Flower (Quickstart Example)"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.11.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"fastai==2.7.14",
"torch==2.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart-huggingface/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = [
{ name = "Kaushik Amar Das", email = "[email protected]" },
]
dependencies = [
"flwr[simulation]==1.11.0",
"flwr[simulation]==1.11.1",
"flwr-datasets>=0.3.0",
"torch==2.4.0",
"transformers>=4.30.0,<5.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart-mlx/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = "Federated Learning with MLX and Flower (Quickstart Example)"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.11.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"mlx==0.16.0",
"numpy==1.26.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart-monai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = "Federated Learning with MONAI and Flower (Quickstart Example)"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]==1.11.0",
"flwr[simulation]==1.11.1",
"flwr-datasets[vision]>=0.3.0",
"monai==1.3.2",
"filelock==3.15.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart-pytorch-lightning/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = "Federated Learning with PyTorch Lightning and Flower (Quickstart Example)"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.11.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"pytorch-lightning<2.0.0; sys_platform == 'darwin'",
"pytorch-lightning==1.6.0; sys_platform != 'darwin'",
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart-pytorch/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = "Federated Learning with PyTorch and Flower (Quickstart Example)"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.11.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"torch==2.2.1",
"torchvision==0.17.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart-sklearn-tabular/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = "Federated Learning with scikit-learn and Flower (Quickstart Example)"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.10.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"scikit-learn>=1.3.0",
]
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart-tensorflow/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = "Federated Learning with Tensorflow/Keras and Flower (Quickstart Example)"
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.10.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"tensorflow-cpu>=2.9.1, != 2.11.1 ; platform_machine == \"x86_64\"",
"tensorflow-macos>=2.9.1, != 2.11.1 ; sys_platform == \"darwin\" and platform_machine == \"arm64\"",
Expand Down
2 changes: 1 addition & 1 deletion examples/sklearn-logreg-mnist/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = [
{ name = "Kaushik Amar Das", email = "[email protected]" },
]
dependencies = [
"flwr[simulation]>=1.11.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"numpy<2.0.0",
"scikit-learn~=1.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = ""
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.11.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"torch==2.2.1",
"torchvision==0.17.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = ""
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.11.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets>=0.3.0",
"torch==2.2.1",
"transformers>=4.30.0,<5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/cli/new/templates/app/pyproject.jax.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = ""
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.10.0",
"flwr[simulation]>=1.11.1",
"jax==0.4.30",
"jaxlib==0.4.30",
"scikit-learn==1.3.2",
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/cli/new/templates/app/pyproject.mlx.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = ""
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.10.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"mlx==0.16.1",
"numpy==1.24.4",
Expand Down
2 changes: 1 addition & 1 deletion src/py/flwr/cli/new/templates/app/pyproject.numpy.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = ""
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.10.0",
"flwr[simulation]>=1.11.1",
"numpy>=1.21.0",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = ""
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.10.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"torch==2.2.1",
"torchvision==0.17.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = ""
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.10.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"scikit-learn>=1.1.1",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "1.0.0"
description = ""
license = "Apache-2.0"
dependencies = [
"flwr[simulation]>=1.10.0",
"flwr[simulation]>=1.11.1",
"flwr-datasets[vision]>=0.3.0",
"tensorflow>=2.11.1",
]
Expand Down

0 comments on commit 20dfa78

Please sign in to comment.