svc-infra 0.1.619__py3-none-any.whl → 0.1.621__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.

Potentially problematic release.


This version of svc-infra might be problematic. Click here for more details.

@@ -1,6 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import importlib.util
3
4
  import os
5
+ import sys
4
6
  from importlib.metadata import PackageNotFoundError, distribution
5
7
  from pathlib import Path
6
8
  from typing import Dict, List
@@ -9,7 +11,15 @@ import click
9
11
  import typer
10
12
  from typer.core import TyperGroup
11
13
 
12
- from svc_infra.app.root import resolve_project_root
14
+
15
+ def _norm(name: str) -> str:
16
+ """Normalize a topic name for stable CLI commands.
17
+
18
+ - Lowercase
19
+ - Replace spaces and underscores with hyphens
20
+ - Strip leading/trailing whitespace
21
+ """
22
+ return name.strip().lower().replace(" ", "-").replace("_", "-")
13
23
 
14
24
 
15
25
  def _discover_fs_topics(docs_dir: Path) -> Dict[str, Path]:
@@ -17,99 +27,192 @@ def _discover_fs_topics(docs_dir: Path) -> Dict[str, Path]:
17
27
  if docs_dir.exists() and docs_dir.is_dir():
18
28
  for p in sorted(docs_dir.glob("*.md")):
19
29
  if p.is_file():
20
- topics[p.stem.replace(" ", "-")] = p
30
+ topics[_norm(p.stem)] = p
21
31
  return topics
22
32
 
23
33
 
24
34
  def _discover_pkg_topics() -> Dict[str, Path]:
25
35
  """Discover docs packaged under 'docs/' in the installed distribution.
26
36
 
27
- This lets 'svc-infra docs' work from external projects that don't have a
28
- local docs/ directory by falling back to files shipped in the wheel.
37
+ Works in external projects without a local docs/ by inspecting the wheel
38
+ metadata and, as a fallback, searching for a top-level docs/ next to the
39
+ installed package directory in site-packages.
29
40
  """
30
41
  topics: Dict[str, Path] = {}
31
- try:
32
- dist = distribution("svc-infra")
33
- except PackageNotFoundError:
34
- return topics
35
-
36
- files = getattr(dist, "files", None) or []
37
- for f in files:
38
- # f is a PackagePath; string form like 'docs/topic.md'
39
- s = str(f)
40
- if not s.startswith("docs/") or not s.endswith(".md"):
41
- continue
42
- name = Path(s).stem.replace(" ", "-")
42
+
43
+ # 1) Prefer distribution metadata (RECORD) for both hyphen/underscore names
44
+ dist = None
45
+ for name in ("svc-infra", "svc_infra"):
43
46
  try:
