From 6ce01daa5de115901fc1ae71da0f70f189a5c511 Mon Sep 17 00:00:00 2001 From: plind-junior <59729252+plind-junior@users.noreply.github.com> Date: Wed, 29 Apr 2026 16:14:40 +0900 Subject: [PATCH 1/2] fix(cli): stop bittensor argparse from hijacking click --help MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `gitt --help` and `gitt --help` printed bittensor's bt.config argparse output instead of click's command tree, because importing bittensor at module load parses sys.argv and exits on -h/--help before click runs. Bare `gitt` worked. Extend the existing stub gate (PR #704, used for shell completion) to also fire when -h/--help is in argv. Help-only invocations don't need the real bittensor — click resolves help text from decorators without running command bodies. --- gittensor/cli/main.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gittensor/cli/main.py b/gittensor/cli/main.py index abcbc0fd2..c407389e3 100644 --- a/gittensor/cli/main.py +++ b/gittensor/cli/main.py @@ -16,8 +16,12 @@ import os import sys -# Stub heavy imports during shell completion so tab-completion stays fast. -if os.environ.get('_GITT_COMPLETE'): +# Stub heavy imports during shell completion and --help so tab-completion stays +# fast and bittensor's argparse doesn't hijack click's help output. +_is_completion = bool(os.environ.get('_GITT_COMPLETE')) +_is_help_only = any(arg in ('-h', '--help') for arg in sys.argv[1:]) + +if _is_completion or _is_help_only: import types as _types class _Stub(_types.ModuleType): @@ -27,7 +31,7 @@ def __getattr__(self, _name): def __call__(self, *_a, **_kw): return self - _stub = _Stub('_gitt_completion_stub') + _stub = _Stub('_gitt_cli_stub') for _pkg in ('bittensor', 'requests'): sys.modules[_pkg] = _stub From 05b88c8638ee3cfcf125eea5baace1ee455fee2d Mon Sep 17 00:00:00 2001 From: plind-junior <59729252+plind-junior@users.noreply.github.com> Date: Wed, 29 Apr 2026 16:22:43 +0900 Subject: [PATCH 2/2] fix(cli): inline help/completion gate to satisfy ruff E402 Ruff flagged the previous form (two assignments + if-block before later imports) with E402 'module level import not at top of file'. Collapsing the gate back to a single conditional preserves the conditional-import idiom that ruff E402 looks past, matching the pre-existing pattern from PR #704. --- gittensor/cli/main.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gittensor/cli/main.py b/gittensor/cli/main.py index c407389e3..a51558279 100644 --- a/gittensor/cli/main.py +++ b/gittensor/cli/main.py @@ -18,10 +18,7 @@ # Stub heavy imports during shell completion and --help so tab-completion stays # fast and bittensor's argparse doesn't hijack click's help output. -_is_completion = bool(os.environ.get('_GITT_COMPLETE')) -_is_help_only = any(arg in ('-h', '--help') for arg in sys.argv[1:]) - -if _is_completion or _is_help_only: +if os.environ.get('_GITT_COMPLETE') or any(arg in ('-h', '--help') for arg in sys.argv[1:]): import types as _types class _Stub(_types.ModuleType):