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,42 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
#
|
|
3
|
+
# An example hook script to prepare the commit log message.
|
|
4
|
+
# Called by "git commit" with the name of the file that has the
|
|
5
|
+
# commit message, followed by the description of the commit
|
|
6
|
+
# message's source. The hook's purpose is to edit the commit
|
|
7
|
+
# message file. If the hook fails with a non-zero status,
|
|
8
|
+
# the commit is aborted.
|
|
9
|
+
#
|
|
10
|
+
# To enable this hook, rename this file to "prepare-commit-msg".
|
|
11
|
+
|
|
12
|
+
# This hook includes three examples. The first one removes the
|
|
13
|
+
# "# Please enter the commit message..." help message.
|
|
14
|
+
#
|
|
15
|
+
# The second includes the output of "git diff --name-status -r"
|
|
16
|
+
# into the message, just before the "git status" output. It is
|
|
17
|
+
# commented because it doesn't cope with --amend or with squashed
|
|
18
|
+
# commits.
|
|
19
|
+
#
|
|
20
|
+
# The third example adds a Signed-off-by line to the message, that can
|
|
21
|
+
# still be edited. This is rarely a good idea.
|
|
22
|
+
|
|
23
|
+
COMMIT_MSG_FILE=$1
|
|
24
|
+
COMMIT_SOURCE=$2
|
|
25
|
+
SHA1=$3
|
|
26
|
+
|
|
27
|
+
/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE"
|
|
28
|
+
|
|
29
|
+
# case "$COMMIT_SOURCE,$SHA1" in
|
|
30
|
+
# ,|template,)
|
|
31
|
+
# /usr/bin/perl -i.bak -pe '
|
|
32
|
+
# print "\n" . `git diff --cached --name-status -r`
|
|
33
|
+
# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;;
|
|
34
|
+
# *) ;;
|
|
35
|
+
# esac
|
|
36
|
+
|
|
37
|
+
# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
|
|
38
|
+
# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE"
|
|
39
|
+
# if test -z "$COMMIT_SOURCE"
|
|
40
|
+
# then
|
|
41
|
+
# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE"
|
|
42
|
+
# fi
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
#
|
|
3
|
+
# An example hook script to block unannotated tags from entering.
|
|
4
|
+
# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
|
|
5
|
+
#
|
|
6
|
+
# To enable this hook, rename this file to "update".
|
|
7
|
+
#
|
|
8
|
+
# Config
|
|
9
|
+
# ------
|
|
10
|
+
# hooks.allowunannotated
|
|
11
|
+
# This boolean sets whether unannotated tags will be allowed into the
|
|
12
|
+
# repository. By default they won't be.
|
|
13
|
+
# hooks.allowdeletetag
|
|
14
|
+
# This boolean sets whether deleting tags will be allowed in the
|
|
15
|
+
# repository. By default they won't be.
|
|
16
|
+
# hooks.allowmodifytag
|
|
17
|
+
# This boolean sets whether a tag may be modified after creation. By default
|
|
18
|
+
# it won't be.
|
|
19
|
+
# hooks.allowdeletebranch
|
|
20
|
+
# This boolean sets whether deleting branches will be allowed in the
|
|
21
|
+
# repository. By default they won't be.
|
|
22
|
+
# hooks.denycreatebranch
|
|
23
|
+
# This boolean sets whether remotely creating branches will be denied
|
|
24
|
+
# in the repository. By default this is allowed.
|
|
25
|
+
#
|
|
26
|
+
|
|
27
|
+
# --- Command line
|
|
28
|
+
refname="$1"
|
|
29
|
+
oldrev="$2"
|
|
30
|
+
newrev="$3"
|
|
31
|
+
|
|
32
|
+
# --- Safety check
|
|
33
|
+
if [ -z "$GIT_DIR" ]; then
|
|
34
|
+
echo "Don't run this script from the command line." >&2
|
|
35
|
+
echo " (if you want, you could supply GIT_DIR then run" >&2
|
|
36
|
+
echo " $0 <ref> <oldrev> <newrev>)" >&2
|
|
37
|
+
exit 1
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
|
|
41
|
+
echo "usage: $0 <ref> <oldrev> <newrev>" >&2
|
|
42
|
+
exit 1
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
# --- Config
|
|
46
|
+
allowunannotated=$(git config --type=bool hooks.allowunannotated)
|
|
47
|
+
allowdeletebranch=$(git config --type=bool hooks.allowdeletebranch)
|
|
48
|
+
denycreatebranch=$(git config --type=bool hooks.denycreatebranch)
|
|
49
|
+
allowdeletetag=$(git config --type=bool hooks.allowdeletetag)
|
|
50
|
+
allowmodifytag=$(git config --type=bool hooks.allowmodifytag)
|
|
51
|
+
|
|
52
|
+
# check for no description
|
|
53
|
+
projectdesc=$(sed -e '1q' "$GIT_DIR/description")
|
|
54
|
+
case "$projectdesc" in
|
|
55
|
+
"Unnamed repository"* | "")
|
|
56
|
+
echo "*** Project description file hasn't been set" >&2
|
|
57
|
+
exit 1
|
|
58
|
+
;;
|
|
59
|
+
esac
|
|
60
|
+
|
|
61
|
+
# --- Check types
|
|
62
|
+
# if $newrev is 0000...0000, it's a commit to delete a ref.
|
|
63
|
+
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
|
|
64
|
+
if [ "$newrev" = "$zero" ]; then
|
|
65
|
+
newrev_type=delete
|
|
66
|
+
else
|
|
67
|
+
newrev_type=$(git cat-file -t $newrev)
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
case "$refname","$newrev_type" in
|
|
71
|
+
refs/tags/*,commit)
|
|
72
|
+
# un-annotated tag
|
|
73
|
+
short_refname=${refname##refs/tags/}
|
|
74
|
+
if [ "$allowunannotated" != "true" ]; then
|
|
75
|
+
echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
|
|
76
|
+
echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
|
|
77
|
+
exit 1
|
|
78
|
+
fi
|
|
79
|
+
;;
|
|
80
|
+
refs/tags/*,delete)
|
|
81
|
+
# delete tag
|
|
82
|
+
if [ "$allowdeletetag" != "true" ]; then
|
|
83
|
+
echo "*** Deleting a tag is not allowed in this repository" >&2
|
|
84
|
+
exit 1
|
|
85
|
+
fi
|
|
86
|
+
;;
|
|
87
|
+
refs/tags/*,tag)
|
|
88
|
+
# annotated tag
|
|
89
|
+
if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
|
|
90
|
+
then
|
|
91
|
+
echo "*** Tag '$refname' already exists." >&2
|
|
92
|
+
echo "*** Modifying a tag is not allowed in this repository." >&2
|
|
93
|
+
exit 1
|
|
94
|
+
fi
|
|
95
|
+
;;
|
|
96
|
+
refs/heads/*,commit)
|
|
97
|
+
# branch
|
|
98
|
+
if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
|
|
99
|
+
echo "*** Creating a branch is not allowed in this repository" >&2
|
|
100
|
+
exit 1
|
|
101
|
+
fi
|
|
102
|
+
;;
|
|
103
|
+
refs/heads/*,delete)
|
|
104
|
+
# delete branch
|
|
105
|
+
if [ "$allowdeletebranch" != "true" ]; then
|
|
106
|
+
echo "*** Deleting a branch is not allowed in this repository" >&2
|
|
107
|
+
exit 1
|
|
108
|
+
fi
|
|
109
|
+
;;
|
|
110
|
+
refs/remotes/*,commit)
|
|
111
|
+
# tracking branch
|
|
112
|
+
;;
|
|
113
|
+
refs/remotes/*,delete)
|
|
114
|
+
# delete tracking branch
|
|
115
|
+
if [ "$allowdeletebranch" != "true" ]; then
|
|
116
|
+
echo "*** Deleting a tracking branch is not allowed in this repository" >&2
|
|
117
|
+
exit 1
|
|
118
|
+
fi
|
|
119
|
+
;;
|
|
120
|
+
*)
|
|
121
|
+
# Anything else (is there anything else?)
|
|
122
|
+
echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
|
|
123
|
+
exit 1
|
|
124
|
+
;;
|
|
125
|
+
esac
|
|
126
|
+
|
|
127
|
+
# --- Finished
|
|
128
|
+
exit 0
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal enabledelayedexpansion
|
|
3
|
+
|
|
4
|
+
echo ==========================================
|
|
5
|
+
echo LFS Work Session
|
|
6
|
+
echo Keep this window open while working.
|
|
7
|
+
echo ==========================================
|
|
8
|
+
|
|
9
|
+
REM Store current directory using CD command
|
|
10
|
+
set "PROJECT_DIR=%CD%"
|
|
11
|
+
|
|
12
|
+
REM Clean up stale PID file from previous ungraceful exit
|
|
13
|
+
if exist ".wl\lfs-watch.pid" del ".wl\lfs-watch.pid"
|
|
14
|
+
|
|
15
|
+
echo.
|
|
16
|
+
echo [1/3] Pulling latest changes...
|
|
17
|
+
git pull
|
|
18
|
+
if errorlevel 1 (
|
|
19
|
+
echo ERROR: git pull failed.
|
|
20
|
+
echo If you have uncommitted changes, run: git stash
|
|
21
|
+
echo Otherwise, check your network connection.
|
|
22
|
+
pause
|
|
23
|
+
exit /b 1
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
echo.
|
|
27
|
+
echo [2/3] Starting LFS watch (Ctrl-C to stop)...
|
|
28
|
+
echo Minimize this window and work in your CAD application.
|
|
29
|
+
echo Press Ctrl-C when finished to proceed to push.
|
|
30
|
+
echo.
|
|
31
|
+
wl lfs watch
|
|
32
|
+
if errorlevel 1 (
|
|
33
|
+
echo ERROR: wl lfs watch failed to start.
|
|
34
|
+
echo Make sure wl is installed and watchdog is available.
|
|
35
|
+
echo Run: pip install watchdog
|
|
36
|
+
pause
|
|
37
|
+
exit /b 1
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
echo.
|
|
41
|
+
echo [3/3] Push changes? [Y/N]
|
|
42
|
+
set /p PUSH_CHOICE="Enter Y to push, any other key to skip: "
|
|
43
|
+
if /i "%PUSH_CHOICE%"=="Y" (
|
|
44
|
+
echo.
|
|
45
|
+
echo Adding changes...
|
|
46
|
+
git add -A
|
|
47
|
+
echo Committing...
|
|
48
|
+
git diff --quiet --cached || git commit -m "work: auto commit"
|
|
49
|
+
echo Pushing...
|
|
50
|
+
git push
|
|
51
|
+
if errorlevel 1 (
|
|
52
|
+
echo ERROR: git push failed.
|
|
53
|
+
pause
|
|
54
|
+
exit /b 1
|
|
55
|
+
)
|
|
56
|
+
echo Done!
|
|
57
|
+
) else (
|
|
58
|
+
echo Skipped push.
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
echo.
|
|
62
|
+
echo Press any key to exit...
|
|
63
|
+
pause >nul
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Python 相关文件
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.so
|
|
5
|
+
*.dll
|
|
6
|
+
*.dylib
|
|
7
|
+
*.pyd
|
|
8
|
+
*.egg-info/
|
|
9
|
+
.pytest_cache/
|
|
10
|
+
.coverage
|
|
11
|
+
htmlcov/
|
|
12
|
+
.tox/
|
|
13
|
+
.hypothesis/
|
|
14
|
+
.cache/
|
|
15
|
+
.pre-commit-config.yaml
|
|
16
|
+
|
|
17
|
+
.wl/
|
|
18
|
+
.coveragerc
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# 临时文件和系统文件
|
|
22
|
+
.DS_Store
|
|
23
|
+
|
|
24
|
+
# 图像和媒体文件
|
|
25
|
+
*.png
|
|
26
|
+
*.jpg
|
|
27
|
+
*.pdf
|
|
28
|
+
|
|
29
|
+
# Jupyter 文件
|
|
30
|
+
.ipynb_checkpoints/
|
|
31
|
+
|
|
32
|
+
# 日志和数据文件
|
|
33
|
+
*.log
|
|
34
|
+
logs/
|
|
35
|
+
results/
|
|
36
|
+
|
|
37
|
+
# 本地配置
|
|
38
|
+
.env
|
|
39
|
+
.env.local
|
|
40
|
+
auto_activate_venv.sh
|
|
41
|
+
deactivate_temp.sh
|
|
42
|
+
tools/auto_activate_venv.sh
|
|
43
|
+
|
|
44
|
+
# 工具和脚本(本地使用,不加入版本控制)
|
|
45
|
+
tools/
|
|
46
|
+
Makefile
|
|
47
|
+
todos/
|
|
48
|
+
|
|
49
|
+
# 示例文件夹(通常不加入版本控制)
|
|
50
|
+
# examples/
|
|
51
|
+
|
|
52
|
+
# 测试文件夹(通常加入版本控制)
|
|
53
|
+
# test/
|
|
54
|
+
output/
|
|
55
|
+
.history/
|
|
56
|
+
|
|
57
|
+
rust/target/
|
|
58
|
+
rust/.cargo/
|
|
59
|
+
Cargo.lock
|
|
60
|
+
typings/
|
|
61
|
+
|
|
62
|
+
examples/output*
|
|
63
|
+
|
|
64
|
+
# Added by Task Master AI
|
|
65
|
+
# Logs
|
|
66
|
+
logs
|
|
67
|
+
npm-debug.log*
|
|
68
|
+
yarn-debug.log*
|
|
69
|
+
yarn-error.log*
|
|
70
|
+
dev-debug.log
|
|
71
|
+
# Dependency directories
|
|
72
|
+
node_modules/
|
|
73
|
+
# Environment variables
|
|
74
|
+
# Editor directories and files
|
|
75
|
+
.idea
|
|
76
|
+
.vscode
|
|
77
|
+
*.suo
|
|
78
|
+
*.ntvs*
|
|
79
|
+
*.njsproj
|
|
80
|
+
*.sln
|
|
81
|
+
*.sw?
|
|
82
|
+
# OS specific
|
|
83
|
+
# Task files
|
|
84
|
+
tasks.json
|
|
85
|
+
tasks/
|
|
86
|
+
vendors/
|
|
87
|
+
**/*.token
|
|
88
|
+
|
|
89
|
+
# worktrees (see git-dev-sop §1.1)
|
|
90
|
+
.worktrees/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [year] [author]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "py-reducer-workspace"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
dependencies = [
|
|
8
|
+
# "cadquery>=2.5.2",
|
|
9
|
+
# "matplotlib>=3.10.5",
|
|
10
|
+
# "toml>=0.10.2",
|
|
11
|
+
# "tomli>=2.2.1",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[[tool.uv.index]]
|
|
15
|
+
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
|
|
16
|
+
default = true
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
[tool.uv.workspace]
|
|
20
|
+
members = [
|
|
21
|
+
"packages/*",
|
|
22
|
+
] # 声明子包路径
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
[tool.uv.sources]
|
|
27
|
+
py_XXXX = { workspace = true } # 标记子包为 workspace 内部依赖
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "py-reducer-workspace"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
dependencies = [
|
|
8
|
+
# "cadquery>=2.5.2",
|
|
9
|
+
# "matplotlib>=3.10.5",
|
|
10
|
+
# "toml>=0.10.2",
|
|
11
|
+
# "tomli>=2.2.1",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[[tool.uv.index]]
|
|
15
|
+
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
|
|
16
|
+
default = true
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "workspace-root"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
dependencies = []
|
|
8
|
+
|
|
9
|
+
[[tool.uv.index]]
|
|
10
|
+
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
|
|
11
|
+
default = true
|
|
12
|
+
|
|
13
|
+
[tool.uv.workspace]
|
|
14
|
+
members = ["packages/*"]
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# {project_name}
|
|
2
|
+
|
|
3
|
+
[](https://github.com/your-username/{project_name}/actions/workflows/ci.yml)
|
|
4
|
+
[](https://badge.fury.io/py/{project_name})
|
|
5
|
+
[](https://pypi.org/project/{project_name}/)
|
|
6
|
+
|
|
7
|
+
{project_description}
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **init**: Initialize project environment with Git, virtual environment, i18n, Rust submodule, etc.
|
|
12
|
+
- **build**: Execute build tasks, support Python package building and distribution
|
|
13
|
+
- **test**: Run project tests
|
|
14
|
+
- **format**: Support Python and Rust code formatting (integrated with black, rustfmt, etc.)
|
|
15
|
+
- **lint**: Execute code quality checks
|
|
16
|
+
- **clean**: Clean build artifacts and temporary files
|
|
17
|
+
- **self**: Self-management commands
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
### From PyPI
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install {project_name}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### From Source
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Clone the repository
|
|
31
|
+
git clone https://github.com/your-username/{project_name}.git
|
|
32
|
+
cd {project_name}
|
|
33
|
+
|
|
34
|
+
# Install in development mode
|
|
35
|
+
pip install -e .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
After installation, you can use the `{cli_command}` command:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Show help
|
|
44
|
+
{cli_command} --help
|
|
45
|
+
|
|
46
|
+
# Initialize a new project
|
|
47
|
+
{cli_command} init
|
|
48
|
+
|
|
49
|
+
# Build the project
|
|
50
|
+
{cli_command} build
|
|
51
|
+
|
|
52
|
+
# Run tests
|
|
53
|
+
{cli_command} test
|
|
54
|
+
|
|
55
|
+
# Format code
|
|
56
|
+
{cli_command} format
|
|
57
|
+
|
|
58
|
+
# Lint code
|
|
59
|
+
{cli_command} lint
|
|
60
|
+
|
|
61
|
+
# Clean build artifacts
|
|
62
|
+
{cli_command} clean
|
|
63
|
+
|
|
64
|
+
# Update the tool itself
|
|
65
|
+
{cli_command} self update
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Development
|
|
69
|
+
|
|
70
|
+
### Prerequisites
|
|
71
|
+
|
|
72
|
+
- Python >= 3.10
|
|
73
|
+
- Rust toolchain (if applicable)
|
|
74
|
+
- Git
|
|
75
|
+
|
|
76
|
+
### Setup Development Environment
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Clone the repository
|
|
80
|
+
git clone https://github.com/your-username/{project_name}.git
|
|
81
|
+
cd {project_name}
|
|
82
|
+
|
|
83
|
+
# Install dependencies
|
|
84
|
+
pip install -e .
|
|
85
|
+
|
|
86
|
+
# Or if using uv
|
|
87
|
+
uv pip install -e .
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Running Tests
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Run all tests
|
|
94
|
+
pytest tests/
|
|
95
|
+
|
|
96
|
+
# Or using the {cli_command} command
|
|
97
|
+
{cli_command} test
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Building Distribution Packages
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# Build with {cli_command} command
|
|
104
|
+
{cli_command} build dist
|
|
105
|
+
|
|
106
|
+
# Or directly with maturin (if applicable)
|
|
107
|
+
maturin build --release --out dist --sdist
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## CI/CD
|
|
111
|
+
|
|
112
|
+
This project uses GitHub Actions for continuous integration and deployment:
|
|
113
|
+
|
|
114
|
+
- **CI**: Runs tests on multiple platforms (Ubuntu, Windows, macOS) and Python versions (3.10, 3.11, 3.12)
|
|
115
|
+
- **Code Quality**: Runs linting and type checking
|
|
116
|
+
- **Publish**: Automatically publishes to PyPI when a new tag is pushed
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "wl_cli_native"
|
|
3
|
+
version = "0.2.2"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
description = "wl_cli - Python项目"
|
|
6
|
+
authors = ["Admin <admin@example.com>"]
|
|
7
|
+
|
|
8
|
+
[dependencies]
|
|
9
|
+
pyo3 = { version = "0.28.2", features = ["extension-module"] }
|
|
10
|
+
|
|
11
|
+
[lib]
|
|
12
|
+
name = "wl_cli_native"
|
|
13
|
+
crate-type = ["cdylib"]
|
|
14
|
+
path = "src/lib.rs"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# 尝试导入 Rust 扩展,如果失败则使用 Python 实现
|
|
2
|
+
# This is a template file, {project_name} will be replaced with actual project name
|
|
3
|
+
from typing import cast
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
# Dynamic import using project name placeholder
|
|
7
|
+
project_name = "{project_name}"
|
|
8
|
+
rust_module = __import__(f"{project_name}_native")
|
|
9
|
+
rust_sum_as_string = rust_module.sum_as_string
|
|
10
|
+
HAS_RUST_EXTENSION = True
|
|
11
|
+
except ImportError:
|
|
12
|
+
HAS_RUST_EXTENSION = False
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def sum_as_string(a: int, b: int) -> str:
|
|
16
|
+
"""
|
|
17
|
+
计算两个整数的和并返回字符串表示。
|
|
18
|
+
优先使用 Rust 扩展实现,不可用时回落至 Python 实现。
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
a: 第一个整数
|
|
22
|
+
b: 第二个整数
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
两个整数和的字符串表示
|
|
26
|
+
"""
|
|
27
|
+
if HAS_RUST_EXTENSION:
|
|
28
|
+
return cast("str", rust_sum_as_string(a, b))
|
|
29
|
+
else:
|
|
30
|
+
# Python 实现作为回落
|
|
31
|
+
return str(a + b)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
use pyo3::prelude::*;
|
|
2
|
+
|
|
3
|
+
/// A Python module implemented in Rust.
|
|
4
|
+
#[pymodule]
|
|
5
|
+
fn wl_cli_native(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
6
|
+
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
|
|
7
|
+
Ok(())
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
#[pyfunction]
|
|
11
|
+
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
|
|
12
|
+
Ok((a + b).to_string())
|
|
13
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from unittest.mock import patch
|
|
3
|
+
|
|
4
|
+
from wl_cli.lib import HAS_RUST_EXTENSION, sum_as_string
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_sum_as_string():
|
|
8
|
+
"""测试 sum_as_string 函数基本功能"""
|
|
9
|
+
assert sum_as_string(1, 2) == "3"
|
|
10
|
+
assert sum_as_string(0, 0) == "0"
|
|
11
|
+
assert sum_as_string(100, 200) == "300"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_sum_as_string_rust_available():
|
|
15
|
+
"""测试 Rust 扩展可用时的功能"""
|
|
16
|
+
if HAS_RUST_EXTENSION:
|
|
17
|
+
# 确保使用的是 Rust 实现
|
|
18
|
+
result = sum_as_string(1, 2)
|
|
19
|
+
assert result == "3"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_sum_as_string_fallback():
|
|
23
|
+
"""测试 Rust 扩展不可用时的回落功能"""
|
|
24
|
+
# 模拟 Rust 扩展不可用
|
|
25
|
+
with patch.dict("sys.modules", {"wl_cli_native": None}):
|
|
26
|
+
# 重新导入模块以应用模拟
|
|
27
|
+
if "wl_cli.lib.rust_utils" in sys.modules:
|
|
28
|
+
del sys.modules["wl_cli.lib.rust_utils"]
|
|
29
|
+
if "wl_cli.lib" in sys.modules:
|
|
30
|
+
del sys.modules["wl_cli.lib"]
|
|
31
|
+
|
|
32
|
+
from wl_cli.lib import HAS_RUST_EXTENSION, sum_as_string
|
|
33
|
+
|
|
34
|
+
# 验证已切换到 Python 实现
|
|
35
|
+
assert not HAS_RUST_EXTENSION
|
|
36
|
+
|
|
37
|
+
# 测试 Python 回落实现
|
|
38
|
+
assert sum_as_string(1, 2) == "3"
|
|
39
|
+
assert sum_as_string(0, 0) == "0"
|
|
40
|
+
assert sum_as_string(100, 200) == "300"
|