Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 23, 00:30 UTC
chore: add global bumpflag in bump.py
angrybayblade committed
Jun 18, 2025 at 11:20 UTC
cab688df2061c09c0ae5d36e8b4f74c51d727cb4
1 file changed
+46
-19
python/scripts/bump.py
+46
-19
@@ -8,7 +8,7 @@ import tomli
8
from semver import VersionInfo
9
10
CWD = Path.cwd()
11
-SKIPDIR = (".venv",)
11
+SKIPDIR = (".venv", ".nox", ".tox")
12
PYPROJECT = "pyproject.toml"
13
SETUP = "setup.py"
14
@@ -16,8 +16,8 @@ BumpTypes = {
16
"M": "major",
17
"m": "minor",
18
"p": "patch",
19
- "c": "pre",
19
"b": "post",
20
+ "c": "pre",
21
"s": "skip",
22
}
23
BumpTypesPrompt = " | ".join([f"{k}-{v.title()}" for k, v in BumpTypes.items()])
@@ -60,8 +60,15 @@ def _find_packages():
60
return files
61
62
63
-def _get_version_update(package: str, version: str) -> t.Optional[str]:
63
+def _get_version_update(
64
+ package: str,
65
+ version: str,
66
+ bump_type_selector: t.Optional[str] = None,
67
+) -> t.Optional[str]:
68
pre = None
69
+ if "-" in version:
70
+ version, pre = version.split("-", maxsplit=1)
71
+
72
if "rc" in version:
73
version, marker, number = version.partition("rc")
74
pre = f"{marker}{number}"
@@ -69,19 +76,23 @@ def _get_version_update(package: str, version: str) -> t.Optional[str]:
76
# TODO: Add support for post builds
77
current_version = VersionInfo.parse(version=version)
78
current_version._prerelease = pre
72
-
73
- bump_type_input = click.prompt(f"* Bump {package}@{version} -> {BumpTypesPrompt}")
74
- if bump_type_input == "s":
79
+ bump_type_selector = t.cast(
80
+ str,
81
+ bump_type_selector
82
+ or click.prompt(f"* Bump {package}@{version} -> {BumpTypesPrompt}"),
83
+ )
84
+ if bump_type_selector == "s":
85
return None
86
87
try:
78
- bump_type = BumpType(BumpTypes[bump_type_input])
88
+ _bump_type = BumpType(BumpTypes[bump_type_selector])
89
except (ValueError, KeyError) as e:
90
raise click.ClickException(f"Invalid bump type: {e}")
81
- return str(_get_bumped_version(current=current_version, bump_type=bump_type))
91
+
92
+ return str(_get_bumped_version(current=current_version, bump_type=_bump_type))
93
94
84
-def _bump_setup_py(file: Path):
95
+def _bump_setup_py(file: Path, bump_type: t.Optional[str] = None):
96
# Load config
97
content = file.read_text(encoding="utf-8")
98
_, _, arguments = content.partition("setup(")
@@ -107,17 +118,21 @@ def _bump_setup_py(file: Path):
118
raise ValueError(f"Package or version not found in {file}")
119
120
# Bump version
110
- next_version = _get_version_update(package=package, version=version)
121
+ next_version = _get_version_update(
122
+ package=package,
123
+ version=version,
124
+ bump_type_selector=bump_type,
125
+ )
126
if next_version is None:
127
click.echo(f"* Skipping {package}")
128
return
129
115
- click.echo(f"* Bumping {package} -> {next_version}")
130
+ click.echo(f"* Bumping {package} {version} -> {next_version}")
131
content = content.replace(f'version="{version}"', f'version="{next_version}"')
132
file.write_text(content, encoding="utf-8")
133
134
120
-def _bump_pyproject_toml(file: Path):
135
+def _bump_pyproject_toml(file: Path, bump_type: t.Optional[str] = None):
136
# Load config
137
content = file.read_text(encoding="utf-8")
138
config = tomli.loads(content)
@@ -128,27 +143,39 @@ def _bump_pyproject_toml(file: Path):
143
version = project["version"]
144
145
# Bump version
131
- next_version = _get_version_update(package=package, version=version)
146
+ next_version = _get_version_update(
147
+ package=package,
148
+ version=version,
149
+ bump_type_selector=bump_type,
150
+ )
151
if next_version is None:
152
click.echo(f"* Skipping {package}")
153
return
154
136
- click.echo(f"* Bumping {package} -> {next_version}")
155
+ click.echo(f"* Bumping {package} {version} -> {next_version}")
156
content = content.replace(f'version = "{version}"', f'version = "{next_version}"')
157
file.write_text(content, encoding="utf-8")
158
159
141
-def _bump_package(file: Path):
160
+def _bump_package(file: Path, bump_type: t.Optional[str] = None):
161
if file.name == PYPROJECT:
143
- return _bump_pyproject_toml(file=file)
144
- return _bump_setup_py(file=file)
162
+ return _bump_pyproject_toml(file=file, bump_type=bump_type)
163
+ return _bump_setup_py(file=file, bump_type=bump_type)
164
165
166
@click.command("bump")
148
-def bump():
167
+@click.option("--pre", "bump_type", flag_value="c")
168
+@click.option("--post", "bump_type", flag_value="b")
169
+@click.option("--patch", "bump_type", flag_value="p")
170
+@click.option("--minor", "bump_type", flag_value="m")
171
+@click.option("--major", "bump_type", flag_value="M")
172
+def bump(bump_type: t.Optional[str]):
173
packages = _find_packages()
174
for package in packages:
151
- _bump_package(file=package)
175
+ try:
176
+ _bump_package(file=package, bump_type=bump_type)
177
+ except Exception as e:
178
+ raise e.__class__(f"Error bumping {package}")
179
180
181
if __name__ == "__main__":