44
- abs_path = dist.locate_file(f)
45
- # Ensure it's a file before adding
46
- abs_p = Path(abs_path)
47
- if abs_p.exists() and abs_p.is_file():
48
- topics[name] = abs_p
49
- except Exception:
50
- # best-effort; skip unreadable entries
51
- continue
47
+ dist = distribution(name)
48
+ break
49
+ except PackageNotFoundError:
50
+ dist = None
51
+
52
+ if dist is not None:
53
+ files = getattr(dist, "files", None) or []
54
+ for f in files:
55
+ s = str(f)
56
+ if not s.startswith("docs/") or not s.endswith(".md"):
57
+ continue
58
+ topic_name = _norm(Path(s).stem)
59
+ try:
60
+ abs_path = Path(dist.locate_file(f))
61
+ if abs_path.exists() and abs_path.is_file():
62
+ topics[topic_name] = abs_path
63
+ except Exception:
64
+ # Best effort; continue to next
65
+ continue
66
+
67
+ # 2) Fallback: site-packages sibling 'docs/' directory (and repo-root docs in editable installs)
68
+ try:
69
+ spec = importlib.util.find_spec("svc_infra")
70
+ if spec and spec.submodule_search_locations:
71
+ pkg_dir = Path(next(iter(spec.submodule_search_locations)))
72
+ candidates = [
73
+ pkg_dir.parent / "docs", # site-packages/docs OR src/docs
74
+ pkg_dir / "docs", # site-packages/svc_infra/docs OR src/svc_infra/docs
75
+ pkg_dir.parent.parent
76
+ / "docs", # repo-root/docs when running editable from repo (src/svc_infra → ../../docs)
77
+ ]
78
+ for candidate in candidates:
79
+ if candidate.exists() and candidate.is_dir():
80
+ for p in sorted(candidate.glob("*.md")):
81
+ if p.is_file():
82
+ topics.setdefault(_norm(p.stem), p)
83
+ # If one candidate had docs, that's sufficient
84
+ if any(k for k in topics):
85
+ break
86
+ except Exception:
87
+ # Optional fallback only
88
+ pass
89
+
90
+ # 3) Last-resort: scan sys.path entries that look like site-/dist-packages for a top-level docs/
91
+ # directory containing markdown files. This covers non-standard installs/editable modes.
92
+ try:
93
+ if not topics:
94
+ for entry in sys.path:
95
+ try:
96
+ if not entry or ("site-packages" not in entry and "dist-packages" not in entry):
97
+ continue
98
+ docs_dir = Path(entry) / "docs"
99
+ if docs_dir.exists() and docs_dir.is_dir():
100
+ found = _discover_fs_topics(docs_dir)
101
+ if found:
102
+ # Merge but do not override anything already found
103
+ for k, v in found.items():
104
+ topics.setdefault(k, v)
105
+ # If we found one valid docs dir, it's enough
106
+ break
107
+ except Exception:
108
+ continue
109
+ except Exception:
110
+ pass
111
+
112
+ # 4) Parse dist-info/RECORD or egg-info/SOURCES.txt to enumerate docs if available
113
+ try:
114
+ if not topics:
115
+ spec = importlib.util.find_spec("svc_infra")
116
+ base_dir: Path | None = None
117
+ if spec and spec.submodule_search_locations:
118
+ base_dir = Path(next(iter(spec.submodule_search_locations))).parent
119
+ # Fallback to first site-packages on sys.path
120
+ if base_dir is None:
121
+ for entry in sys.path:
122
+ if entry and "site-packages" in entry:
123
+ base_dir = Path(entry)
124
+ break
125
+ if base_dir and base_dir.exists():
126
+ # Check for both hyphen and underscore dist-info names
127
+ candidates = list(base_dir.glob("svc_infra-*.dist-info")) + list(
128
+ base_dir.glob("svc-infra-*.dist-info")
129
+ )
130
+ for di in candidates:
131
+ record = di / "RECORD"
132
+ if record.exists():
133
+ try:
134
+ for line in record.read_text(
135
+ encoding="utf-8", errors="ignore"
136
+ ).splitlines():
137
+ rel = line.split(",", 1)[0]
138
+ if rel.startswith("docs/") and rel.endswith(".md"):
139
+ abs_p = base_dir / rel
140
+ if abs_p.exists() and abs_p.is_file():
141
+ topics.setdefault(_norm(Path(rel).stem), abs_p)
142
+ except Exception:
143
+ continue
144
+ # egg-info fallback
145
+ if not topics:
146
+ egg_candidates = list(base_dir.glob("svc_infra-*.egg-info")) + list(
147
+ base_dir.glob("svc-infra-*.egg-info")
148
+ )
149
+ for ei in egg_candidates:
150
+ sources = ei / "SOURCES.txt"
151
+ if sources.exists():
152
+ try:
153
+ for rel in sources.read_text(
154
+ encoding="utf-8", errors="ignore"
155
+ ).splitlines():
156
+ rel = rel.strip()
157
+ if rel.startswith("docs/") and rel.endswith(".md"):
158
+ abs_p = base_dir / rel
159
+ if abs_p.exists() and abs_p.is_file():
160
+ topics.setdefault(_norm(Path(rel).stem), abs_p)
161
+ except Exception:
162
+ continue
163
+ except Exception:
164
+ pass
165
+
166
+ # 5) Deep fallback: recursively search site-packages/dist-packages for any 'docs' folder
167
+ # containing markdown files (limited depth to keep overhead reasonable).
168
+ try:
169
+ if not topics:
170
+ for entry in sys.path:
171
+ if not entry or ("site-packages" not in entry and "dist-packages" not in entry):
172
+ continue
173
+ base = Path(entry)
174
+ if not base.exists() or not base.is_dir():
175
+ continue
176
+ base_parts = len(base.parts)
177
+ for root, dirs, files in os.walk(base):
178
+ root_path = Path(root)
179
+ # Limit search depth to avoid expensive scans
180
+ if len(root_path.parts) - base_parts > 4:
181
+ # prune
182
+ dirs[:] = []
183
+ continue
184
+ if root_path.name == "docs":
185
+ for p in sorted(root_path.glob("*.md")):
186
+ if p.is_file():
187
+ topics.setdefault(_norm(p.stem), p)
188
+ # do not break; there might be multiple doc dirs
189
+ except Exception:
190
+ pass
191
+
52
192
  return topics
53
193
 
54
194
 
55
195
  def _resolve_docs_dir(ctx: click.Context) -> Path | None:
