py-wlcli 0.8.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py_wlcli-0.8.0.dist-info/METADATA +139 -0
- py_wlcli-0.8.0.dist-info/RECORD +320 -0
- py_wlcli-0.8.0.dist-info/WHEEL +4 -0
- py_wlcli-0.8.0.dist-info/entry_points.txt +2 -0
- py_wlcli-0.8.0.dist-info/licenses/LICENSE +21 -0
- wl_cli/__init__.py +27 -0
- wl_cli/__main__.py +130 -0
- wl_cli/capabilities.py +79 -0
- wl_cli/cc/__init__.py +5 -0
- wl_cli/cc/checks.py +1019 -0
- wl_cli/cc/cli.py +370 -0
- wl_cli/cc/mutate.py +1350 -0
- wl_cli/cli_click.py +156 -0
- wl_cli/commands/__init__.py +84 -0
- wl_cli/commands/base.py +80 -0
- wl_cli/commands/buildcommands/__init__.py +1 -0
- wl_cli/commands/buildcommands/build.py +71 -0
- wl_cli/commands/buildcommands/build_utils.py +47 -0
- wl_cli/commands/buildcommands/builders/__init__.py +18 -0
- wl_cli/commands/buildcommands/builders/cleanup.py +35 -0
- wl_cli/commands/buildcommands/builders/coordinator.py +122 -0
- wl_cli/commands/buildcommands/builders/environment.py +81 -0
- wl_cli/commands/buildcommands/builders/rust_builder.py +39 -0
- wl_cli/commands/buildcommands/builders/stubs.py +58 -0
- wl_cli/commands/buildcommands/dist.py +326 -0
- wl_cli/commands/buildcommands/test.py +89 -0
- wl_cli/commands/clean/__init__.py +1 -0
- wl_cli/commands/clean/build.py +151 -0
- wl_cli/commands/clean/clean.py +294 -0
- wl_cli/commands/clean/clean_utils.py +77 -0
- wl_cli/commands/clean/core.py +236 -0
- wl_cli/commands/clean/dead_code/__init__.py +0 -0
- wl_cli/commands/clean/dead_code/dead_code_command.py +70 -0
- wl_cli/commands/clean/dead_code/detector.py +161 -0
- wl_cli/commands/clean/dead_code/fixer.py +176 -0
- wl_cli/commands/clean/dead_code/reporter.py +295 -0
- wl_cli/commands/clean/dead_code/utils.py +0 -0
- wl_cli/commands/clean/lfs.py +215 -0
- wl_cli/commands/clean/python.py +81 -0
- wl_cli/commands/clean/rust.py +91 -0
- wl_cli/commands/clean/utils/__init__.py +34 -0
- wl_cli/commands/clean/venv.py +91 -0
- wl_cli/commands/cleanup.py +73 -0
- wl_cli/commands/click_base.py +79 -0
- wl_cli/commands/config/__init__.py +1 -0
- wl_cli/commands/config/config.py +291 -0
- wl_cli/commands/debug/__init__.py +6 -0
- wl_cli/commands/debug/debug.py +309 -0
- wl_cli/commands/debug/debug_cache.py +86 -0
- wl_cli/commands/debug/debug_subagent.py +156 -0
- wl_cli/commands/debug/output_formatter.py +165 -0
- wl_cli/commands/debug/source_hasher.py +92 -0
- wl_cli/commands/format/__init__.py +13 -0
- wl_cli/commands/format/format_cache_adapter.py +125 -0
- wl_cli/commands/format/format_command.py +197 -0
- wl_cli/commands/format/format_coordinator.py +191 -0
- wl_cli/commands/format/format_executor.py +470 -0
- wl_cli/commands/format/format_outcome.py +44 -0
- wl_cli/commands/format/format_path_handler.py +1016 -0
- wl_cli/commands/format/format_progress.py +62 -0
- wl_cli/commands/format/format_reporter.py +31 -0
- wl_cli/commands/format/python_formatter.py +506 -0
- wl_cli/commands/format/rust_formatter.py +106 -0
- wl_cli/commands/gate/__init__.py +1 -0
- wl_cli/commands/gate/gate_command.py +862 -0
- wl_cli/commands/gate/preflight.py +445 -0
- wl_cli/commands/git/__init__.py +1 -0
- wl_cli/commands/git/config.py +169 -0
- wl_cli/commands/git/git_facts.py +60 -0
- wl_cli/commands/git/git_flow.py +86 -0
- wl_cli/commands/git/hook.py +112 -0
- wl_cli/commands/git/policy.py +216 -0
- wl_cli/commands/git/push_update.py +82 -0
- wl_cli/commands/initenv/__init__.py +1 -0
- wl_cli/commands/initenv/common/__init__.py +23 -0
- wl_cli/commands/initenv/common/check_git_bash.py +78 -0
- wl_cli/commands/initenv/common/error_handler.py +68 -0
- wl_cli/commands/initenv/common/exceptions.py +52 -0
- wl_cli/commands/initenv/components/__init__.py +4 -0
- wl_cli/commands/initenv/components/cargo_sync.py +240 -0
- wl_cli/commands/initenv/components/config_manager.py +106 -0
- wl_cli/commands/initenv/components/directory_utils.py +71 -0
- wl_cli/commands/initenv/components/git/__init__.py +9 -0
- wl_cli/commands/initenv/components/git/branch_creator.py +143 -0
- wl_cli/commands/initenv/components/git/git_flow_interface.py +24 -0
- wl_cli/commands/initenv/components/git/git_flow_manager.py +159 -0
- wl_cli/commands/initenv/components/git/git_lfs_manager.py +272 -0
- wl_cli/commands/initenv/components/git/git_utility.py +254 -0
- wl_cli/commands/initenv/components/git/gitignore_manager.py +53 -0
- wl_cli/commands/initenv/components/git_initializer.py +212 -0
- wl_cli/commands/initenv/components/i18n_manager.py +104 -0
- wl_cli/commands/initenv/components/log_manager.py +241 -0
- wl_cli/commands/initenv/components/project_structure/__init__.py +23 -0
- wl_cli/commands/initenv/components/project_structure/config_generator.py +360 -0
- wl_cli/commands/initenv/components/project_structure/directory_creator.py +184 -0
- wl_cli/commands/initenv/components/project_structure/hook_source.py +110 -0
- wl_cli/commands/initenv/components/project_structure/hooks_manager.py +995 -0
- wl_cli/commands/initenv/components/project_structure/readme_handler.py +56 -0
- wl_cli/commands/initenv/components/project_structure/rust_files_handler.py +30 -0
- wl_cli/commands/initenv/components/project_structure/setup_handler.py +103 -0
- wl_cli/commands/initenv/components/project_structure/sop_generator.py +73 -0
- wl_cli/commands/initenv/components/project_structure/template_copier.py +104 -0
- wl_cli/commands/initenv/components/project_structure/template_manager.py +195 -0
- wl_cli/commands/initenv/components/pyproject_generator.py +194 -0
- wl_cli/commands/initenv/components/rust_initializer.py +145 -0
- wl_cli/commands/initenv/components/symlink_cleaner.py +99 -0
- wl_cli/commands/initenv/components/symlink_manager.py +52 -0
- wl_cli/commands/initenv/components/venv_manager.py +118 -0
- wl_cli/commands/initenv/initenv.py +169 -0
- wl_cli/commands/initenv/services/__init__.py +11 -0
- wl_cli/commands/initenv/services/environment_initializer.py +288 -0
- wl_cli/commands/initenv/services/git_lfs_initializer.py +26 -0
- wl_cli/commands/initenv/services/project_structure_initializer.py +52 -0
- wl_cli/commands/lfs/README.md +221 -0
- wl_cli/commands/lfs/__init__.py +5 -0
- wl_cli/commands/lfs/cli.py +106 -0
- wl_cli/commands/lfs/config.py +164 -0
- wl_cli/commands/lfs/hook.py +61 -0
- wl_cli/commands/lfs/initializer.py +531 -0
- wl_cli/commands/lfs/manager.py +95 -0
- wl_cli/commands/lfs/policy.py +165 -0
- wl_cli/commands/lfs/watcher.py +294 -0
- wl_cli/commands/lint/__init__.py +1 -0
- wl_cli/commands/lint/lint_command.py +297 -0
- wl_cli/commands/lint/lint_executor.py +409 -0
- wl_cli/commands/lint/lint_reporter.py +579 -0
- wl_cli/commands/lint/lint_run.py +258 -0
- wl_cli/commands/lint/mypy_config.py +90 -0
- wl_cli/commands/registry.py +103 -0
- wl_cli/commands/self/__init__.py +7 -0
- wl_cli/commands/self/common/__init__.py +8 -0
- wl_cli/commands/self/common/capabilities.py +30 -0
- wl_cli/commands/self/common/config.py +27 -0
- wl_cli/commands/self/common/version_cache.py +85 -0
- wl_cli/commands/self/handlers/__init__.py +19 -0
- wl_cli/commands/self/handlers/base_handler.py +28 -0
- wl_cli/commands/self/handlers/install_handler.py +85 -0
- wl_cli/commands/self/handlers/status_handler.py +66 -0
- wl_cli/commands/self/handlers/uninstall_handler.py +58 -0
- wl_cli/commands/self/handlers/update_handler.py +102 -0
- wl_cli/commands/self/handlers/version_handler.py +16 -0
- wl_cli/commands/self/self_command.py +237 -0
- wl_cli/commands/self/services/__init__.py +15 -0
- wl_cli/commands/self/services/installation_manager.py +187 -0
- wl_cli/commands/self/services/local_installer.py +165 -0
- wl_cli/commands/self/services/pypi_updater.py +278 -0
- wl_cli/commands/self/services/windows_update.py +174 -0
- wl_cli/commands/testcommands/__init__.py +8 -0
- wl_cli/commands/testcommands/base_dependency_analyzer.py +198 -0
- wl_cli/commands/testcommands/batch_processor.py +278 -0
- wl_cli/commands/testcommands/cache_manager.py +1156 -0
- wl_cli/commands/testcommands/coverage_analyzer.py +955 -0
- wl_cli/commands/testcommands/coverage_cache_manager.py +183 -0
- wl_cli/commands/testcommands/progress_manager.py +79 -0
- wl_cli/commands/testcommands/python_env_detector.py +207 -0
- wl_cli/commands/testcommands/report_generator.py +101 -0
- wl_cli/commands/testcommands/single_test_executor.py +250 -0
- wl_cli/commands/testcommands/speed_checker.py +118 -0
- wl_cli/commands/testcommands/test_command_builder.py +165 -0
- wl_cli/commands/testcommands/test_commands.py +786 -0
- wl_cli/commands/testcommands/test_reporter.py +181 -0
- wl_cli/commands/testcommands/test_result_handler.py +96 -0
- wl_cli/commands/testcommands/test_runner.py +1343 -0
- wl_cli/commands/testcommands/test_utils.py +197 -0
- wl_cli/commands/testcommands/utils/__init__.py +17 -0
- wl_cli/commands/testcommands/utils/coverage_parser.py +98 -0
- wl_cli/commands/testcommands/utils/env_info.py +36 -0
- wl_cli/commands/testcommands/utils/junit_parser.py +75 -0
- wl_cli/commands/testcommands/utils/markdown_utils.py +20 -0
- wl_cli/commands/testcommands/utils/project_root.py +61 -0
- wl_cli/commands/update/__init__.py +9 -0
- wl_cli/commands/update/services/__init__.py +21 -0
- wl_cli/commands/update/services/backup_manager.py +207 -0
- wl_cli/commands/update/services/component_manager.py +83 -0
- wl_cli/commands/update/services/conflict_resolver.py +189 -0
- wl_cli/commands/update/services/vendors_updater.py +85 -0
- wl_cli/commands/update/services/version_tracker.py +127 -0
- wl_cli/commands/update/update_command.py +270 -0
- wl_cli/commands/update/utils/__init__.py +3 -0
- wl_cli/commands/version/__init__.py +9 -0
- wl_cli/commands/version/version_command.py +155 -0
- wl_cli/commands/workflow.py +477 -0
- wl_cli/env/__init__.py +5 -0
- wl_cli/env/cli.py +167 -0
- wl_cli/env_status.py +157 -0
- wl_cli/envelope.py +91 -0
- wl_cli/exceptions.py +85 -0
- wl_cli/lib/__init__.py +3 -0
- wl_cli/lib/rust_utils.py +35 -0
- wl_cli/mcp/__init__.py +6 -0
- wl_cli/mcp/capabilities.py +19 -0
- wl_cli/mcp/cli.py +22 -0
- wl_cli/mcp/gitlab.py +553 -0
- wl_cli/mcp/k8s.py +344 -0
- wl_cli/mcp/protocol.py +159 -0
- wl_cli/platform.py +139 -0
- wl_cli/quality/__init__.py +18 -0
- wl_cli/utils/__init__.py +7 -0
- wl_cli/utils/cache.py +491 -0
- wl_cli/utils/cache_ledger.py +355 -0
- wl_cli/utils/cache_store.py +546 -0
- wl_cli/utils/config/__init__.py +27 -0
- wl_cli/utils/config/config_loader.py +163 -0
- wl_cli/utils/config/core.py +862 -0
- wl_cli/utils/config/defaults.py +142 -0
- wl_cli/utils/config/env_exporter.py +86 -0
- wl_cli/utils/config/env_parser.py +108 -0
- wl_cli/utils/config/validation.py +280 -0
- wl_cli/utils/error_handler.py +165 -0
- wl_cli/utils/file_copier.py +56 -0
- wl_cli/utils/file_operations.py +506 -0
- wl_cli/utils/language_utils.py +122 -0
- wl_cli/utils/lazy_import.py +240 -0
- wl_cli/utils/log_levels.py +35 -0
- wl_cli/utils/log_rotators.py +74 -0
- wl_cli/utils/logging.py +458 -0
- wl_cli/utils/output_context.py +142 -0
- wl_cli/utils/performance/__init__.py +1 -0
- wl_cli/utils/performance/decorators.py +111 -0
- wl_cli/utils/performance/exporter.py +38 -0
- wl_cli/utils/performance/models.py +16 -0
- wl_cli/utils/performance/monitor.py +161 -0
- wl_cli/utils/performance_monitor.py +32 -0
- wl_cli/utils/platform_adapter.py +131 -0
- wl_cli/utils/pre_commit.py +266 -0
- wl_cli/utils/pre_commit_config.py +72 -0
- wl_cli/utils/root.py +521 -0
- wl_cli/utils/root_fallback.py +256 -0
- wl_cli/utils/run_evidence.py +236 -0
- wl_cli/utils/structured_logger.py +18 -0
- wl_cli/utils/structured_logging/__init__.py +19 -0
- wl_cli/utils/structured_logging/config.py +337 -0
- wl_cli/utils/structured_logging/core.py +177 -0
- wl_cli/utils/structured_logging/env.py +56 -0
- wl_cli/utils/structured_logging/filtering.py +75 -0
- wl_cli/utils/structured_logging/filters.py +55 -0
- wl_cli/utils/structured_logging/formatters.py +251 -0
- wl_cli/utils/structured_logging/handlers.py +308 -0
- wl_cli/utils/structured_logging/logger.py +354 -0
- wl_cli/utils/subprocess.py +71 -0
- wl_cli/utils/subprocess_utils.py +260 -0
- wl_cli/utils/test_utils/__init__.py +5 -0
- wl_cli/utils/test_utils/test_filter.py +36 -0
- wl_cli/utils/uv_run.py +79 -0
- wl_cli/utils/uv_tool.py +117 -0
- wl_cli/utils/uv_tree.py +71 -0
- wl_cli/utils/uv_workspace.py +174 -0
- wl_cli/utils/version/__init__.py +15 -0
- wl_cli/utils/version/pypi_version_checker.py +95 -0
- wl_cli/utils/version/version_comparator.py +133 -0
- wl_cli/utils/version/version_detectors.py +312 -0
- wl_cli/utils/version/version_service.py +131 -0
- wl_cli/utils/version/version_updater.py +198 -0
- wl_cli/utils/wl_dir_updater.py +1440 -0
- wl_cli/utils/workspace_detector/__init__.py +28 -0
- wl_cli/utils/workspace_detector/core.py +161 -0
- wl_cli/utils/workspace_detector/detection_strategies.py +107 -0
- wl_cli/utils/workspace_detector/exceptions.py +5 -0
- wl_cli/utils/workspace_detector/types.py +17 -0
- wl_cli/utils/workspace_detector/venv_resolver.py +84 -0
- wl_cli/vendors/config/.codespellrc +2 -0
- wl_cli/vendors/config/dependencies.toml +10 -0
- wl_cli/vendors/config/mypy.ini +62 -0
- wl_cli/vendors/config/pyproject_defaults.toml +28 -0
- wl_cli/vendors/config/template_config.toml +24 -0
- wl_cli/vendors/config/tool_configs.toml +76 -0
- wl_cli/vendors/git/.gitignore +122 -0
- wl_cli/vendors/git/.pre-commit-config.yaml +37 -0
- wl_cli/vendors/hooks/applypatch-msg.sample +15 -0
- wl_cli/vendors/hooks/commit-msg.sample +24 -0
- wl_cli/vendors/hooks/fsmonitor-watchman.sample +174 -0
- wl_cli/vendors/hooks/post-update.sample +8 -0
- wl_cli/vendors/hooks/pre-applypatch.sample +14 -0
- wl_cli/vendors/hooks/pre-commit +45 -0
- wl_cli/vendors/hooks/pre-commit.legacy +31 -0
- wl_cli/vendors/hooks/pre-commit.sample +49 -0
- wl_cli/vendors/hooks/pre-merge-commit.sample +13 -0
- wl_cli/vendors/hooks/pre-push.sample +60 -0
- wl_cli/vendors/hooks/pre-rebase.sample +169 -0
- wl_cli/vendors/hooks/pre-receive.sample +24 -0
- wl_cli/vendors/hooks/prepare-commit-msg.sample +42 -0
- wl_cli/vendors/hooks/push-to-checkout.sample +78 -0
- wl_cli/vendors/hooks/sendemail-validate.sample +77 -0
- wl_cli/vendors/hooks/unix/applypatch-msg.sample +15 -0
- wl_cli/vendors/hooks/unix/check_lockfile.py +58 -0
- wl_cli/vendors/hooks/unix/check_lockfile.sh +36 -0
- wl_cli/vendors/hooks/unix/commit-msg.sample +24 -0
- wl_cli/vendors/hooks/unix/fsmonitor-watchman.sample +174 -0
- wl_cli/vendors/hooks/unix/post-update.sample +8 -0
- wl_cli/vendors/hooks/unix/pre-applypatch.sample +14 -0
- wl_cli/vendors/hooks/unix/pre-commit +190 -0
- wl_cli/vendors/hooks/unix/pre-commit.legacy +31 -0
- wl_cli/vendors/hooks/unix/pre-commit.py +81 -0
- wl_cli/vendors/hooks/unix/pre-commit.sample +49 -0
- wl_cli/vendors/hooks/unix/pre-merge-commit.sample +13 -0
- wl_cli/vendors/hooks/unix/pre-push +417 -0
- wl_cli/vendors/hooks/unix/pre-push.sample +53 -0
- wl_cli/vendors/hooks/unix/pre-rebase.sample +169 -0
- wl_cli/vendors/hooks/unix/pre-receive.sample +24 -0
- wl_cli/vendors/hooks/unix/prepare-commit-msg.sample +42 -0
- wl_cli/vendors/hooks/update.sample +128 -0
- wl_cli/vendors/hooks/win/work.bat +63 -0
- wl_cli/vendors/project/.gitignore +90 -0
- wl_cli/vendors/project/.python-version +1 -0
- wl_cli/vendors/project/LICENSE +21 -0
- wl_cli/vendors/project/README.md +0 -0
- wl_cli/vendors/project/pyproject.toml +27 -0
- wl_cli/vendors/project/pyproject_no_workspace.toml +16 -0
- wl_cli/vendors/project/pyproject_workspace.toml +14 -0
- wl_cli/vendors/readme/README.md +120 -0
- wl_cli/vendors/rust/Cargo.toml +14 -0
- wl_cli/vendors/rust/lib/__init__.py +3 -0
- wl_cli/vendors/rust/lib/rust_utils.py +31 -0
- wl_cli/vendors/rust/src/lib.rs +13 -0
- wl_cli/vendors/rust/src/main.rs +3 -0
- wl_cli/vendors/rust/tests/test_rust_fallback.py +40 -0
- wl_cli/vendors/sop_doc/git-dev-sop.md +220 -0
- wl_cli/vendors/sop_doc/industrial-standard-sop.md +145 -0
- wl_cli/vendors/sop_doc/python-sop.md +342 -0
- wl_cli/vendors/sop_doc/rust-readme.md +219 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Version updating utilities for publish command.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from ...exceptions import CommandError
|
|
9
|
+
from ..logging import log_info, log_info_pair
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class VersionUpdater:
|
|
13
|
+
"""Update versions in project files."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, project_root: Path | None = None):
|
|
16
|
+
"""Initialize VersionUpdater with optional project root."""
|
|
17
|
+
self.project_root = project_root or self._resolve_project_root()
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
def _resolve_project_root() -> Path:
|
|
21
|
+
current_path = Path.cwd().resolve()
|
|
22
|
+
for path in (current_path, *current_path.parents):
|
|
23
|
+
if (path / "pyproject.toml").is_file() or (path / "VERSION").is_file():
|
|
24
|
+
return path
|
|
25
|
+
|
|
26
|
+
package_path = Path(__file__).resolve()
|
|
27
|
+
for path in package_path.parents:
|
|
28
|
+
if (path / "pyproject.toml").is_file() or (path / "VERSION").is_file():
|
|
29
|
+
return path
|
|
30
|
+
|
|
31
|
+
return current_path
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def _safe_replace(content, pattern, new_version):
|
|
35
|
+
"""Safely replace version in content without interpreting numbers as group references."""
|
|
36
|
+
|
|
37
|
+
def replace_match(match):
|
|
38
|
+
return f"{match.group(1)}{new_version}{match.group(3)}"
|
|
39
|
+
|
|
40
|
+
return re.sub(pattern, replace_match, content)
|
|
41
|
+
|
|
42
|
+
def _update_version_file(self, new_version: str) -> None:
|
|
43
|
+
"""Update the VERSION file with a specific version."""
|
|
44
|
+
version_file = self.project_root / "VERSION"
|
|
45
|
+
try:
|
|
46
|
+
version_file.write_text(f"{new_version}\n", encoding="utf-8")
|
|
47
|
+
log_info(f"Updated VERSION file to {new_version}")
|
|
48
|
+
except Exception as e:
|
|
49
|
+
raise CommandError(f"Failed to update VERSION file: {e}")
|
|
50
|
+
|
|
51
|
+
def _update_python_version(self, new_version: str) -> None:
|
|
52
|
+
"""Update the Python __init__.py file with a specific version."""
|
|
53
|
+
python_version_file = self.project_root / "src" / "wl_cli" / "__init__.py"
|
|
54
|
+
if python_version_file.exists():
|
|
55
|
+
try:
|
|
56
|
+
content = python_version_file.read_text(encoding="utf-8")
|
|
57
|
+
# Check if the file uses the new VERSION file pattern (which it should)
|
|
58
|
+
# We don't need to modify it since it reads from VERSION file
|
|
59
|
+
# But we'll maintain backward compatibility for old format
|
|
60
|
+
if "__version__ = " in content:
|
|
61
|
+
if "_read_version_from_file" not in content:
|
|
62
|
+
# Old format: directly replace the version string
|
|
63
|
+
version_pattern = (
|
|
64
|
+
r'(__version__\s*=\s*["\'])(\d+\.\d+\.\d+(?:\.\d+)?)(["\'])'
|
|
65
|
+
)
|
|
66
|
+
if re.search(version_pattern, content):
|
|
67
|
+
updated_content = self._safe_replace(
|
|
68
|
+
content, version_pattern, new_version
|
|
69
|
+
)
|
|
70
|
+
python_version_file.write_text(
|
|
71
|
+
updated_content, encoding="utf-8"
|
|
72
|
+
)
|
|
73
|
+
log_info(f"Updated Python version to {new_version}")
|
|
74
|
+
# else: no valid version pattern found, do nothing silently
|
|
75
|
+
else:
|
|
76
|
+
# New format: no need to modify, reads from VERSION file
|
|
77
|
+
log_info(
|
|
78
|
+
"Python __init__.py uses VERSION file, skipping update"
|
|
79
|
+
)
|
|
80
|
+
# else: no __version__ line found, do nothing silently
|
|
81
|
+
except Exception as e:
|
|
82
|
+
raise CommandError(f"Failed to update Python version: {e}")
|
|
83
|
+
|
|
84
|
+
@staticmethod
|
|
85
|
+
def _to_rust_version(version: str) -> str:
|
|
86
|
+
"""Convert a version string to Rust-compatible 3-part semver.
|
|
87
|
+
|
|
88
|
+
Rust/Cargo only supports MAJOR.MINOR.PATCH (3-part) semver.
|
|
89
|
+
If the input has 4 parts (e.g. 0.6.0.1), only the first 3 are used.
|
|
90
|
+
"""
|
|
91
|
+
parts = version.split(".")
|
|
92
|
+
return ".".join(parts[:3])
|
|
93
|
+
|
|
94
|
+
def _update_rust_version(self, new_version: str) -> None:
|
|
95
|
+
"""Update the Rust Cargo.toml file with a specific version.
|
|
96
|
+
|
|
97
|
+
Cargo.toml only supports 3-part semver (MAJOR.MINOR.PATCH),
|
|
98
|
+
so if new_version has 4 parts, only the first 3 are written.
|
|
99
|
+
"""
|
|
100
|
+
rust_version = self._to_rust_version(new_version)
|
|
101
|
+
rust_version_file = self.project_root / "rust" / "Cargo.toml"
|
|
102
|
+
if rust_version_file.exists():
|
|
103
|
+
try:
|
|
104
|
+
content = rust_version_file.read_text(encoding="utf-8")
|
|
105
|
+
# Find version pattern in [package] section and replace with Rust-compatible version
|
|
106
|
+
package_section_pattern = r'(\[package\][^\[]*version\s*=\s*["\'])(\d+\.\d+\.\d+(?:\.\d+)?)(["\'])'
|
|
107
|
+
updated_content = re.sub(
|
|
108
|
+
package_section_pattern,
|
|
109
|
+
lambda m: f"{m.group(1)}{rust_version}{m.group(3)}",
|
|
110
|
+
content,
|
|
111
|
+
flags=re.DOTALL,
|
|
112
|
+
)
|
|
113
|
+
rust_version_file.write_text(updated_content, encoding="utf-8")
|
|
114
|
+
log_info(f"Updated Rust version to {rust_version}")
|
|
115
|
+
if rust_version != new_version:
|
|
116
|
+
log_info(
|
|
117
|
+
f" (truncated from {new_version} for Cargo semver compatibility)"
|
|
118
|
+
)
|
|
119
|
+
except Exception as e:
|
|
120
|
+
raise CommandError(f"Failed to update Rust version: {e}")
|
|
121
|
+
|
|
122
|
+
def increment_version(
|
|
123
|
+
self, detector, comparator, pypi_checker=None, dry_run: bool = False
|
|
124
|
+
) -> None:
|
|
125
|
+
"""Increment the version to be greater than both local and PyPI versions.
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
detector: Version detector to get current version.
|
|
129
|
+
comparator: Version comparator to compare and increment versions.
|
|
130
|
+
pypi_checker: PyPI version checker (optional).
|
|
131
|
+
dry_run: Whether to perform a dry run without modifying files.
|
|
132
|
+
"""
|
|
133
|
+
log_info_pair(
|
|
134
|
+
"Checking versions and incrementing as needed...",
|
|
135
|
+
"正在检查版本并根据需要递增...",
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
# Get current PyPI version
|
|
139
|
+
pypi_version = None
|
|
140
|
+
if pypi_checker:
|
|
141
|
+
try:
|
|
142
|
+
pypi_version = pypi_checker._get_pypi_version()
|
|
143
|
+
except Exception:
|
|
144
|
+
# If getting PyPI version fails, use current version as base
|
|
145
|
+
pass
|
|
146
|
+
else:
|
|
147
|
+
# Backward compatibility: try to get PyPI version from detector
|
|
148
|
+
try:
|
|
149
|
+
if hasattr(detector, "_get_pypi_version"):
|
|
150
|
+
pypi_version = detector._get_pypi_version()
|
|
151
|
+
except Exception:
|
|
152
|
+
pass
|
|
153
|
+
if pypi_version:
|
|
154
|
+
log_info_pair(
|
|
155
|
+
f"Latest version on PyPI: {pypi_version}",
|
|
156
|
+
f"PyPI 上的最新版本: {pypi_version}",
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
# Get current local version
|
|
160
|
+
current_version = detector.get_current_version(comparator)
|
|
161
|
+
log_info_pair(
|
|
162
|
+
f"Current local version: {current_version}",
|
|
163
|
+
f"当前本地版本: {current_version}",
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
# Determine which version to use as base for incrementing
|
|
167
|
+
if pypi_version:
|
|
168
|
+
# Compare versions and use the greater one as base
|
|
169
|
+
greater_version = comparator.get_greater_version(
|
|
170
|
+
pypi_version, current_version
|
|
171
|
+
)
|
|
172
|
+
log_info_pair(
|
|
173
|
+
f"Greater version between local and PyPI: {greater_version}",
|
|
174
|
+
f"本地和 PyPI 之间较大的版本: {greater_version}",
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
# Always increment the version regardless of whether they are equal or not
|
|
178
|
+
new_version = comparator.increment_version_from_base(greater_version)
|
|
179
|
+
else:
|
|
180
|
+
# If we can't get PyPI version, increment local version
|
|
181
|
+
new_version = comparator.increment_version_from_base(current_version)
|
|
182
|
+
|
|
183
|
+
log_info_pair(
|
|
184
|
+
f"New version to be set: {new_version}",
|
|
185
|
+
f"将要设置的新版本: {new_version}",
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
if dry_run:
|
|
189
|
+
log_info_pair(
|
|
190
|
+
"Dry run mode: Would update version files",
|
|
191
|
+
"Dry run mode: 将更新版本文件",
|
|
192
|
+
)
|
|
193
|
+
else:
|
|
194
|
+
# Update VERSION file first (highest priority)
|
|
195
|
+
self._update_version_file(new_version)
|
|
196
|
+
# Then update Python and Rust versions
|
|
197
|
+
self._update_python_version(new_version)
|
|
198
|
+
self._update_rust_version(new_version)
|