Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

chore: add global bumpflag in bump.py

angrybaybladecab688df2061
diff --git a/python/scripts/bump.py b/python/scripts/bump.py
index 67245d3d5..833c3eb30 100644
--- a/python/scripts/bump.py
+++ b/python/scripts/bump.py
@@ -8,7 +8,7 @@ import tomli
from semver import VersionInfo
CWD = Path.cwd()
-SKIPDIR = (".venv",)
+SKIPDIR = (".venv", ".nox", ".tox")
PYPROJECT = "pyproject.toml"
SETUP = "setup.py"
@@ -16,8 +16,8 @@ BumpTypes = {
"M": "major",
"m": "minor",
"p": "patch",
- "c": "pre",
"b": "post",
+ "c": "pre",
"s": "skip",
}
BumpTypesPrompt = " | ".join([f"{k}-{v.title()}" for k, v in BumpTypes.items()])
@@ -60,8 +60,15 @@ def _find_packages():
return files
-def _get_version_update(package: str, version: str) -> t.Optional[str]:
+def _get_version_update(
+ package: str,
+ version: str,
+ bump_type_selector: t.Optional[str] = None,
+) -> t.Optional[str]:
pre = None
+ if "-" in version:
+ version, pre = version.split("-", maxsplit=1)
+
if "rc" in version:
version, marker, number = version.partition("rc")
pre = f"{marker}{number}"
@@ -69,19 +76,23 @@ def _get_version_update(package: str, version: str) -> t.Optional[str]:
# TODO: Add support for post builds
current_version = VersionInfo.parse(version=version)
current_version._prerelease = pre
-
- bump_type_input = click.prompt(f"* Bump {package}@{version} -> {BumpTypesPrompt}")
- if bump_type_input == "s":
+ bump_type_selector = t.cast(
+ str,
+ bump_type_selector
+ or click.prompt(f"* Bump {package}@{version} -> {BumpTypesPrompt}"),
+ )
+ if bump_type_selector == "s":
return None
try:
- bump_type = BumpType(BumpTypes[bump_type_input])
+ _bump_type = BumpType(BumpTypes[bump_type_selector])
except (ValueError, KeyError) as e:
raise click.ClickException(f"Invalid bump type: {e}")
- return str(_get_bumped_version(current=current_version, bump_type=bump_type))
+
+ return str(_get_bumped_version(current=current_version, bump_type=_bump_type))
-def _bump_setup_py(file: Path):
+def _bump_setup_py(file: Path, bump_type: t.Optional[str] = None):
# Load config
content = file.read_text(encoding="utf-8")
_, _, arguments = content.partition("setup(")
@@ -107,17 +118,21 @@ def _bump_setup_py(file: Path):
raise ValueError(f"Package or version not found in {file}")
# Bump version
- next_version = _get_version_update(package=package, version=version)
+ next_version = _get_version_update(
+ package=package,
+ version=version,
+ bump_type_selector=bump_type,
+ )
if next_version is None:
click.echo(f"* Skipping {package}")
return
- click.echo(f"* Bumping {package} -> {next_version}")
+ click.echo(f"* Bumping {package} {version} -> {next_version}")
content = content.replace(f'version="{version}"', f'version="{next_version}"')
file.write_text(content, encoding="utf-8")
-def _bump_pyproject_toml(file: Path):
+def _bump_pyproject_toml(file: Path, bump_type: t.Optional[str] = None):
# Load config
content = file.read_text(encoding="utf-8")
config = tomli.loads(content)
@@ -128,27 +143,39 @@ def _bump_pyproject_toml(file: Path):
version = project["version"]
# Bump version
- next_version = _get_version_update(package=package, version=version)
+ next_version = _get_version_update(
+ package=package,
+ version=version,
+ bump_type_selector=bump_type,
+ )
if next_version is None:
click.echo(f"* Skipping {package}")
return
- click.echo(f"* Bumping {package} -> {next_version}")
+ click.echo(f"* Bumping {package} {version} -> {next_version}")
content = content.replace(f'version = "{version}"', f'version = "{next_version}"')
file.write_text(content, encoding="utf-8")
-def _bump_package(file: Path):
+def _bump_package(file: Path, bump_type: t.Optional[str] = None):
if file.name == PYPROJECT:
- return _bump_pyproject_toml(file=file)
- return _bump_setup_py(file=file)
+ return _bump_pyproject_toml(file=file, bump_type=bump_type)
+ return _bump_setup_py(file=file, bump_type=bump_type)
@click.command("bump")
-def bump():
[email protected]("--pre", "bump_type", flag_value="c")
[email protected]("--post", "bump_type", flag_value="b")
[email protected]("--patch", "bump_type", flag_value="p")
[email protected]("--minor", "bump_type", flag_value="m")
[email protected]("--major", "bump_type", flag_value="M")
+def bump(bump_type: t.Optional[str]):
packages = _find_packages()
for package in packages:
- _bump_package(file=package)
+ try:
+ _bump_package(file=package, bump_type=bump_type)
+ except Exception as e:
+ raise e.__class__(f"Error bumping {package}")
if __name__ == "__main__":