Skip to content

Commit 775f0de

Browse files
committed
fmt
1 parent 80e09bd commit 775f0de

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

scripts/bump_version.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,79 @@
22

33
import argparse
44
import re
5-
from pathlib import Path
65
from datetime import datetime
6+
from pathlib import Path
7+
78
import tomli
89
import tomli_w
910

11+
1012
def read_toml(file_path: Path) -> dict:
1113
"""Read and parse a TOML file."""
1214
with open(file_path, "rb") as f:
1315
return tomli.load(f)
1416

17+
1518
def write_toml(file_path: Path, data: dict) -> None:
1619
"""Write data to a TOML file."""
1720
with open(file_path, "wb") as f:
1821
tomli_w.dump(data, f)
1922

23+
2024
def bump_version(current_version: str, bump_type: str) -> str:
2125
"""Bump the version number based on semver rules."""
22-
major, minor, patch = map(int, current_version.split('.'))
23-
26+
major, minor, patch = map(int, current_version.split("."))
27+
2428
if bump_type == "major":
2529
return f"{major + 1}.0.0"
2630
elif bump_type == "minor":
2731
return f"{major}.{minor + 1}.0"
2832
else: # patch
2933
return f"{major}.{minor}.{patch + 1}"
3034

35+
3136
def update_pyproject_toml(file_path: Path, new_version: str) -> None:
3237
"""Update version in pyproject.toml."""
3338
data = read_toml(file_path)
3439
data["project"]["version"] = new_version
3540
write_toml(file_path, data)
3641

42+
3743
def update_server_py(file_path: Path, new_version: str) -> None:
3844
"""Update version in server.py."""
3945
content = file_path.read_text()
4046
# Update version pattern in server.py
4147
new_content = re.sub(
42-
r'__version__\s*=\s*["\'][\d.]+["\']',
43-
f'__version__ = "{new_version}"',
44-
content
48+
r'__version__\s*=\s*["\'][\d.]+["\']', f'__version__ = "{new_version}"', content
4549
)
4650
file_path.write_text(new_content)
4751

52+
4853
def update_changelog(file_path: Path, new_version: str) -> None:
4954
"""Update CHANGELOG.md with new version."""
5055
content = file_path.read_text()
5156
today = datetime.now().strftime("%Y-%m-%d")
5257
new_entry = f"\n## [{new_version}] - {today}\n\n"
53-
58+
5459
if "# Changelog" in content:
5560
# Insert after the first line containing "# Changelog"
5661
parts = content.split("# Changelog", 1)
5762
content = parts[0] + "# Changelog" + new_entry + parts[1]
5863
else:
5964
# If no Changelog header exists, add it
6065
content = f"# Changelog\n{new_entry}\n{content}"
61-
66+
6267
file_path.write_text(content)
6368

69+
6470
def main():
6571
parser = argparse.ArgumentParser(description="Bump version numbers in the project")
6672
parser.add_argument(
6773
"bump_type",
6874
nargs="?",
6975
choices=["major", "minor", "patch"],
7076
default="minor",
71-
help="Type of version bump (default: minor)"
77+
help="Type of version bump (default: minor)",
7278
)
7379
args = parser.parse_args()
7480

@@ -78,20 +84,21 @@ def main():
7884
# Read current version from pyproject.toml
7985
pyproject_path = root_dir / "pyproject.toml"
8086
current_version = read_toml(pyproject_path)["project"]["version"]
81-
87+
8288
# Calculate new version
8389
new_version = bump_version(current_version, args.bump_type)
84-
90+
8591
# Update files
8692
update_pyproject_toml(pyproject_path, new_version)
8793
update_server_py(root_dir / "src" / "semgrep_mcp" / "server.py", new_version)
8894
update_changelog(root_dir / "CHANGELOG.md", new_version)
89-
95+
9096
print(f"Successfully bumped version from {current_version} to {new_version}")
9197
print("Files updated:")
9298
print("- pyproject.toml")
9399
print("- src/semgrep_mcp/server.py")
94100
print("- CHANGELOG.md")
95101

102+
96103
if __name__ == "__main__":
97-
main()
104+
main()

src/semgrep_mcp/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def remove_temp_dir_from_results(results: SemgrepScanResult, temp_dir: str) -> N
406406
# Create a fast MCP server
407407
mcp = FastMCP(
408408
"Semgrep",
409-
version=VERSION,
409+
version=__version__,
410410
request_timeout=DEFAULT_TIMEOUT,
411411
)
412412

@@ -663,7 +663,7 @@ async def get_abstract_syntax_tree(
663663

664664

665665
@click.command()
666-
@click.version_option(version=VERSION, prog_name="Semgrep MCP Server")
666+
@click.version_option(version=__version__, prog_name="Semgrep MCP Server")
667667
@click.option(
668668
"-t",
669669
"--transport",

0 commit comments

Comments
 (0)