56
- # CLI option takes precedence; walk up parent contexts because Typer
57
- # executes subcommands in child contexts that do not inherit params.
58
- current: click.Context | None = ctx
59
- while current is not None:
60
- docs_dir = (current.params or {}).get("docs_dir")
61
- if docs_dir:
62
- path = docs_dir if isinstance(docs_dir, Path) else Path(docs_dir)
63
- path = path.expanduser()
64
- if path.exists():
65
- return path
66
- current = current.parent
67
- # Env var next
68
- env_dir = os.getenv("SVC_INFRA_DOCS_DIR")
69
- if env_dir:
70
- p = Path(env_dir).expanduser()
71
- if p.exists():
72
- return p
73
- # Project docs
74
- root = resolve_project_root()
75
- proj_docs = root / "docs"
76
- if proj_docs.exists():
77
- return proj_docs
196
+ # Deprecated: we no longer read docs from arbitrary paths or env.
197
+ # All docs are sourced from the packaged svc-infra distribution only.
78
198
  return None
79
199
 
80
200
 
81
201
  class DocsGroup(TyperGroup):
82
202
  def list_commands(self, ctx: click.Context) -> List[str]:
83
203
  names: List[str] = list(super().list_commands(ctx) or [])
84
- dir_to_use = _resolve_docs_dir(ctx)
85
- fs = _discover_fs_topics(dir_to_use) if dir_to_use else {}
86
204
  pkg = _discover_pkg_topics()
87
- # FS topics win on conflicts; add both for visibility
88
- names.extend([k for k in fs.keys()])
89
- names.extend([k for k in pkg.keys() if k not in fs])
205
+ names.extend([k for k in pkg.keys()])
90
206
  # Deduplicate and sort
91
- uniq = sorted({*names})
92
- return uniq
207
+ return sorted({*names})
93
208
 
94
209
  def get_command(self, ctx: click.Context, name: str) -> click.Command | None:
95
- # Built-ins first (e.g., list)
210
+ # Built-ins first (e.g., list, show)
96
211
  cmd = super().get_command(ctx, name)
97
212
  if cmd is not None:
98
213
  return cmd
99
214
 
100
- # Dynamic topic resolution
101
- dir_to_use = _resolve_docs_dir(ctx)
102
- fs = _discover_fs_topics(dir_to_use) if dir_to_use else {}
103
- if name in fs:
104
- file_path = fs[name]
105
-
106
- @click.command(name=name)
107
- def _show_fs() -> None:
108
- click.echo(file_path.read_text(encoding="utf-8", errors="replace"))
109
-
110
- return _show_fs
111
-
112
- # Packaged fallback
215
+ # Packaged topics only
113
216
  pkg = _discover_pkg_topics()
114
217
  if name in pkg:
115
218
  file_path = pkg[name]
@@ -130,55 +233,30 @@ def register(app: typer.Typer) -> None:
130
233
 
131
234
  @docs_app.callback(invoke_without_command=True)
132
235
  def _docs_options(
133
- docs_dir: Path | None = typer.Option(
134
- None,
135
- "--docs-dir",
136
- help="Path to a docs directory to read from (overrides env/project root)",
137
- ),
138
236
  topic: str | None = typer.Option(None, "--topic", help="Topic to show directly"),
139
237
  ) -> None:
140
- """Support --docs-dir and --topic at group level."""
238
+ """Support --topic at group level (packaged docs only)."""
141
239
  if topic:
142
- ctx = click.get_current_context()
143
- dir_to_use = _resolve_docs_dir(ctx)
144
- fs = _discover_fs_topics(dir_to_use) if dir_to_use else {}
145
- if topic in fs:
146
- typer.echo(fs[topic].read_text(encoding="utf-8", errors="replace"))
240
+ pkg = _discover_pkg_topics()
241
+ if topic in pkg:
242
+ typer.echo(pkg[topic].read_text(encoding="utf-8", errors="replace"))
147
243
  raise typer.Exit(code=0)
148
244
  raise typer.BadParameter(f"Unknown topic: {topic}")
149
245
 
150
246
  @docs_app.command("list", help="List available documentation topics")
151
247
  def list_topics() -> None:
152
- ctx = click.get_current_context()
153
- root = resolve_project_root()
154
- dir_to_use = _resolve_docs_dir(ctx)
155
- fs = _discover_fs_topics(dir_to_use) if dir_to_use else {}
156
248
  pkg = _discover_pkg_topics()
157
249
 
158
- # Print FS topics first (project/env/option), then packaged topics not shadowed by FS
250
+ # Print packaged topics only
159
251
  def _print(name: str, path: Path) -> None:
160
- try:
161
- rel = path.relative_to(root)
162
- typer.echo(f"{name}\t{rel}")
163
- except Exception:
164
- # For packaged topics, path will be site-packages absolute path
165
- typer.echo(f"{name}\t{path}")
252
+ typer.echo(f"{name}\t{path}")
166
253
 
