MCPcopy Index your code
hub / github.com/AstrBotDevs/AstrBot / update_package_version

Function update_package_version

scripts/prepare_release.py:196–224  ·  view source on GitHub ↗

Update the package version in astrbot/__init__.py. Args: version: Release version to write. Returns: Path to the modified astrbot/__init__.py file. Raises: ReleaseError: The package version constant cannot be found or parsed.

(version: str)

Source from the content-addressed store, hash-verified

194
195
196def update_package_version(version: str) -> Path:
197 """Update the package version in astrbot/__init__.py.
198
199 Args:
200 version: Release version to write.
201
202 Returns:
203 Path to the modified astrbot/__init__.py file.
204
205 Raises:
206 ReleaseError: The package version constant cannot be found or parsed.
207 """
208 package_init_path = REPO_ROOT / "astrbot" / "__init__.py"
209 lines = package_init_path.read_text(encoding="utf-8").splitlines(keepends=True)
210
211 for index, line in enumerate(lines):
212 match = re.match(
213 r"^(\s*__version__\s*=\s*)([\"'])(.*?)(\2)(\s*(?:#.*)?)(\n?)$",
214 line,
215 )
216 if not match:
217 continue
218
219 prefix, quote, _current, _closing_quote, suffix, newline = match.groups()
220 lines[index] = f"{prefix}{quote}{version}{quote}{suffix}{newline}"
221 package_init_path.write_text("".join(lines), encoding="utf-8")
222 return package_init_path
223
224 raise ReleaseError("Missing __version__ in astrbot/__init__.py")
225
226
227def write_changelog(version: str, commits: list[str]) -> Path:

Callers 1

mainFunction · 0.85

Calls 4

ReleaseErrorClass · 0.85
write_textMethod · 0.80
read_textMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected