ambitgraph 0.9.0__tar.gz → 0.9.2__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.
Files changed (122) hide show
  1. {ambitgraph-0.9.0/ambitgraph.egg-info → ambitgraph-0.9.2}/PKG-INFO +1 -1
  2. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/__main__.py +1 -1
  3. ambitgraph-0.9.2/ambit_map/assistant.py +152 -0
  4. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/cli.py +51 -33
  5. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/mapllm.py +197 -234
  6. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/serve.py +12 -12
  7. ambitgraph-0.9.2/ambitgraph/__init__.py +34 -0
  8. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/_delimited.py +55 -27
  9. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/config.py +5 -0
  10. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/console.py +143 -74
  11. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/demo.py +76 -25
  12. ambitgraph-0.9.2/ambitgraph/docs_discovery.py +365 -0
  13. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/doctor.py +89 -19
  14. ambitgraph-0.9.2/ambitgraph/engine_identity.py +86 -0
  15. ambitgraph-0.9.2/ambitgraph/eval.py +178 -0
  16. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/explain.py +45 -64
  17. ambitgraph-0.9.2/ambitgraph/explain_stage.py +504 -0
  18. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/families.py +157 -83
  19. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/feeds.py +42 -14
  20. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/gate_check.py +285 -120
  21. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/gate_server.py +16 -1
  22. ambitgraph-0.9.2/ambitgraph/harvest.py +644 -0
  23. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/inventory.py +113 -39
  24. ambitgraph-0.9.2/ambitgraph/jsobjects.py +824 -0
  25. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/langs.py +24 -14
  26. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/mds.py +80 -21
  27. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/objects.py +57 -17
  28. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/omniscient_next/__init__.py +179 -59
  29. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/omniscient_next/_init_js.py +12 -1
  30. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/omniscient_next/charts.js +3 -1
  31. ambitgraph-0.9.2/ambitgraph/omniscient_next/classdiagram.js +1224 -0
  32. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/omniscient_next/graph.js +37 -0
  33. ambitgraph-0.9.2/ambitgraph/omniscient_next/insideview.js +1491 -0
  34. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/omniscient_next/library.js +375 -235
  35. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/omniscient_next/next_embed.css +184 -46
  36. ambitgraph-0.9.2/ambitgraph/omniscient_next/objectcard.js +402 -0
  37. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/pipeline.py +75 -7
  38. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/prompts.py +37 -15
  39. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/pyshapes.py +46 -0
  40. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/report.py +7 -10
  41. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/reports.py +41 -20
  42. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/responsibility.py +73 -41
  43. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/sample.py +7 -4
  44. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/shell.py +11 -16
  45. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/stages.py +69 -2
  46. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/symbols.py +361 -95
  47. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/tables.py +114 -89
  48. ambitgraph-0.9.2/ambitgraph/tasks.py +158 -0
  49. ambitgraph-0.9.2/ambitgraph/text_capture.py +190 -0
  50. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/urcode.py +35 -16
  51. {ambitgraph-0.9.0 → ambitgraph-0.9.2/ambitgraph.egg-info}/PKG-INFO +1 -1
  52. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph.egg-info/SOURCES.txt +7 -0
  53. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/pyproject.toml +1 -1
  54. ambitgraph-0.9.0/ambitgraph/__init__.py +0 -39
  55. ambitgraph-0.9.0/ambitgraph/docs_discovery.py +0 -281
  56. ambitgraph-0.9.0/ambitgraph/engine_identity.py +0 -87
  57. ambitgraph-0.9.0/ambitgraph/eval.py +0 -126
  58. ambitgraph-0.9.0/ambitgraph/harvest.py +0 -510
  59. ambitgraph-0.9.0/ambitgraph/tasks.py +0 -105
  60. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/LICENSE +0 -0
  61. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/MANIFEST.in +0 -0
  62. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/README.md +0 -0
  63. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_contracts/__init__.py +0 -0
  64. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_contracts/edge.py +0 -0
  65. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_contracts/envelope.py +0 -0
  66. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_contracts/fields.py +0 -0
  67. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_contracts/grant.py +0 -0
  68. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_contracts/household.py +0 -0
  69. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/__init__.py +0 -0
  70. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/ambit-map-enrich.md +0 -0
  71. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/ambit-mapllm-contract.md +0 -0
  72. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/daemon.py +0 -0
  73. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/dialects/__init__.py +0 -0
  74. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/dialects/contract.py +0 -0
  75. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/dialects/express_pack.py +0 -0
  76. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/dialects/fastapi_pack.py +0 -0
  77. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/dialects/flask_pack.py +0 -0
  78. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/dialects/nextjs_pack.py +0 -0
  79. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/dialects/supabase_pack.py +0 -0
  80. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/langmirror.py +0 -0
  81. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/load.py +0 -0
  82. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/model.py +0 -0
  83. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/orchestrate.py +0 -0
  84. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_map/registry.py +0 -0
  85. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_telegraph/__init__.py +0 -0
  86. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_telegraph/cli.py +0 -0
  87. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_telegraph/export.py +0 -0
  88. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_telegraph/ledger.py +0 -0
  89. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_telegraph/responsibility.py +0 -0
  90. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambit_telegraph/store.py +0 -0
  91. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/WALKTHROUGH.md +0 -0
  92. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/__main__.py +0 -0
  93. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/cli.py +0 -0
  94. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/cockpit.py +0 -0
  95. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/codelib.py +0 -0
  96. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/design_tokens.py +0 -0
  97. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/duplication.py +0 -0
  98. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/edges.py +0 -0
  99. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/emit.py +0 -0
  100. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/estimate.py +0 -0
  101. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/gate.py +0 -0
  102. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/html_safe.py +0 -0
  103. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/jscalls.py +0 -0
  104. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/merge.py +0 -0
  105. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/merge_jsp.py +0 -0
  106. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/omniscient_next/escape.js +0 -0
  107. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/omniscient_next/filterpanel.js +0 -0
  108. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/omniscient_next/paths.js +0 -0
  109. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/omniscient_next/search.js +0 -0
  110. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/omniscient_next/siderail.js +0 -0
  111. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/omniscient_next/standalone.py +0 -0
  112. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/omniscient_next/wholemap.js +0 -0
  113. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/parameterize.py +0 -0
  114. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/portal.py +0 -0
  115. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/pycalls.py +0 -0
  116. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/ratify.py +0 -0
  117. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph/secretary.py +0 -0
  118. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph.egg-info/dependency_links.txt +0 -0
  119. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph.egg-info/entry_points.txt +0 -0
  120. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph.egg-info/requires.txt +0 -0
  121. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/ambitgraph.egg-info/top_level.txt +0 -0
  122. {ambitgraph-0.9.0 → ambitgraph-0.9.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ambitgraph
3
- Version: 0.9.0
3
+ Version: 0.9.2
4
4
  Summary: Read-only codebase scan: reusable units, families, roles, ownership candidates, duplication.
5
5
  Author: AmbitGraph
6
6
  License: Proprietary
@@ -3,4 +3,4 @@ import sys
3
3
  from .cli import main
4
4
 
5
5
  if __name__ == "__main__":
6
- sys.exit(main(sys.argv[1:]))
6
+ sys.exit(main(sys.argv[1:])) # argv[1:]: the arguments after the program name
@@ -0,0 +1,152 @@
1
+ # -*- coding: utf-8 -*-
2
+ """ambit_map/assistant.py -- the instruction set: what a person is told so that
3
+ their own assistant can write the explanations, and the product never has to.
4
+
5
+ WHAT THIS MODULE HIDES: how the three steps are worded and where they appear.
6
+ The same three steps are shown on the terminal, in the run folder's readme and
7
+ on the served page, and they come from ONE list here -- three surfaces with
8
+ three wordings is how a person follows two of them and gets stuck.
9
+
10
+ IT NAMES PLACES ON THE MACHINE ON PURPOSE. A person has to find the task file
11
+ to hand it to their assistant, so these surfaces print real paths. That is
12
+ safe only because none of them is ever carried into an exported payload: the
13
+ export's own guarantee is pinned on the engine side, and this lane's own half
14
+ is that everything it writes lands under the run directory.
15
+
16
+ NOTHING HERE OPENS A WINDOW UNASKED. The page is opened through a caller's own
17
+ opener, and a person who asked for no browser gets none.
18
+ """
19
+
20
+ #: The three steps, in order, worded once and shown on every surface.
21
+ STEPS = (
22
+ "1. Open the task file and hand it to your assistant.",
23
+ "2. Have your assistant write its answers into the results file.",
24
+ "3. Rebuild the map; the explanations appear on each file's page.",
25
+ )
26
+
27
+ #: What the page says about where the run stands. The three states are three
28
+ #: different facts for the person waiting, so each gets its own sentence.
29
+ _STATE_LINES = {
30
+ "waiting": "Waiting for the results file to be written.",
31
+ "received": "The results file has arrived and is being read.",
32
+ "done": "The explanations are in the map.",
33
+ }
34
+
35
+
36
+ class Page:
37
+ """One rendering of the instruction page: its full text, the line a person
38
+ copies, and the sentence naming where the run stands."""
39
+
40
+ def __init__(self, text, copy_line, state_line):
41
+ """Hold one rendering's three parts.
42
+
43
+ @param text: the page's full text (str)
44
+ @param copy_line: the line a person copies (str)
45
+ @param state_line: the sentence naming where the run stands (str)
46
+ """
47
+ self.text = text
48
+ self.copy_line = copy_line
49
+ self.state_line = state_line
50
+
51
+
52
+ def state_line(state):
53
+ """The sentence naming where the run stands.
54
+
55
+ @param state: one of "waiting", "received" or "done" (str)
56
+ @return: the sentence for that state (str)
57
+ @raises KeyError: when the state is not one of the three
58
+ """
59
+ return _STATE_LINES[state] # the fixed sentence for this state; an unknown state raises KeyError
60
+
61
+
62
+ def build_page(state, run_dir, task_path, results_path, folder):
63
+ """Render the instruction page a person reads while the run waits.
64
+
65
+ Logic: the state sentence, the three steps, the copy line, and the three
66
+ paths a person needs -- the folder being mapped, the task to hand over,
67
+ and the results file to write. Every path is printed because a person
68
+ cannot act on a description of a location.
69
+
70
+ @param state: where the run stands (str)
71
+ @param run_dir: the run directory (str)
72
+ @param task_path: the task file to hand to an assistant (str)
73
+ @param results_path: the file the answers are written into (str)
74
+ @param folder: the folder being mapped (str)
75
+ @return: the rendered page (Page)
76
+ """
77
+ line_to_copy = task_path
78
+ body = [
79
+ "Explanations for %s" % folder,
80
+ state_line(state),
81
+ "",
82
+ ]
83
+ body.extend(STEPS)
84
+ body.extend([
85
+ "",
86
+ "The task file: %s" % task_path,
87
+ "Write the answers to: %s" % results_path,
88
+ "This run: %s" % run_dir,
89
+ ])
90
+ return Page("\n".join(body), line_to_copy, state_line(state))
91
+
92
+
93
+ def build_readme(run_dir, task_path, results_path, folder):
94
+ """The same three steps, written into the run folder for a person who
95
+ finds the folder before the page.
96
+
97
+ @param run_dir: the run directory (str)
98
+ @param task_path: the task file to hand to an assistant (str)
99
+ @param results_path: the file the answers are written into (str)
100
+ @param folder: the folder being mapped (str)
101
+ @return: the readme's text (str)
102
+ """
103
+ body = ["Explanations for %s" % folder, ""]
104
+ body.extend(STEPS)
105
+ body.extend([
106
+ "",
107
+ "The task file: %s" % task_path,
108
+ "Write the answers to: %s" % results_path,
109
+ "This run: %s" % run_dir,
110
+ ])
111
+ return "\n".join(body)
112
+
113
+
114
+ def terminal_text(run_dir, task_path, results_path, folder):
115
+ """The same three steps, printed where the person already is.
116
+
117
+ @param run_dir: the run directory (str)
118
+ @param task_path: the task file to hand to an assistant (str)
119
+ @param results_path: the file the answers are written into (str)
120
+ @param folder: the folder being mapped (str)
121
+ @return: the terminal's text (str)
122
+ """
123
+ body = ["Explanations for %s" % folder, ""]
124
+ body.extend(STEPS)
125
+ body.extend([
126
+ "",
127
+ "Task: %s" % task_path,
128
+ "Answers: %s" % results_path,
129
+ "Run: %s" % run_dir,
130
+ ])
131
+ return "\n".join(body)
132
+
133
+
134
+ def show(state, no_open, opener, run_dir, task_path, results_path, folder):
135
+ """Render the page and, unless a person asked for no browser, open it.
136
+
137
+ Logic: the page is always built, so the terminal and the readme can carry
138
+ the same words; the opener is called only when a browser was wanted.
139
+
140
+ @param state: where the run stands (str)
141
+ @param no_open: True when the person asked for no browser (bool)
142
+ @param opener: called with the page's text when a browser is wanted (callable)
143
+ @param run_dir: the run directory (str)
144
+ @param task_path: the task file to hand to an assistant (str)
145
+ @param results_path: the file the answers are written into (str)
146
+ @param folder: the folder being mapped (str)
147
+ @return: the rendered page (Page)
148
+ """
149
+ page = build_page(state, run_dir, task_path, results_path, folder)
150
+ if not no_open:
151
+ opener(page.text)
152
+ return page
@@ -18,6 +18,11 @@ from . import daemon
18
18
 
19
19
 
20
20
  def build_parser() -> argparse.ArgumentParser:
21
+ """Build the command-line parser for `python -m ambit_map`.
22
+
23
+ @return: the configured parser, every map and launcher flag registered (argparse.ArgumentParser)
24
+ """
25
+ # p: the parser being built
21
26
  p = argparse.ArgumentParser(prog="ambit-map",
22
27
  description="Map a repository and serve it on loopback.")
23
28
  p.add_argument("repo", help="the repository to map (read-only)")
@@ -57,19 +62,21 @@ def build_parser() -> argparse.ArgumentParser:
57
62
 
58
63
 
59
64
  def cmd_map(args) -> int:
60
- """Map a repository and serve it on loopback. THE ONE ENTRY POINT.
61
-
62
- The engine seam (a lazy `from ambit_map import cli` inside an
63
- ambitgraph/cli.py command body, following the ambitgraph/cli.py:1396
64
- _cmd_gate pattern) will call cmd_map(args) UNCHANGED -- args need only carry the
65
- six attributes (repo, port, out, config, no_open, once), so an argparse
66
- Namespace built by the engine's own parser works verbatim. Do not add
67
- required positional parameters to this function. --patience,
68
- --stop/--status/--foreground/--idle-minutes are ALL read with getattr
69
- and a default, so a Namespace built by an OLDER engine parser (which has
70
- none of them) keeps working verbatim -- the exact failure mode
71
- (AttributeError traceback on every `python -m ambitgraph map ...`) this
72
- seam exists to prevent.
65
+ """Map a repository and serve it on loopback, or run the launcher's
66
+ stop/status/foreground control paths. THE ONE ENTRY POINT.
67
+ Logic: stop/status answer and exit without scanning; --once scans,
68
+ renders once and exits; the default re-attaches to a running map or
69
+ launches a detached child; --foreground serves in this process.
70
+
71
+ @param args: a Namespace carrying at least repo, port, out, config, no_open and once --
72
+ the engine seam (a lazy `from ambit_map import cli` inside an
73
+ ambitgraph/cli.py command body, following its own _cmd_gate
74
+ pattern) calls cmd_map(args) UNCHANGED and needs only those six, so
75
+ this function must never gain a required positional parameter;
76
+ --patience/--stop/--status/--foreground/--idle-minutes are read
77
+ with getattr and a default so a Namespace built by an OLDER
78
+ engine parser, which has none of them, keeps working verbatim (Namespace)
79
+ @return: the process exit code (int)
73
80
  """
74
81
  # getattr, never args.stop/.status/.foreground/.idle_minutes/.patience
75
82
  # directly -- see the docstring above.
@@ -86,20 +93,22 @@ def cmd_map(args) -> int:
86
93
  # path), never orch.plan() itself, which would mkdir the out dir and
87
94
  # write a fresh config just to answer a status question.
88
95
  if stop_flag or status_flag:
96
+ # repo_p: the repo path, resolved; out_p: the given --out, resolved, or the repo's own default
89
97
  repo_p = Path(args.repo).resolve()
90
98
  out_p = Path(args.out).resolve() if getattr(args, "out", None) else orch.default_out_dir(repo_p)
91
99
  if stop_flag:
100
+ # rc: the process exit code the called daemon function reports
92
101
  rc, message = daemon.stop(out_p, str(repo_p))
93
102
  print(message)
94
103
  return rc
95
- rc, message = daemon.status(out_p, str(repo_p))
104
+ rc, message = daemon.status(out_p, str(repo_p)) # rc: the exit code; message: the line to print
96
105
  print(message)
97
106
  return rc
98
107
 
99
108
  if args.once:
100
109
  try:
101
110
  plan = orch.plan(args.repo, out=args.out, config=args.config, budget=budget)
102
- result, model = orch.bootstrap(plan)
111
+ result, model = orch.bootstrap(plan) # result: this run's ScanResult; model: its MapModel
103
112
  # Drawing the page is the second child of this path, after the
104
113
  # scan, and it fails in its own ways -- inside the try so that a
105
114
  # builder that cannot draw says so and leaves, exactly as a scan
@@ -133,6 +142,7 @@ def cmd_map(args) -> int:
133
142
  print(str(exc))
134
143
  return 2
135
144
  cmd = daemon.invocation_form() + " map"
145
+ # rc: the detached child's exit code; lines: its lines to print; url: its page url or None
136
146
  rc, lines, url = daemon.launch(args, plan.out_dir, str(plan.repo), idle_minutes,
137
147
  budget_s=budget + 30, cmd=cmd)
138
148
  # flush=True, every line, BEFORE open_browser: a caller that piped
@@ -148,29 +158,26 @@ def cmd_map(args) -> int:
148
158
  orch.open_browser(url, not args.no_open)
149
159
  return rc
150
160
 
151
- # --foreground: today's srv.serve path (routing
152
- # through srv.serve() rather than duplicating bind/greet/open/serve is
153
- # what makes reg.SERVE_BANNER ever print at all), now ALSO writing the
154
- # serve file after the bind (on_bound) and carrying idle_minutes, so a
155
- # `--stop`/`--status` from another terminal can find and manage a
156
- # foreground-launched map exactly as it would a detached one.
161
+ # --foreground: serves through srv.serve() (never duplicating
162
+ # bind/greet/open/serve, which is what makes reg.SERVE_BANNER print at
163
+ # all), writing the serve file after the bind (on_bound) and carrying
164
+ # idle_minutes, so a `--stop`/`--status` from another terminal can find
165
+ # and manage a foreground-launched map exactly as it would a detached
166
+ # one.
157
167
  try:
158
168
  plan = orch.plan(args.repo, out=args.out, config=args.config, budget=budget)
159
169
  except orch.OutInsideRepo as exc:
160
170
  print(str(exc))
161
171
  return 2
162
172
 
163
- # The identity check runs BEFORE the scan, and before anything is
164
- # written: this path used to write its serve file without looking,
165
- # and the exiting server's own cleanup then deleted whatever file was
166
- # PRESENT -- which could be a different, still-running map's own
167
- # record. A live map for this repo refuses here instead: the running
168
- # url is printed, nothing is scanned, nothing is written or removed.
173
+ # The identity check runs BEFORE the scan and before anything is
174
+ # written, because a serve file written without it could replace a
175
+ # different, still-running map's own record. A live map for this
176
+ # repo refuses here instead: the running url is printed, nothing is
177
+ # scanned, nothing is written or removed.
169
178
  #
170
- # DAEMON_ALREADY_RUNNING is now the ONE line this
171
- # refusal prints, and it carries {url} itself -- a separate
172
- # DAEMON_REATTACH "-- opened it" used to print alongside it while this
173
- # path opens nothing, which was simply false.
179
+ # DAEMON_ALREADY_RUNNING carries {url} itself (DAEMON_DAMAGED precedes
180
+ # it only when the running map reports damage); this path opens nothing.
174
181
  #
175
182
  # A stale record that already_running's own identity check found and
176
183
  # removed along the way (dead pid, unreachable, wrong repo, pid
@@ -191,6 +198,7 @@ def cmd_map(args) -> int:
191
198
  # ever again.
192
199
  info, health, reason, installed = daemon.already_running(plan.out_dir, str(plan.repo))
193
200
  if health is not None and reason in (daemon.ENGINE_CHANGED, daemon.ENGINE_UNREADABLE):
201
+ # stop_code: daemon.stop's exit code; stop_message: its printable line
194
202
  stop_code, stop_message = daemon.stop(plan.out_dir, str(plan.repo))
195
203
  if stop_code != 0:
196
204
  print(stop_message)
@@ -208,13 +216,13 @@ def cmd_map(args) -> int:
208
216
  elif health is not None:
209
217
  url = "http://127.0.0.1:{0}/".format(info.get("port"))
210
218
  if health.get("damaged"):
211
- print(reg.DAEMON_DAMAGED.format(reason=health["damaged"]))
219
+ print(reg.DAEMON_DAMAGED.format(reason=health["damaged"])) # confirmed set by the check above
212
220
  print(reg.DAEMON_ALREADY_RUNNING.format(url=url, repo=args.repo,
213
221
  cmd=daemon.invocation_form() + " map"))
214
222
  return 2
215
223
 
216
224
  try:
217
- result, model = orch.bootstrap(plan)
225
+ result, model = orch.bootstrap(plan) # result: this run's ScanResult; model: its MapModel
218
226
  except orch.ScanFailed as exc:
219
227
  print(str(exc))
220
228
  return 2
@@ -228,6 +236,11 @@ def cmd_map(args) -> int:
228
236
  log_path = daemon.log_path_for(plan.out_dir)
229
237
 
230
238
  def on_bound(bound_port, token):
239
+ """Write the serve file once the server has actually bound its port.
240
+
241
+ @param bound_port: the port the server bound to (int)
242
+ @param token: the token the /stop route checks requests against, minted by serve() before the bind (str)
243
+ """
231
244
  # `token` is minted by serve() itself (before the bind) and
232
245
  # handed to this closure the same way `bound_port` is -- this
233
246
  # process never invents or reads it from anywhere else, so the
@@ -243,6 +256,11 @@ def cmd_map(args) -> int:
243
256
 
244
257
 
245
258
  def main(argv) -> int:
259
+ """Parse the command line and run cmd_map with it.
260
+
261
+ @param argv: the command-line arguments, excluding the program name (list of str)
262
+ @return: the process exit code (int)
263
+ """
246
264
  parser = build_parser()
247
265
  args = parser.parse_args(argv)
248
266
  return cmd_map(args)