167
- for name, path in fs.items():
168
- _print(name, path)
169
254
  for name, path in pkg.items():
170
- if name not in fs:
171
- _print(name, path)
255
+ _print(name, path)
172
256
 
173
257
  # Also support a generic "show" command
174
258
  @docs_app.command("show", help="Show docs for a topic (alternative to dynamic subcommand)")
175
259
  def show(topic: str) -> None:
176
- ctx = click.get_current_context()
177
- dir_to_use = _resolve_docs_dir(ctx)
178
- fs = _discover_fs_topics(dir_to_use) if dir_to_use else {}
179
- if topic in fs:
180
- typer.echo(fs[topic].read_text(encoding="utf-8", errors="replace"))
181
- return
182
260
  pkg = _discover_pkg_topics()
183
261
  if topic in pkg:
184
262
  typer.echo(pkg[topic].read_text(encoding="utf-8", errors="replace"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: svc-infra
3
- Version: 0.1.619
3
+ Version: 0.1.621
4
4
  Summary: Infrastructure for building and deploying prod-ready services
5
5
  License: MIT
6
6
  Keywords: fastapi,sqlalchemy,alembic,auth,infra,async,pydantic
@@ -142,7 +142,7 @@ svc_infra/cli/cmds/db/sql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
142
142
  svc_infra/cli/cmds/db/sql/alembic_cmds.py,sha256=uCreHg69Zf6B5gbv9Dm39jCRk6q2KQy_05A-75IP0Fg,9650
143
143
  svc_infra/cli/cmds/db/sql/sql_export_cmds.py,sha256=YpkguUJFeFApMphVkhOJllTi25ejlsQaJarMe6vJD54,2685
144
144
  svc_infra/cli/cmds/db/sql/sql_scaffold_cmds.py,sha256=MKc_T_tY1Y_wQl7XTlq8GhYWMMI1q1_vcFZVPOEcNUg,4601
145
- svc_infra/cli/cmds/docs/docs_cmds.py,sha256=nvqxkqeYNSV79Eeq0Kv8PN1M8CbyS3lnrFNjHNlO53w,6661
145
+ svc_infra/cli/cmds/docs/docs_cmds.py,sha256=fbdnTEfzx3HNNXK3zL5fa_Lk3FowzHBcfS_VHQah7VQ,10720
146
146
  svc_infra/cli/cmds/dx/__init__.py,sha256=wQtl3-kOgoESlpVkjl3YFtqkOnQSIvVsOdutiaZFejM,197
147
147
  svc_infra/cli/cmds/dx/dx_cmds.py,sha256=XTKUJzS3UIYn6h3CHzDEWKYJaWn0TzGiUCq3OeW27E0,3326
148
148
  svc_infra/cli/cmds/help.py,sha256=wGfZFMYaR2ZPwW2JwKDU7M3m4AtdCd8GRQ412AmEBUM,758
@@ -296,7 +296,7 @@ svc_infra/webhooks/fastapi.py,sha256=BCNvGNxukf6dC2a4i-6en-PrjBGV19YvCWOot5lXWsA
296
296
  svc_infra/webhooks/router.py,sha256=6JvAVPMEth_xxHX-IsIOcyMgHX7g1H0OVxVXKLuMp9w,1596
297
297
  svc_infra/webhooks/service.py,sha256=hWgiJRXKBwKunJOx91C7EcLUkotDtD3Xp0RT6vj2IC0,1797
298
298
  svc_infra/webhooks/signing.py,sha256=NCwdZzmravUe7HVIK_uXK0qqf12FG-_MVsgPvOw6lsM,784
299
- svc_infra-0.1.619.dist-info/METADATA,sha256=yoqsuCYdTjgJVgqMPZDDVIjbd5xDW7KQ7XbNRlbsPfA,8106
300
- svc_infra-0.1.619.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
301
- svc_infra-0.1.619.dist-info/entry_points.txt,sha256=6x_nZOsjvn6hRZsMgZLgTasaCSKCgAjsGhACe_CiP0U,48
302
- svc_infra-0.1.619.dist-info/RECORD,,
299
+ svc_infra-0.1.621.dist-info/METADATA,sha256=QD-ETuukvgwtsMr9N5ylyIOBUgPW6yms4kDLJbFN1H4,8106
300
+ svc_infra-0.1.621.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
301
+ svc_infra-0.1.621.dist-info/entry_points.txt,sha256=6x_nZOsjvn6hRZsMgZLgTasaCSKCgAjsGhACe_CiP0U,48
302
+ svc_infra-0.1.621.dist-info/RECORD,,