dhis2w-cli 0.12.0__tar.gz → 0.13.0__tar.gz

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.
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dhis2w-cli
3
- Version: 0.12.0
3
+ Version: 0.13.0
4
4
  Summary: dhis2 command-line interface (Typer) — mounts plugins from dhis2w-core.
5
5
  Author: Morten Hansen
6
6
  Author-email: Morten Hansen <morten@winterop.com>
7
- Requires-Dist: dhis2w-core>=0.12.0,<0.13
7
+ Requires-Dist: dhis2w-core>=0.13.0,<0.14
8
8
  Requires-Dist: typer>=0.24
9
9
  Requires-Dist: rich>=15
10
- Requires-Dist: dhis2w-browser>=0.12.0,<0.13 ; extra == 'browser'
10
+ Requires-Dist: dhis2w-browser>=0.13.0,<0.14 ; extra == 'browser'
11
11
  Requires-Python: >=3.13
12
12
  Provides-Extra: browser
13
13
  Description-Content-Type: text/markdown
@@ -1,18 +1,18 @@
1
1
  [project]
2
2
  name = "dhis2w-cli"
3
- version = "0.12.0"
3
+ version = "0.13.0"
4
4
  description = "dhis2 command-line interface (Typer) — mounts plugins from dhis2w-core."
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Morten Hansen", email = "morten@winterop.com" }]
7
7
  requires-python = ">=3.13"
8
8
  dependencies = [
9
- "dhis2w-core>=0.12.0,<0.13",
9
+ "dhis2w-core>=0.13.0,<0.14",
10
10
  "typer>=0.24",
11
11
  "rich>=15",
12
12
  ]
13
13
 
14
14
  [project.optional-dependencies]
15
- browser = ["dhis2w-browser>=0.12.0,<0.13"]
15
+ browser = ["dhis2w-browser>=0.13.0,<0.14"]
16
16
 
17
17
  [project.scripts]
18
18
  dhis2 = "dhis2w_cli.main:main"
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  import logging
6
6
  import os
7
+ import sys
7
8
  from importlib.metadata import PackageNotFoundError, version
8
9
  from typing import Annotated
9
10
 
@@ -15,6 +16,35 @@ from dhis2w_core.rich_console import STDERR_CONSOLE
15
16
  from rich.logging import RichHandler
16
17
 
17
18
 
19
+ def _extract_profile_from_argv(argv: list[str]) -> str | None:
20
+ """Pre-scan argv for `--profile NAME` / `--profile=NAME` / `-p NAME`.
21
+
22
+ Plugin discovery needs to happen *after* `--profile` is applied — the
23
+ `version` field on the resolved profile picks which `v{41,42,43}`
24
+ plugin tree gets mounted. The Typer root callback sets the env var,
25
+ but plugins are mounted before any argv is parsed. This pre-scan
26
+ runs before `build_app()` so the env is in place when
27
+ `resolve_startup_version()` fires.
28
+
29
+ Returns `None` when no `--profile` flag is present. Stops at `--`
30
+ (positional separator) so a profile-shaped string passed after `--`
31
+ is not mistaken for the option value.
32
+ """
33
+ i = 0
34
+ while i < len(argv):
35
+ arg = argv[i]
36
+ if arg == "--":
37
+ return None
38
+ if arg in {"--profile", "-p"}:
39
+ if i + 1 < len(argv):
40
+ return argv[i + 1]
41
+ return None
42
+ if arg.startswith("--profile="):
43
+ return arg.removeprefix("--profile=")
44
+ i += 1
45
+ return None
46
+
47
+
18
48
  def _version_banner() -> str:
19
49
  """Multi-line banner shown for `dhis2 --version` — package version + active plugin tree.
20
50
 
@@ -140,12 +170,31 @@ def build_app() -> typer.Typer:
140
170
  return app
141
171
 
142
172
 
143
- app = build_app()
144
-
145
-
146
173
  def main() -> None:
147
- """Console-script entrypoint — wraps the Typer app with clean error rendering."""
148
- run_app(app)
174
+ """Console-script entrypoint — wraps the Typer app with clean error rendering.
175
+
176
+ Resolves `--profile` from argv *before* mounting plugins so the
177
+ correct `v{41,42,43}` plugin tree gets discovered. Without this
178
+ pre-pass, `dhis2 --profile v43p ...` would freeze the plugin tree
179
+ at whatever the default profile pinned (typically v42), hiding
180
+ v43-only commands and making `--version`'s banner disagree with
181
+ the actual mounted command tree.
182
+ """
183
+ profile = _extract_profile_from_argv(sys.argv[1:])
184
+ if profile:
185
+ os.environ["DHIS2_PROFILE"] = profile
186
+ fresh_app = build_app()
187
+ run_app(fresh_app)
188
+
189
+
190
+ # Module-level Typer app instance for `typer dhis2w_cli.main utils docs ...`
191
+ # introspection used by `make docs-cli` to regenerate `docs/cli-reference.md`.
192
+ # Not consumed by the console-script entry point — `main()` above builds its
193
+ # own fresh app *after* applying `--profile` from argv, which is what the user
194
+ # expects at runtime. This module-level instance is only walked at docs-build
195
+ # time, where no user CLI args are in play and the canonical (default-profile)
196
+ # command tree is the correct thing to dump.
197
+ app = build_app()
149
198
 
150
199
 
151
200
  if __name__ == "__main__":
File without changes