okstra 0.108.0 → 0.109.0

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 (642) hide show
  1. package/package.json +1 -1
  2. package/runtime/BUILD.json +2 -2
  3. package/runtime/prompts/profiles/_common-contract.md +1 -1
  4. package/runtime/python/okstra_ctl/graphify_cmd.py +225 -0
  5. package/runtime/python/okstra_ctl/resolve_task_key.py +15 -9
  6. package/runtime/python/okstra_project/__init__.py +2 -0
  7. package/runtime/python/okstra_project/state.py +36 -0
  8. package/runtime/python/okstra_vendor/__init__.py +41 -0
  9. package/runtime/python/okstra_vendor/graphify/.vendored-version +1 -0
  10. package/runtime/python/okstra_vendor/graphify/__init__.py +28 -0
  11. package/runtime/python/okstra_vendor/graphify/__main__.py +1371 -0
  12. package/runtime/python/okstra_vendor/graphify/analyze.py +540 -0
  13. package/runtime/python/okstra_vendor/graphify/benchmark.py +129 -0
  14. package/runtime/python/okstra_vendor/graphify/build.py +107 -0
  15. package/runtime/python/okstra_vendor/graphify/cache.py +169 -0
  16. package/runtime/python/okstra_vendor/graphify/cluster.py +137 -0
  17. package/runtime/python/okstra_vendor/graphify/detect.py +510 -0
  18. package/runtime/python/okstra_vendor/graphify/export.py +1014 -0
  19. package/runtime/python/okstra_vendor/graphify/extract.py +3277 -0
  20. package/runtime/python/okstra_vendor/graphify/hooks.py +220 -0
  21. package/runtime/python/okstra_vendor/graphify/ingest.py +297 -0
  22. package/runtime/python/okstra_vendor/graphify/manifest.py +4 -0
  23. package/runtime/python/okstra_vendor/graphify/report.py +175 -0
  24. package/runtime/python/okstra_vendor/graphify/security.py +203 -0
  25. package/runtime/python/okstra_vendor/graphify/serve.py +373 -0
  26. package/runtime/python/okstra_vendor/graphify/skill-aider.md +1184 -0
  27. package/runtime/python/okstra_vendor/graphify/skill-claw.md +1184 -0
  28. package/runtime/python/okstra_vendor/graphify/skill-codex.md +1242 -0
  29. package/runtime/python/okstra_vendor/graphify/skill-copilot.md +1268 -0
  30. package/runtime/python/okstra_vendor/graphify/skill-droid.md +1239 -0
  31. package/runtime/python/okstra_vendor/graphify/skill-kiro.md +1183 -0
  32. package/runtime/python/okstra_vendor/graphify/skill-opencode.md +1238 -0
  33. package/runtime/python/okstra_vendor/graphify/skill-trae.md +1208 -0
  34. package/runtime/python/okstra_vendor/graphify/skill-vscode.md +253 -0
  35. package/runtime/python/okstra_vendor/graphify/skill-windows.md +1245 -0
  36. package/runtime/python/okstra_vendor/graphify/skill.md +1319 -0
  37. package/runtime/python/okstra_vendor/graphify/transcribe.py +182 -0
  38. package/runtime/python/okstra_vendor/graphify/validate.py +72 -0
  39. package/runtime/python/okstra_vendor/graphify/watch.py +188 -0
  40. package/runtime/python/okstra_vendor/graphify/wiki.py +214 -0
  41. package/runtime/python/okstra_vendor/networkx/__init__.py +62 -0
  42. package/runtime/python/okstra_vendor/networkx/algorithms/__init__.py +134 -0
  43. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/__init__.py +26 -0
  44. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clique.py +259 -0
  45. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clustering_coefficient.py +71 -0
  46. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/connectivity.py +412 -0
  47. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/density.py +396 -0
  48. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/distance_measures.py +150 -0
  49. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/dominating_set.py +149 -0
  50. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/kcomponents.py +369 -0
  51. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/matching.py +44 -0
  52. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/maxcut.py +143 -0
  53. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/ramsey.py +53 -0
  54. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/steinertree.py +265 -0
  55. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/__init__.py +0 -0
  56. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py +41 -0
  57. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_clique.py +112 -0
  58. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_connectivity.py +199 -0
  59. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_density.py +146 -0
  60. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_distance_measures.py +59 -0
  61. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_dominating_set.py +78 -0
  62. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_kcomponents.py +303 -0
  63. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_matching.py +8 -0
  64. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_maxcut.py +94 -0
  65. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_ramsey.py +31 -0
  66. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_steinertree.py +306 -0
  67. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_traveling_salesman.py +1014 -0
  68. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_treewidth.py +274 -0
  69. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_vertex_cover.py +68 -0
  70. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/traveling_salesman.py +1508 -0
  71. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/treewidth.py +255 -0
  72. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/vertex_cover.py +83 -0
  73. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/__init__.py +5 -0
  74. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/connectivity.py +122 -0
  75. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/correlation.py +302 -0
  76. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/mixing.py +255 -0
  77. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/neighbor_degree.py +160 -0
  78. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/pairs.py +127 -0
  79. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/__init__.py +0 -0
  80. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/base_test.py +81 -0
  81. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_connectivity.py +143 -0
  82. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_correlation.py +122 -0
  83. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_mixing.py +174 -0
  84. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_neighbor_degree.py +107 -0
  85. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_pairs.py +87 -0
  86. package/runtime/python/okstra_vendor/networkx/algorithms/asteroidal.py +164 -0
  87. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/__init__.py +88 -0
  88. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/basic.py +322 -0
  89. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/centrality.py +290 -0
  90. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/cluster.py +289 -0
  91. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/covering.py +57 -0
  92. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/edgelist.py +360 -0
  93. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/extendability.py +105 -0
  94. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/generators.py +603 -0
  95. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/link_analysis.py +316 -0
  96. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matching.py +590 -0
  97. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matrix.py +232 -0
  98. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/projection.py +526 -0
  99. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/redundancy.py +112 -0
  100. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/spectral.py +69 -0
  101. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/__init__.py +0 -0
  102. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_basic.py +125 -0
  103. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_centrality.py +192 -0
  104. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_cluster.py +84 -0
  105. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_covering.py +33 -0
  106. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_edgelist.py +240 -0
  107. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_extendability.py +334 -0
  108. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_generators.py +407 -0
  109. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_link_analysis.py +218 -0
  110. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matching.py +327 -0
  111. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matrix.py +138 -0
  112. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_project.py +409 -0
  113. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_redundancy.py +35 -0
  114. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py +80 -0
  115. package/runtime/python/okstra_vendor/networkx/algorithms/boundary.py +168 -0
  116. package/runtime/python/okstra_vendor/networkx/algorithms/bridges.py +205 -0
  117. package/runtime/python/okstra_vendor/networkx/algorithms/broadcasting.py +164 -0
  118. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/__init__.py +20 -0
  119. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness.py +591 -0
  120. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness_subset.py +236 -0
  121. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/closeness.py +282 -0
  122. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness.py +364 -0
  123. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness_subset.py +227 -0
  124. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_closeness.py +96 -0
  125. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/degree_alg.py +150 -0
  126. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/dispersion.py +107 -0
  127. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/eigenvector.py +357 -0
  128. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/flow_matrix.py +130 -0
  129. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/group.py +787 -0
  130. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/harmonic.py +88 -0
  131. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/katz.py +331 -0
  132. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/laplacian.py +150 -0
  133. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/load.py +200 -0
  134. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/percolation.py +128 -0
  135. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/reaching.py +209 -0
  136. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/second_order.py +141 -0
  137. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/subgraph_alg.py +361 -0
  138. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/__init__.py +0 -0
  139. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality.py +923 -0
  140. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality_subset.py +354 -0
  141. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_closeness_centrality.py +274 -0
  142. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py +259 -0
  143. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality_subset.py +147 -0
  144. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_closeness.py +43 -0
  145. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_degree_centrality.py +144 -0
  146. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_dispersion.py +73 -0
  147. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py +186 -0
  148. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_group.py +277 -0
  149. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_harmonic_centrality.py +122 -0
  150. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_katz_centrality.py +345 -0
  151. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_laplacian_centrality.py +220 -0
  152. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_load_centrality.py +344 -0
  153. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_percolation_centrality.py +87 -0
  154. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_reaching.py +140 -0
  155. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_second_order_centrality.py +82 -0
  156. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_subgraph.py +110 -0
  157. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_trophic.py +302 -0
  158. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_voterank.py +64 -0
  159. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/trophic.py +181 -0
  160. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/voterank_alg.py +95 -0
  161. package/runtime/python/okstra_vendor/networkx/algorithms/chains.py +172 -0
  162. package/runtime/python/okstra_vendor/networkx/algorithms/chordal.py +443 -0
  163. package/runtime/python/okstra_vendor/networkx/algorithms/clique.py +818 -0
  164. package/runtime/python/okstra_vendor/networkx/algorithms/cluster.py +732 -0
  165. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/__init__.py +4 -0
  166. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/equitable_coloring.py +505 -0
  167. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/greedy_coloring.py +565 -0
  168. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/__init__.py +0 -0
  169. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/test_coloring.py +863 -0
  170. package/runtime/python/okstra_vendor/networkx/algorithms/communicability_alg.py +163 -0
  171. package/runtime/python/okstra_vendor/networkx/algorithms/community/__init__.py +28 -0
  172. package/runtime/python/okstra_vendor/networkx/algorithms/community/asyn_fluid.py +153 -0
  173. package/runtime/python/okstra_vendor/networkx/algorithms/community/bipartitions.py +354 -0
  174. package/runtime/python/okstra_vendor/networkx/algorithms/community/centrality.py +171 -0
  175. package/runtime/python/okstra_vendor/networkx/algorithms/community/community_utils.py +30 -0
  176. package/runtime/python/okstra_vendor/networkx/algorithms/community/divisive.py +216 -0
  177. package/runtime/python/okstra_vendor/networkx/algorithms/community/kclique.py +79 -0
  178. package/runtime/python/okstra_vendor/networkx/algorithms/community/label_propagation.py +338 -0
  179. package/runtime/python/okstra_vendor/networkx/algorithms/community/leiden.py +162 -0
  180. package/runtime/python/okstra_vendor/networkx/algorithms/community/local.py +220 -0
  181. package/runtime/python/okstra_vendor/networkx/algorithms/community/louvain.py +384 -0
  182. package/runtime/python/okstra_vendor/networkx/algorithms/community/lukes.py +227 -0
  183. package/runtime/python/okstra_vendor/networkx/algorithms/community/modularity_max.py +452 -0
  184. package/runtime/python/okstra_vendor/networkx/algorithms/community/quality.py +347 -0
  185. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/__init__.py +0 -0
  186. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_asyn_fluid.py +147 -0
  187. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_bipartitions.py +157 -0
  188. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_centrality.py +85 -0
  189. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_divisive.py +106 -0
  190. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_kclique.py +91 -0
  191. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_label_propagation.py +241 -0
  192. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_leiden.py +138 -0
  193. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_local.py +76 -0
  194. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_louvain.py +264 -0
  195. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_lukes.py +152 -0
  196. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_modularity_max.py +340 -0
  197. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_quality.py +139 -0
  198. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_utils.py +26 -0
  199. package/runtime/python/okstra_vendor/networkx/algorithms/components/__init__.py +6 -0
  200. package/runtime/python/okstra_vendor/networkx/algorithms/components/attracting.py +115 -0
  201. package/runtime/python/okstra_vendor/networkx/algorithms/components/biconnected.py +394 -0
  202. package/runtime/python/okstra_vendor/networkx/algorithms/components/connected.py +282 -0
  203. package/runtime/python/okstra_vendor/networkx/algorithms/components/semiconnected.py +71 -0
  204. package/runtime/python/okstra_vendor/networkx/algorithms/components/strongly_connected.py +359 -0
  205. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/__init__.py +0 -0
  206. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_attracting.py +70 -0
  207. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_biconnected.py +248 -0
  208. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_connected.py +138 -0
  209. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_semiconnected.py +55 -0
  210. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_strongly_connected.py +193 -0
  211. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_weakly_connected.py +96 -0
  212. package/runtime/python/okstra_vendor/networkx/algorithms/components/weakly_connected.py +196 -0
  213. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/__init__.py +11 -0
  214. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/connectivity.py +811 -0
  215. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/cuts.py +616 -0
  216. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/disjoint_paths.py +408 -0
  217. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_augmentation.py +1270 -0
  218. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_kcomponents.py +592 -0
  219. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcomponents.py +220 -0
  220. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcutsets.py +235 -0
  221. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/stoerwagner.py +152 -0
  222. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/__init__.py +0 -0
  223. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_connectivity.py +421 -0
  224. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_cuts.py +309 -0
  225. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_disjoint_paths.py +249 -0
  226. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_augmentation.py +502 -0
  227. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py +488 -0
  228. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcomponents.py +323 -0
  229. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcutsets.py +280 -0
  230. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_stoer_wagner.py +102 -0
  231. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/utils.py +88 -0
  232. package/runtime/python/okstra_vendor/networkx/algorithms/core.py +588 -0
  233. package/runtime/python/okstra_vendor/networkx/algorithms/covering.py +142 -0
  234. package/runtime/python/okstra_vendor/networkx/algorithms/cuts.py +416 -0
  235. package/runtime/python/okstra_vendor/networkx/algorithms/cycles.py +1234 -0
  236. package/runtime/python/okstra_vendor/networkx/algorithms/d_separation.py +677 -0
  237. package/runtime/python/okstra_vendor/networkx/algorithms/dag.py +1392 -0
  238. package/runtime/python/okstra_vendor/networkx/algorithms/distance_measures.py +1095 -0
  239. package/runtime/python/okstra_vendor/networkx/algorithms/distance_regular.py +272 -0
  240. package/runtime/python/okstra_vendor/networkx/algorithms/dominance.py +142 -0
  241. package/runtime/python/okstra_vendor/networkx/algorithms/dominating.py +268 -0
  242. package/runtime/python/okstra_vendor/networkx/algorithms/efficiency_measures.py +167 -0
  243. package/runtime/python/okstra_vendor/networkx/algorithms/euler.py +470 -0
  244. package/runtime/python/okstra_vendor/networkx/algorithms/flow/__init__.py +11 -0
  245. package/runtime/python/okstra_vendor/networkx/algorithms/flow/boykovkolmogorov.py +370 -0
  246. package/runtime/python/okstra_vendor/networkx/algorithms/flow/capacityscaling.py +407 -0
  247. package/runtime/python/okstra_vendor/networkx/algorithms/flow/dinitz_alg.py +238 -0
  248. package/runtime/python/okstra_vendor/networkx/algorithms/flow/edmondskarp.py +241 -0
  249. package/runtime/python/okstra_vendor/networkx/algorithms/flow/gomory_hu.py +178 -0
  250. package/runtime/python/okstra_vendor/networkx/algorithms/flow/maxflow.py +611 -0
  251. package/runtime/python/okstra_vendor/networkx/algorithms/flow/mincost.py +356 -0
  252. package/runtime/python/okstra_vendor/networkx/algorithms/flow/networksimplex.py +662 -0
  253. package/runtime/python/okstra_vendor/networkx/algorithms/flow/preflowpush.py +425 -0
  254. package/runtime/python/okstra_vendor/networkx/algorithms/flow/shortestaugmentingpath.py +300 -0
  255. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/__init__.py +0 -0
  256. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gl1.gpickle.bz2 +0 -0
  257. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gw1.gpickle.bz2 +0 -0
  258. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/netgen-2.gpickle.bz2 +0 -0
  259. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_gomory_hu.py +128 -0
  260. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow.py +573 -0
  261. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow_large_graph.py +155 -0
  262. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_mincost.py +475 -0
  263. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_networksimplex.py +481 -0
  264. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/wlm3.gpickle.bz2 +0 -0
  265. package/runtime/python/okstra_vendor/networkx/algorithms/flow/utils.py +194 -0
  266. package/runtime/python/okstra_vendor/networkx/algorithms/graph_hashing.py +435 -0
  267. package/runtime/python/okstra_vendor/networkx/algorithms/graphical.py +483 -0
  268. package/runtime/python/okstra_vendor/networkx/algorithms/hierarchy.py +57 -0
  269. package/runtime/python/okstra_vendor/networkx/algorithms/hybrid.py +196 -0
  270. package/runtime/python/okstra_vendor/networkx/algorithms/isolate.py +107 -0
  271. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/__init__.py +7 -0
  272. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/ismags.py +1306 -0
  273. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorph.py +336 -0
  274. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorphvf2.py +1262 -0
  275. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/matchhelpers.py +352 -0
  276. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/temporalisomorphvf2.py +308 -0
  277. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/__init__.py +0 -0
  278. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.A99 +0 -0
  279. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.B99 +0 -0
  280. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.A99 +0 -0
  281. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.B99 +0 -0
  282. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_ismags.py +719 -0
  283. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphism.py +103 -0
  284. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py +490 -0
  285. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_match_helpers.py +64 -0
  286. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py +212 -0
  287. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py +202 -0
  288. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp.py +1655 -0
  289. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp_helpers.py +3118 -0
  290. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py +196 -0
  291. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tree_isomorphism.py +264 -0
  292. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2pp.py +1102 -0
  293. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2userfunc.py +192 -0
  294. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/__init__.py +2 -0
  295. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/hits_alg.py +337 -0
  296. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/pagerank_alg.py +498 -0
  297. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/__init__.py +0 -0
  298. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_hits.py +77 -0
  299. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_pagerank.py +213 -0
  300. package/runtime/python/okstra_vendor/networkx/algorithms/link_prediction.py +687 -0
  301. package/runtime/python/okstra_vendor/networkx/algorithms/lowest_common_ancestors.py +280 -0
  302. package/runtime/python/okstra_vendor/networkx/algorithms/matching.py +1148 -0
  303. package/runtime/python/okstra_vendor/networkx/algorithms/minors/__init__.py +27 -0
  304. package/runtime/python/okstra_vendor/networkx/algorithms/minors/contraction.py +738 -0
  305. package/runtime/python/okstra_vendor/networkx/algorithms/minors/tests/test_contraction.py +544 -0
  306. package/runtime/python/okstra_vendor/networkx/algorithms/mis.py +78 -0
  307. package/runtime/python/okstra_vendor/networkx/algorithms/moral.py +59 -0
  308. package/runtime/python/okstra_vendor/networkx/algorithms/node_classification.py +219 -0
  309. package/runtime/python/okstra_vendor/networkx/algorithms/non_randomness.py +155 -0
  310. package/runtime/python/okstra_vendor/networkx/algorithms/operators/__init__.py +4 -0
  311. package/runtime/python/okstra_vendor/networkx/algorithms/operators/all.py +324 -0
  312. package/runtime/python/okstra_vendor/networkx/algorithms/operators/binary.py +468 -0
  313. package/runtime/python/okstra_vendor/networkx/algorithms/operators/product.py +633 -0
  314. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/__init__.py +0 -0
  315. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_all.py +328 -0
  316. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_binary.py +451 -0
  317. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_product.py +491 -0
  318. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_unary.py +55 -0
  319. package/runtime/python/okstra_vendor/networkx/algorithms/operators/unary.py +77 -0
  320. package/runtime/python/okstra_vendor/networkx/algorithms/perfect_graph.py +73 -0
  321. package/runtime/python/okstra_vendor/networkx/algorithms/planar_drawing.py +464 -0
  322. package/runtime/python/okstra_vendor/networkx/algorithms/planarity.py +1463 -0
  323. package/runtime/python/okstra_vendor/networkx/algorithms/polynomials.py +306 -0
  324. package/runtime/python/okstra_vendor/networkx/algorithms/reciprocity.py +98 -0
  325. package/runtime/python/okstra_vendor/networkx/algorithms/regular.py +167 -0
  326. package/runtime/python/okstra_vendor/networkx/algorithms/richclub.py +138 -0
  327. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/__init__.py +5 -0
  328. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/astar.py +239 -0
  329. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/dense.py +264 -0
  330. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/generic.py +716 -0
  331. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/__init__.py +0 -0
  332. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_astar.py +254 -0
  333. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense.py +212 -0
  334. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py +88 -0
  335. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_generic.py +511 -0
  336. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_unweighted.py +149 -0
  337. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_weighted.py +983 -0
  338. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/unweighted.py +625 -0
  339. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/weighted.py +2542 -0
  340. package/runtime/python/okstra_vendor/networkx/algorithms/similarity.py +2107 -0
  341. package/runtime/python/okstra_vendor/networkx/algorithms/simple_paths.py +966 -0
  342. package/runtime/python/okstra_vendor/networkx/algorithms/smallworld.py +404 -0
  343. package/runtime/python/okstra_vendor/networkx/algorithms/smetric.py +30 -0
  344. package/runtime/python/okstra_vendor/networkx/algorithms/sparsifiers.py +296 -0
  345. package/runtime/python/okstra_vendor/networkx/algorithms/structuralholes.py +374 -0
  346. package/runtime/python/okstra_vendor/networkx/algorithms/summarization.py +564 -0
  347. package/runtime/python/okstra_vendor/networkx/algorithms/swap.py +406 -0
  348. package/runtime/python/okstra_vendor/networkx/algorithms/tests/__init__.py +0 -0
  349. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_asteroidal.py +23 -0
  350. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_boundary.py +154 -0
  351. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_bridges.py +144 -0
  352. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_broadcasting.py +109 -0
  353. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chains.py +136 -0
  354. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chordal.py +129 -0
  355. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_clique.py +300 -0
  356. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cluster.py +678 -0
  357. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_communicability.py +80 -0
  358. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_core.py +266 -0
  359. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_covering.py +85 -0
  360. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cuts.py +171 -0
  361. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cycles.py +984 -0
  362. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_d_separation.py +340 -0
  363. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dag.py +835 -0
  364. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_measures.py +831 -0
  365. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_regular.py +85 -0
  366. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominance.py +299 -0
  367. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominating.py +115 -0
  368. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_efficiency.py +58 -0
  369. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_euler.py +314 -0
  370. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graph_hashing.py +872 -0
  371. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graphical.py +163 -0
  372. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hierarchy.py +46 -0
  373. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hybrid.py +24 -0
  374. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_isolate.py +26 -0
  375. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_link_prediction.py +615 -0
  376. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_lowest_common_ancestors.py +459 -0
  377. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_matching.py +556 -0
  378. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_max_weight_clique.py +179 -0
  379. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_mis.py +62 -0
  380. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_moral.py +15 -0
  381. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_node_classification.py +140 -0
  382. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_non_randomness.py +60 -0
  383. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_perfect_graph.py +27 -0
  384. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planar_drawing.py +274 -0
  385. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planarity.py +556 -0
  386. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_polynomials.py +57 -0
  387. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_reciprocity.py +37 -0
  388. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_regular.py +88 -0
  389. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_richclub.py +149 -0
  390. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_similarity.py +1158 -0
  391. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_simple_paths.py +803 -0
  392. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smallworld.py +76 -0
  393. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smetric.py +8 -0
  394. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_sparsifiers.py +138 -0
  395. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_structuralholes.py +191 -0
  396. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_summarization.py +642 -0
  397. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_swap.py +179 -0
  398. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_threshold.py +270 -0
  399. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_time_dependent.py +431 -0
  400. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_tournament.py +161 -0
  401. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_triads.py +248 -0
  402. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_vitality.py +41 -0
  403. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_voronoi.py +103 -0
  404. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_walks.py +54 -0
  405. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_wiener.py +157 -0
  406. package/runtime/python/okstra_vendor/networkx/algorithms/threshold.py +981 -0
  407. package/runtime/python/okstra_vendor/networkx/algorithms/time_dependent.py +142 -0
  408. package/runtime/python/okstra_vendor/networkx/algorithms/tournament.py +406 -0
  409. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/__init__.py +5 -0
  410. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/beamsearch.py +90 -0
  411. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/breadth_first_search.py +576 -0
  412. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/depth_first_search.py +529 -0
  413. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgebfs.py +185 -0
  414. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgedfs.py +182 -0
  415. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/__init__.py +0 -0
  416. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_beamsearch.py +25 -0
  417. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_bfs.py +203 -0
  418. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_dfs.py +307 -0
  419. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgebfs.py +147 -0
  420. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgedfs.py +131 -0
  421. package/runtime/python/okstra_vendor/networkx/algorithms/tree/__init__.py +7 -0
  422. package/runtime/python/okstra_vendor/networkx/algorithms/tree/branchings.py +1042 -0
  423. package/runtime/python/okstra_vendor/networkx/algorithms/tree/coding.py +413 -0
  424. package/runtime/python/okstra_vendor/networkx/algorithms/tree/decomposition.py +88 -0
  425. package/runtime/python/okstra_vendor/networkx/algorithms/tree/distance_measures.py +219 -0
  426. package/runtime/python/okstra_vendor/networkx/algorithms/tree/mst.py +1281 -0
  427. package/runtime/python/okstra_vendor/networkx/algorithms/tree/operations.py +106 -0
  428. package/runtime/python/okstra_vendor/networkx/algorithms/tree/recognition.py +273 -0
  429. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/__init__.py +0 -0
  430. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_branchings.py +624 -0
  431. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_coding.py +114 -0
  432. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_decomposition.py +79 -0
  433. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_distance_measures.py +99 -0
  434. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_mst.py +934 -0
  435. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_operations.py +53 -0
  436. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_recognition.py +174 -0
  437. package/runtime/python/okstra_vendor/networkx/algorithms/triads.py +500 -0
  438. package/runtime/python/okstra_vendor/networkx/algorithms/vitality.py +76 -0
  439. package/runtime/python/okstra_vendor/networkx/algorithms/voronoi.py +86 -0
  440. package/runtime/python/okstra_vendor/networkx/algorithms/walks.py +77 -0
  441. package/runtime/python/okstra_vendor/networkx/algorithms/wiener.py +278 -0
  442. package/runtime/python/okstra_vendor/networkx/classes/__init__.py +13 -0
  443. package/runtime/python/okstra_vendor/networkx/classes/coreviews.py +435 -0
  444. package/runtime/python/okstra_vendor/networkx/classes/digraph.py +1363 -0
  445. package/runtime/python/okstra_vendor/networkx/classes/filters.py +95 -0
  446. package/runtime/python/okstra_vendor/networkx/classes/function.py +1549 -0
  447. package/runtime/python/okstra_vendor/networkx/classes/graph.py +2082 -0
  448. package/runtime/python/okstra_vendor/networkx/classes/graphviews.py +269 -0
  449. package/runtime/python/okstra_vendor/networkx/classes/multidigraph.py +977 -0
  450. package/runtime/python/okstra_vendor/networkx/classes/multigraph.py +1294 -0
  451. package/runtime/python/okstra_vendor/networkx/classes/reportviews.py +1447 -0
  452. package/runtime/python/okstra_vendor/networkx/classes/tests/__init__.py +0 -0
  453. package/runtime/python/okstra_vendor/networkx/classes/tests/dispatch_interface.py +192 -0
  454. package/runtime/python/okstra_vendor/networkx/classes/tests/historical_tests.py +476 -0
  455. package/runtime/python/okstra_vendor/networkx/classes/tests/test_coreviews.py +362 -0
  456. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph.py +331 -0
  457. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph_historical.py +110 -0
  458. package/runtime/python/okstra_vendor/networkx/classes/tests/test_filters.py +177 -0
  459. package/runtime/python/okstra_vendor/networkx/classes/tests/test_function.py +1045 -0
  460. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph.py +950 -0
  461. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph_historical.py +12 -0
  462. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graphviews.py +349 -0
  463. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multidigraph.py +459 -0
  464. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multigraph.py +528 -0
  465. package/runtime/python/okstra_vendor/networkx/classes/tests/test_reportviews.py +1421 -0
  466. package/runtime/python/okstra_vendor/networkx/classes/tests/test_special.py +131 -0
  467. package/runtime/python/okstra_vendor/networkx/classes/tests/test_subgraphviews.py +371 -0
  468. package/runtime/python/okstra_vendor/networkx/conftest.py +261 -0
  469. package/runtime/python/okstra_vendor/networkx/convert.py +502 -0
  470. package/runtime/python/okstra_vendor/networkx/convert_matrix.py +1314 -0
  471. package/runtime/python/okstra_vendor/networkx/drawing/__init__.py +7 -0
  472. package/runtime/python/okstra_vendor/networkx/drawing/layout.py +2036 -0
  473. package/runtime/python/okstra_vendor/networkx/drawing/nx_agraph.py +470 -0
  474. package/runtime/python/okstra_vendor/networkx/drawing/nx_latex.py +570 -0
  475. package/runtime/python/okstra_vendor/networkx/drawing/nx_pydot.py +361 -0
  476. package/runtime/python/okstra_vendor/networkx/drawing/nx_pylab.py +2978 -0
  477. package/runtime/python/okstra_vendor/networkx/drawing/tests/__init__.py +0 -0
  478. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_complex.png +0 -0
  479. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_empty_graph.png +0 -0
  480. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_house_with_colors.png +0 -0
  481. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_labels_and_colors.png +0 -0
  482. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_shortest_path.png +0 -0
  483. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_house_with_colors.png +0 -0
  484. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_agraph.py +237 -0
  485. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_image_comparison_pylab_mpl.py +229 -0
  486. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_latex.py +285 -0
  487. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_layout.py +631 -0
  488. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pydot.py +146 -0
  489. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pylab.py +1582 -0
  490. package/runtime/python/okstra_vendor/networkx/exception.py +131 -0
  491. package/runtime/python/okstra_vendor/networkx/generators/__init__.py +34 -0
  492. package/runtime/python/okstra_vendor/networkx/generators/atlas.dat.gz +0 -0
  493. package/runtime/python/okstra_vendor/networkx/generators/atlas.py +227 -0
  494. package/runtime/python/okstra_vendor/networkx/generators/classic.py +1091 -0
  495. package/runtime/python/okstra_vendor/networkx/generators/cographs.py +68 -0
  496. package/runtime/python/okstra_vendor/networkx/generators/community.py +1070 -0
  497. package/runtime/python/okstra_vendor/networkx/generators/degree_seq.py +886 -0
  498. package/runtime/python/okstra_vendor/networkx/generators/directed.py +572 -0
  499. package/runtime/python/okstra_vendor/networkx/generators/duplication.py +174 -0
  500. package/runtime/python/okstra_vendor/networkx/generators/ego.py +66 -0
  501. package/runtime/python/okstra_vendor/networkx/generators/expanders.py +499 -0
  502. package/runtime/python/okstra_vendor/networkx/generators/geometric.py +1037 -0
  503. package/runtime/python/okstra_vendor/networkx/generators/harary_graph.py +163 -0
  504. package/runtime/python/okstra_vendor/networkx/generators/internet_as_graphs.py +443 -0
  505. package/runtime/python/okstra_vendor/networkx/generators/intersection.py +125 -0
  506. package/runtime/python/okstra_vendor/networkx/generators/interval_graph.py +70 -0
  507. package/runtime/python/okstra_vendor/networkx/generators/joint_degree_seq.py +664 -0
  508. package/runtime/python/okstra_vendor/networkx/generators/lattice.py +405 -0
  509. package/runtime/python/okstra_vendor/networkx/generators/line.py +501 -0
  510. package/runtime/python/okstra_vendor/networkx/generators/mycielski.py +110 -0
  511. package/runtime/python/okstra_vendor/networkx/generators/nonisomorphic_trees.py +259 -0
  512. package/runtime/python/okstra_vendor/networkx/generators/random_clustered.py +117 -0
  513. package/runtime/python/okstra_vendor/networkx/generators/random_graphs.py +1416 -0
  514. package/runtime/python/okstra_vendor/networkx/generators/small.py +1070 -0
  515. package/runtime/python/okstra_vendor/networkx/generators/social.py +554 -0
  516. package/runtime/python/okstra_vendor/networkx/generators/spectral_graph_forge.py +120 -0
  517. package/runtime/python/okstra_vendor/networkx/generators/stochastic.py +54 -0
  518. package/runtime/python/okstra_vendor/networkx/generators/sudoku.py +131 -0
  519. package/runtime/python/okstra_vendor/networkx/generators/tests/__init__.py +0 -0
  520. package/runtime/python/okstra_vendor/networkx/generators/tests/test_atlas.py +75 -0
  521. package/runtime/python/okstra_vendor/networkx/generators/tests/test_classic.py +642 -0
  522. package/runtime/python/okstra_vendor/networkx/generators/tests/test_cographs.py +20 -0
  523. package/runtime/python/okstra_vendor/networkx/generators/tests/test_community.py +362 -0
  524. package/runtime/python/okstra_vendor/networkx/generators/tests/test_degree_seq.py +224 -0
  525. package/runtime/python/okstra_vendor/networkx/generators/tests/test_directed.py +189 -0
  526. package/runtime/python/okstra_vendor/networkx/generators/tests/test_duplication.py +103 -0
  527. package/runtime/python/okstra_vendor/networkx/generators/tests/test_ego.py +39 -0
  528. package/runtime/python/okstra_vendor/networkx/generators/tests/test_expanders.py +182 -0
  529. package/runtime/python/okstra_vendor/networkx/generators/tests/test_geometric.py +488 -0
  530. package/runtime/python/okstra_vendor/networkx/generators/tests/test_harary_graph.py +133 -0
  531. package/runtime/python/okstra_vendor/networkx/generators/tests/test_internet_as_graphs.py +221 -0
  532. package/runtime/python/okstra_vendor/networkx/generators/tests/test_intersection.py +28 -0
  533. package/runtime/python/okstra_vendor/networkx/generators/tests/test_interval_graph.py +144 -0
  534. package/runtime/python/okstra_vendor/networkx/generators/tests/test_joint_degree_seq.py +125 -0
  535. package/runtime/python/okstra_vendor/networkx/generators/tests/test_lattice.py +264 -0
  536. package/runtime/python/okstra_vendor/networkx/generators/tests/test_line.py +316 -0
  537. package/runtime/python/okstra_vendor/networkx/generators/tests/test_mycielski.py +30 -0
  538. package/runtime/python/okstra_vendor/networkx/generators/tests/test_nonisomorphic_trees.py +82 -0
  539. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_clustered.py +33 -0
  540. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_graphs.py +495 -0
  541. package/runtime/python/okstra_vendor/networkx/generators/tests/test_small.py +220 -0
  542. package/runtime/python/okstra_vendor/networkx/generators/tests/test_spectral_graph_forge.py +49 -0
  543. package/runtime/python/okstra_vendor/networkx/generators/tests/test_stochastic.py +72 -0
  544. package/runtime/python/okstra_vendor/networkx/generators/tests/test_sudoku.py +92 -0
  545. package/runtime/python/okstra_vendor/networkx/generators/tests/test_time_series.py +64 -0
  546. package/runtime/python/okstra_vendor/networkx/generators/tests/test_trees.py +195 -0
  547. package/runtime/python/okstra_vendor/networkx/generators/tests/test_triads.py +15 -0
  548. package/runtime/python/okstra_vendor/networkx/generators/time_series.py +74 -0
  549. package/runtime/python/okstra_vendor/networkx/generators/trees.py +1070 -0
  550. package/runtime/python/okstra_vendor/networkx/generators/triads.py +94 -0
  551. package/runtime/python/okstra_vendor/networkx/lazy_imports.py +188 -0
  552. package/runtime/python/okstra_vendor/networkx/linalg/__init__.py +13 -0
  553. package/runtime/python/okstra_vendor/networkx/linalg/algebraicconnectivity.py +650 -0
  554. package/runtime/python/okstra_vendor/networkx/linalg/attrmatrix.py +466 -0
  555. package/runtime/python/okstra_vendor/networkx/linalg/bethehessianmatrix.py +77 -0
  556. package/runtime/python/okstra_vendor/networkx/linalg/graphmatrix.py +168 -0
  557. package/runtime/python/okstra_vendor/networkx/linalg/laplacianmatrix.py +512 -0
  558. package/runtime/python/okstra_vendor/networkx/linalg/modularitymatrix.py +166 -0
  559. package/runtime/python/okstra_vendor/networkx/linalg/spectrum.py +186 -0
  560. package/runtime/python/okstra_vendor/networkx/linalg/tests/__init__.py +0 -0
  561. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_algebraic_connectivity.py +400 -0
  562. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_attrmatrix.py +108 -0
  563. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_bethehessian.py +40 -0
  564. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_graphmatrix.py +275 -0
  565. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_laplacian.py +334 -0
  566. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_modularity.py +86 -0
  567. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_spectrum.py +70 -0
  568. package/runtime/python/okstra_vendor/networkx/readwrite/__init__.py +17 -0
  569. package/runtime/python/okstra_vendor/networkx/readwrite/adjlist.py +330 -0
  570. package/runtime/python/okstra_vendor/networkx/readwrite/edgelist.py +489 -0
  571. package/runtime/python/okstra_vendor/networkx/readwrite/gexf.py +1084 -0
  572. package/runtime/python/okstra_vendor/networkx/readwrite/gml.py +879 -0
  573. package/runtime/python/okstra_vendor/networkx/readwrite/graph6.py +427 -0
  574. package/runtime/python/okstra_vendor/networkx/readwrite/graphml.py +1053 -0
  575. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/__init__.py +19 -0
  576. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/adjacency.py +156 -0
  577. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/cytoscape.py +190 -0
  578. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/node_link.py +261 -0
  579. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/__init__.py +0 -0
  580. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_adjacency.py +78 -0
  581. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_cytoscape.py +78 -0
  582. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_node_link.py +109 -0
  583. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_tree.py +48 -0
  584. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tree.py +137 -0
  585. package/runtime/python/okstra_vendor/networkx/readwrite/leda.py +108 -0
  586. package/runtime/python/okstra_vendor/networkx/readwrite/multiline_adjlist.py +393 -0
  587. package/runtime/python/okstra_vendor/networkx/readwrite/p2g.py +113 -0
  588. package/runtime/python/okstra_vendor/networkx/readwrite/pajek.py +286 -0
  589. package/runtime/python/okstra_vendor/networkx/readwrite/sparse6.py +379 -0
  590. package/runtime/python/okstra_vendor/networkx/readwrite/tests/__init__.py +0 -0
  591. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_adjlist.py +354 -0
  592. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_edgelist.py +318 -0
  593. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gexf.py +612 -0
  594. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gml.py +744 -0
  595. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graph6.py +181 -0
  596. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graphml.py +1531 -0
  597. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_leda.py +30 -0
  598. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_p2g.py +63 -0
  599. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_pajek.py +128 -0
  600. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_sparse6.py +166 -0
  601. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_text.py +1742 -0
  602. package/runtime/python/okstra_vendor/networkx/readwrite/text.py +851 -0
  603. package/runtime/python/okstra_vendor/networkx/relabel.py +285 -0
  604. package/runtime/python/okstra_vendor/networkx/tests/__init__.py +0 -0
  605. package/runtime/python/okstra_vendor/networkx/tests/test_all_random_functions.py +248 -0
  606. package/runtime/python/okstra_vendor/networkx/tests/test_convert.py +321 -0
  607. package/runtime/python/okstra_vendor/networkx/tests/test_convert_numpy.py +531 -0
  608. package/runtime/python/okstra_vendor/networkx/tests/test_convert_pandas.py +349 -0
  609. package/runtime/python/okstra_vendor/networkx/tests/test_convert_scipy.py +281 -0
  610. package/runtime/python/okstra_vendor/networkx/tests/test_exceptions.py +40 -0
  611. package/runtime/python/okstra_vendor/networkx/tests/test_import.py +11 -0
  612. package/runtime/python/okstra_vendor/networkx/tests/test_lazy_imports.py +96 -0
  613. package/runtime/python/okstra_vendor/networkx/tests/test_relabel.py +349 -0
  614. package/runtime/python/okstra_vendor/networkx/tests/test_removed_functions_exception_messages.py +8 -0
  615. package/runtime/python/okstra_vendor/networkx/utils/__init__.py +8 -0
  616. package/runtime/python/okstra_vendor/networkx/utils/backends.py +2171 -0
  617. package/runtime/python/okstra_vendor/networkx/utils/configs.py +396 -0
  618. package/runtime/python/okstra_vendor/networkx/utils/decorators.py +1233 -0
  619. package/runtime/python/okstra_vendor/networkx/utils/heaps.py +338 -0
  620. package/runtime/python/okstra_vendor/networkx/utils/mapped_queue.py +297 -0
  621. package/runtime/python/okstra_vendor/networkx/utils/misc.py +703 -0
  622. package/runtime/python/okstra_vendor/networkx/utils/random_sequence.py +198 -0
  623. package/runtime/python/okstra_vendor/networkx/utils/rcm.py +159 -0
  624. package/runtime/python/okstra_vendor/networkx/utils/tests/__init__.py +0 -0
  625. package/runtime/python/okstra_vendor/networkx/utils/tests/test__init.py +11 -0
  626. package/runtime/python/okstra_vendor/networkx/utils/tests/test_backends.py +225 -0
  627. package/runtime/python/okstra_vendor/networkx/utils/tests/test_config.py +263 -0
  628. package/runtime/python/okstra_vendor/networkx/utils/tests/test_decorators.py +510 -0
  629. package/runtime/python/okstra_vendor/networkx/utils/tests/test_heaps.py +131 -0
  630. package/runtime/python/okstra_vendor/networkx/utils/tests/test_mapped_queue.py +268 -0
  631. package/runtime/python/okstra_vendor/networkx/utils/tests/test_misc.py +393 -0
  632. package/runtime/python/okstra_vendor/networkx/utils/tests/test_random_sequence.py +53 -0
  633. package/runtime/python/okstra_vendor/networkx/utils/tests/test_rcm.py +63 -0
  634. package/runtime/python/okstra_vendor/networkx/utils/tests/test_unionfind.py +55 -0
  635. package/runtime/python/okstra_vendor/networkx/utils/union_find.py +106 -0
  636. package/runtime/skills/okstra-graphify/SKILL.md +161 -0
  637. package/runtime/skills/okstra-inspect/SKILL.md +17 -9
  638. package/runtime/templates/reports/settings.template.json +4 -0
  639. package/src/cli-registry.mjs +7 -0
  640. package/src/commands/graphify.mjs +32 -0
  641. package/src/commands/lifecycle/doctor.mjs +9 -0
  642. package/src/lib/skill-catalog.mjs +1 -0
@@ -0,0 +1,1233 @@
1
+ import bz2
2
+ import collections
3
+ import gzip
4
+ import inspect
5
+ import itertools
6
+ import re
7
+ from collections import defaultdict
8
+ from os.path import splitext
9
+ from pathlib import Path
10
+
11
+ import networkx as nx
12
+ from networkx.utils import create_py_random_state, create_random_state
13
+
14
+ __all__ = [
15
+ "not_implemented_for",
16
+ "open_file",
17
+ "nodes_or_number",
18
+ "np_random_state",
19
+ "py_random_state",
20
+ "argmap",
21
+ ]
22
+
23
+
24
+ def not_implemented_for(*graph_types):
25
+ """Decorator to mark algorithms as not implemented
26
+
27
+ Parameters
28
+ ----------
29
+ graph_types : container of strings
30
+ Entries must be one of "directed", "undirected", "multigraph", or "graph".
31
+
32
+ Returns
33
+ -------
34
+ _require : function
35
+ The decorated function.
36
+
37
+ Raises
38
+ ------
39
+ NetworkXNotImplemented
40
+ If any of the packages cannot be imported
41
+
42
+ Notes
43
+ -----
44
+ Multiple types are joined logically with "and".
45
+ For "or" use multiple @not_implemented_for() lines.
46
+
47
+ Examples
48
+ --------
49
+ Decorate functions like this::
50
+
51
+ @not_implemented_for("directed")
52
+ def sp_function(G):
53
+ pass
54
+
55
+
56
+ # rule out MultiDiGraph
57
+ @not_implemented_for("directed", "multigraph")
58
+ def sp_np_function(G):
59
+ pass
60
+
61
+
62
+ # rule out all except DiGraph
63
+ @not_implemented_for("undirected")
64
+ @not_implemented_for("multigraph")
65
+ def sp_np_function(G):
66
+ pass
67
+ """
68
+ if ("directed" in graph_types) and ("undirected" in graph_types):
69
+ raise ValueError("Function not implemented on directed AND undirected graphs?")
70
+ if ("multigraph" in graph_types) and ("graph" in graph_types):
71
+ raise ValueError("Function not implemented on graph AND multigraphs?")
72
+ if not set(graph_types) < {"directed", "undirected", "multigraph", "graph"}:
73
+ raise KeyError(
74
+ "use one or more of directed, undirected, multigraph, graph. "
75
+ f"You used {graph_types}"
76
+ )
77
+
78
+ # 3-way logic: True if "directed" input, False if "undirected" input, else None
79
+ dval = ("directed" in graph_types) or "undirected" not in graph_types and None
80
+ mval = ("multigraph" in graph_types) or "graph" not in graph_types and None
81
+ errmsg = f"not implemented for {' '.join(graph_types)} type"
82
+
83
+ def _not_implemented_for(g):
84
+ if (mval is None or mval == g.is_multigraph()) and (
85
+ dval is None or dval == g.is_directed()
86
+ ):
87
+ raise nx.NetworkXNotImplemented(errmsg)
88
+
89
+ return g
90
+
91
+ return argmap(_not_implemented_for, 0)
92
+
93
+
94
+ # To handle new extensions, define a function accepting a `path` and `mode`.
95
+ # Then add the extension to _dispatch_dict.
96
+ fopeners = {
97
+ ".gz": gzip.open,
98
+ ".gzip": gzip.open,
99
+ ".bz2": bz2.BZ2File,
100
+ }
101
+ _dispatch_dict = defaultdict(lambda: open, **fopeners)
102
+
103
+
104
+ def open_file(path_arg, mode="r"):
105
+ """Decorator to ensure clean opening and closing of files.
106
+
107
+ Parameters
108
+ ----------
109
+ path_arg : string or int
110
+ Name or index of the argument that is a path.
111
+
112
+ mode : str
113
+ String for opening mode.
114
+
115
+ Returns
116
+ -------
117
+ _open_file : function
118
+ Function which cleanly executes the io.
119
+
120
+ Examples
121
+ --------
122
+ Decorate functions like this::
123
+
124
+ @open_file(0, "r")
125
+ def read_function(pathname):
126
+ pass
127
+
128
+
129
+ @open_file(1, "w")
130
+ def write_function(G, pathname):
131
+ pass
132
+
133
+
134
+ @open_file(1, "w")
135
+ def write_function(G, pathname="graph.dot"):
136
+ pass
137
+
138
+
139
+ @open_file("pathname", "w")
140
+ def write_function(G, pathname="graph.dot"):
141
+ pass
142
+
143
+
144
+ @open_file("path", "w+")
145
+ def another_function(arg, **kwargs):
146
+ path = kwargs["path"]
147
+ pass
148
+
149
+ Notes
150
+ -----
151
+ Note that this decorator solves the problem when a path argument is
152
+ specified as a string, but it does not handle the situation when the
153
+ function wants to accept a default of None (and then handle it).
154
+
155
+ Here is an example of how to handle this case::
156
+
157
+ @open_file("path")
158
+ def some_function(arg1, arg2, path=None):
159
+ if path is None:
160
+ fobj = tempfile.NamedTemporaryFile(delete=False)
161
+ else:
162
+ # `path` could have been a string or file object or something
163
+ # similar. In any event, the decorator has given us a file object
164
+ # and it will close it for us, if it should.
165
+ fobj = path
166
+
167
+ try:
168
+ fobj.write("blah")
169
+ finally:
170
+ if path is None:
171
+ fobj.close()
172
+
173
+ Normally, we'd want to use "with" to ensure that fobj gets closed.
174
+ However, the decorator will make `path` a file object for us,
175
+ and using "with" would undesirably close that file object.
176
+ Instead, we use a try block, as shown above.
177
+ When we exit the function, fobj will be closed, if it should be, by the decorator.
178
+ """
179
+
180
+ def _open_file(path):
181
+ # Now we have the path_arg. There are two types of input to consider:
182
+ # 1) string representing a path that should be opened
183
+ # 2) an already opened file object
184
+ if isinstance(path, str):
185
+ ext = splitext(path)[1]
186
+ elif isinstance(path, Path):
187
+ # path is a pathlib reference to a filename
188
+ ext = path.suffix
189
+ path = str(path)
190
+ else:
191
+ # could be None, or a file handle, in which case the algorithm will deal with it
192
+ return path, lambda: None
193
+
194
+ fobj = _dispatch_dict[ext](path, mode=mode)
195
+ return fobj, lambda: fobj.close()
196
+
197
+ return argmap(_open_file, path_arg, try_finally=True)
198
+
199
+
200
+ def nodes_or_number(which_args):
201
+ """Decorator to allow number of nodes or container of nodes.
202
+
203
+ With this decorator, the specified argument can be either a number or a container
204
+ of nodes. If it is a number, the nodes used are `range(n)`.
205
+ This allows `nx.complete_graph(50)` in place of `nx.complete_graph(list(range(50)))`.
206
+ And it also allows `nx.complete_graph(any_list_of_nodes)`.
207
+
208
+ Parameters
209
+ ----------
210
+ which_args : string or int or sequence of strings or ints
211
+ If string, the name of the argument to be treated.
212
+ If int, the index of the argument to be treated.
213
+ If more than one node argument is allowed, can be a list of locations.
214
+
215
+ Returns
216
+ -------
217
+ _nodes_or_numbers : function
218
+ Function which replaces int args with ranges.
219
+
220
+ Examples
221
+ --------
222
+ Decorate functions like this::
223
+
224
+ @nodes_or_number("nodes")
225
+ def empty_graph(nodes):
226
+ # nodes is converted to a list of nodes
227
+
228
+ @nodes_or_number(0)
229
+ def empty_graph(nodes):
230
+ # nodes is converted to a list of nodes
231
+
232
+ @nodes_or_number(["m1", "m2"])
233
+ def grid_2d_graph(m1, m2, periodic=False):
234
+ # m1 and m2 are each converted to a list of nodes
235
+
236
+ @nodes_or_number([0, 1])
237
+ def grid_2d_graph(m1, m2, periodic=False):
238
+ # m1 and m2 are each converted to a list of nodes
239
+
240
+ @nodes_or_number(1)
241
+ def full_rary_tree(r, n)
242
+ # presumably r is a number. It is not handled by this decorator.
243
+ # n is converted to a list of nodes
244
+ """
245
+
246
+ def _nodes_or_number(n):
247
+ try:
248
+ nodes = list(range(n))
249
+ except TypeError:
250
+ nodes = tuple(n)
251
+ else:
252
+ if n < 0:
253
+ raise nx.NetworkXError(f"Negative number of nodes not valid: {n}")
254
+ return (n, nodes)
255
+
256
+ try:
257
+ iter_wa = iter(which_args)
258
+ except TypeError:
259
+ iter_wa = (which_args,)
260
+
261
+ return argmap(_nodes_or_number, *iter_wa)
262
+
263
+
264
+ def np_random_state(random_state_argument):
265
+ """Decorator to generate a numpy RandomState or Generator instance.
266
+
267
+ The decorator processes the argument indicated by `random_state_argument`
268
+ using :func:`nx.utils.create_random_state`.
269
+ The argument value can be a seed (integer), or a `numpy.random.RandomState`
270
+ or `numpy.random.RandomState` instance or (`None` or `numpy.random`).
271
+ The latter two options use the global random number generator for `numpy.random`.
272
+
273
+ The returned instance is a `numpy.random.RandomState` or `numpy.random.Generator`.
274
+
275
+ Parameters
276
+ ----------
277
+ random_state_argument : string or int
278
+ The name or index of the argument to be converted
279
+ to a `numpy.random.RandomState` instance.
280
+
281
+ Returns
282
+ -------
283
+ _random_state : function
284
+ Function whose random_state keyword argument is a RandomState instance.
285
+
286
+ Examples
287
+ --------
288
+ Decorate functions like this::
289
+
290
+ @np_random_state("seed")
291
+ def random_float(seed=None):
292
+ return seed.rand()
293
+
294
+
295
+ @np_random_state(0)
296
+ def random_float(rng=None):
297
+ return rng.rand()
298
+
299
+
300
+ @np_random_state(1)
301
+ def random_array(dims, random_state=1):
302
+ return random_state.rand(*dims)
303
+
304
+ See Also
305
+ --------
306
+ py_random_state
307
+ """
308
+ return argmap(create_random_state, random_state_argument)
309
+
310
+
311
+ def py_random_state(random_state_argument):
312
+ """Decorator to generate a random.Random instance (or equiv).
313
+
314
+ This decorator processes `random_state_argument` using
315
+ :func:`nx.utils.create_py_random_state`.
316
+ The input value can be a seed (integer), or a random number generator::
317
+
318
+ If int, return a random.Random instance set with seed=int.
319
+ If random.Random instance, return it.
320
+ If None or the `random` package, return the global random number
321
+ generator used by `random`.
322
+ If np.random package, or the default numpy RandomState instance,
323
+ return the default numpy random number generator wrapped in a
324
+ `PythonRandomViaNumpyBits` class.
325
+ If np.random.Generator instance, return it wrapped in a
326
+ `PythonRandomViaNumpyBits` class.
327
+
328
+ # Legacy options
329
+ If np.random.RandomState instance, return it wrapped in a
330
+ `PythonRandomInterface` class.
331
+ If a `PythonRandomInterface` instance, return it
332
+
333
+ Parameters
334
+ ----------
335
+ random_state_argument : string or int
336
+ The name of the argument or the index of the argument in args that is
337
+ to be converted to the random.Random instance or numpy.random.RandomState
338
+ instance that mimics basic methods of random.Random.
339
+
340
+ Returns
341
+ -------
342
+ _random_state : function
343
+ Function whose random_state_argument is converted to a Random instance.
344
+
345
+ Examples
346
+ --------
347
+ Decorate functions like this::
348
+
349
+ @py_random_state("random_state")
350
+ def random_float(random_state=None):
351
+ return random_state.rand()
352
+
353
+
354
+ @py_random_state(0)
355
+ def random_float(rng=None):
356
+ return rng.rand()
357
+
358
+
359
+ @py_random_state(1)
360
+ def random_array(dims, seed=12345):
361
+ return seed.rand(*dims)
362
+
363
+ See Also
364
+ --------
365
+ np_random_state
366
+ """
367
+
368
+ return argmap(create_py_random_state, random_state_argument)
369
+
370
+
371
+ class argmap:
372
+ """A decorator to apply a map to arguments before calling the function
373
+
374
+ This class provides a decorator that maps (transforms) arguments of the function
375
+ before the function is called. Thus for example, we have similar code
376
+ in many functions to determine whether an argument is the number of nodes
377
+ to be created, or a list of nodes to be handled. The decorator provides
378
+ the code to accept either -- transforming the indicated argument into a
379
+ list of nodes before the actual function is called.
380
+
381
+ This decorator class allows us to process single or multiple arguments.
382
+ The arguments to be processed can be specified by string, naming the argument,
383
+ or by index, specifying the item in the args list.
384
+
385
+ Parameters
386
+ ----------
387
+ func : callable
388
+ The function to apply to arguments
389
+
390
+ *args : iterable of (int, str or tuple)
391
+ A list of parameters, specified either as strings (their names), ints
392
+ (numerical indices) or tuples, which may contain ints, strings, and
393
+ (recursively) tuples. Each indicates which parameters the decorator
394
+ should map. Tuples indicate that the map function takes (and returns)
395
+ multiple parameters in the same order and nested structure as indicated
396
+ here.
397
+
398
+ try_finally : bool (default: False)
399
+ When True, wrap the function call in a try-finally block with code
400
+ for the finally block created by `func`. This is used when the map
401
+ function constructs an object (like a file handle) that requires
402
+ post-processing (like closing).
403
+
404
+ Note: try_finally decorators cannot be used to decorate generator
405
+ functions.
406
+
407
+ Examples
408
+ --------
409
+ Most of these examples use `@argmap(...)` to apply the decorator to
410
+ the function defined on the next line.
411
+ In the NetworkX codebase however, `argmap` is used within a function to
412
+ construct a decorator. That is, the decorator defines a mapping function
413
+ and then uses `argmap` to build and return a decorated function.
414
+ A simple example is a decorator that specifies which currency to report money.
415
+ The decorator (named `convert_to`) would be used like::
416
+
417
+ @convert_to("US_Dollars", "income")
418
+ def show_me_the_money(name, income):
419
+ print(f"{name} : {income}")
420
+
421
+ And the code to create the decorator might be::
422
+
423
+ def convert_to(currency, which_arg):
424
+ def _convert(amount):
425
+ if amount.currency != currency:
426
+ amount = amount.to_currency(currency)
427
+ return amount
428
+
429
+ return argmap(_convert, which_arg)
430
+
431
+ Despite this common idiom for argmap, most of the following examples
432
+ use the `@argmap(...)` idiom to save space.
433
+
434
+ Here's an example use of argmap to sum the elements of two of the functions
435
+ arguments. The decorated function::
436
+
437
+ @argmap(sum, "xlist", "zlist")
438
+ def foo(xlist, y, zlist):
439
+ return xlist - y + zlist
440
+
441
+ is syntactic sugar for::
442
+
443
+ def foo(xlist, y, zlist):
444
+ x = sum(xlist)
445
+ z = sum(zlist)
446
+ return x - y + z
447
+
448
+ and is equivalent to (using argument indexes)::
449
+
450
+ @argmap(sum, "xlist", 2)
451
+ def foo(xlist, y, zlist):
452
+ return xlist - y + zlist
453
+
454
+ or::
455
+
456
+ @argmap(sum, "zlist", 0)
457
+ def foo(xlist, y, zlist):
458
+ return xlist - y + zlist
459
+
460
+ Transforming functions can be applied to multiple arguments, such as::
461
+
462
+ def swap(x, y):
463
+ return y, x
464
+
465
+ # the 2-tuple tells argmap that the map `swap` has 2 inputs/outputs.
466
+ @argmap(swap, ("a", "b")):
467
+ def foo(a, b, c):
468
+ return a / b * c
469
+
470
+ is equivalent to::
471
+
472
+ def foo(a, b, c):
473
+ a, b = swap(a, b)
474
+ return a / b * c
475
+
476
+ More generally, the applied arguments can be nested tuples of strings or ints.
477
+ The syntax `@argmap(some_func, ("a", ("b", "c")))` would expect `some_func` to
478
+ accept 2 inputs with the second expected to be a 2-tuple. It should then return
479
+ 2 outputs with the second a 2-tuple. The returns values would replace input "a"
480
+ "b" and "c" respectively. Similarly for `@argmap(some_func, (0, ("b", 2)))`.
481
+
482
+ Also, note that an index larger than the number of named parameters is allowed
483
+ for variadic functions. For example::
484
+
485
+ def double(a):
486
+ return 2 * a
487
+
488
+
489
+ @argmap(double, 3)
490
+ def overflow(a, *args):
491
+ return a, args
492
+
493
+
494
+ print(overflow(1, 2, 3, 4, 5, 6)) # output is 1, (2, 3, 8, 5, 6)
495
+
496
+ **Try Finally**
497
+
498
+ Additionally, this `argmap` class can be used to create a decorator that
499
+ initiates a try...finally block. The decorator must be written to return
500
+ both the transformed argument and a closing function.
501
+ This feature was included to enable the `open_file` decorator which might
502
+ need to close the file or not depending on whether it had to open that file.
503
+ This feature uses the keyword-only `try_finally` argument to `@argmap`.
504
+
505
+ For example this map opens a file and then makes sure it is closed::
506
+
507
+ def open_file(fn):
508
+ f = open(fn)
509
+ return f, lambda: f.close()
510
+
511
+ The decorator applies that to the function `foo`::
512
+
513
+ @argmap(open_file, "file", try_finally=True)
514
+ def foo(file):
515
+ print(file.read())
516
+
517
+ is syntactic sugar for::
518
+
519
+ def foo(file):
520
+ file, close_file = open_file(file)
521
+ try:
522
+ print(file.read())
523
+ finally:
524
+ close_file()
525
+
526
+ and is equivalent to (using indexes)::
527
+
528
+ @argmap(open_file, 0, try_finally=True)
529
+ def foo(file):
530
+ print(file.read())
531
+
532
+ Here's an example of the try_finally feature used to create a decorator::
533
+
534
+ def my_closing_decorator(which_arg):
535
+ def _opener(path):
536
+ if path is None:
537
+ path = open(path)
538
+ fclose = path.close
539
+ else:
540
+ # assume `path` handles the closing
541
+ fclose = lambda: None
542
+ return path, fclose
543
+
544
+ return argmap(_opener, which_arg, try_finally=True)
545
+
546
+ which can then be used as::
547
+
548
+ @my_closing_decorator("file")
549
+ def fancy_reader(file=None):
550
+ # this code doesn't need to worry about closing the file
551
+ print(file.read())
552
+
553
+ Decorators with try_finally = True cannot be used with generator functions,
554
+ because the `finally` block is evaluated before the generator is exhausted::
555
+
556
+ @argmap(open_file, "file", try_finally=True)
557
+ def file_to_lines(file):
558
+ for line in file.readlines():
559
+ yield line
560
+
561
+ is equivalent to::
562
+
563
+ def file_to_lines_wrapped(file):
564
+ for line in file.readlines():
565
+ yield line
566
+
567
+
568
+ def file_to_lines_wrapper(file):
569
+ try:
570
+ file = open_file(file)
571
+ return file_to_lines_wrapped(file)
572
+ finally:
573
+ file.close()
574
+
575
+ which behaves similarly to::
576
+
577
+ def file_to_lines_whoops(file):
578
+ file = open_file(file)
579
+ file.close()
580
+ for line in file.readlines():
581
+ yield line
582
+
583
+ because the `finally` block of `file_to_lines_wrapper` is executed before
584
+ the caller has a chance to exhaust the iterator.
585
+
586
+ Notes
587
+ -----
588
+ An object of this class is callable and intended to be used when
589
+ defining a decorator. Generally, a decorator takes a function as input
590
+ and constructs a function as output. Specifically, an `argmap` object
591
+ returns the input function decorated/wrapped so that specified arguments
592
+ are mapped (transformed) to new values before the decorated function is called.
593
+
594
+ As an overview, the argmap object returns a new function with all the
595
+ dunder values of the original function (like `__doc__`, `__name__`, etc).
596
+ Code for this decorated function is built based on the original function's
597
+ signature. It starts by mapping the input arguments to potentially new
598
+ values. Then it calls the decorated function with these new values in place
599
+ of the indicated arguments that have been mapped. The return value of the
600
+ original function is then returned. This new function is the function that
601
+ is actually called by the user.
602
+
603
+ Three additional features are provided.
604
+ 1) The code is lazily compiled. That is, the new function is returned
605
+ as an object without the code compiled, but with all information
606
+ needed so it can be compiled upon it's first invocation. This saves
607
+ time on import at the cost of additional time on the first call of
608
+ the function. Subsequent calls are then just as fast as normal.
609
+
610
+ 2) If the "try_finally" keyword-only argument is True, a try block
611
+ follows each mapped argument, matched on the other side of the wrapped
612
+ call, by a finally block closing that mapping. We expect func to return
613
+ a 2-tuple: the mapped value and a function to be called in the finally
614
+ clause. This feature was included so the `open_file` decorator could
615
+ provide a file handle to the decorated function and close the file handle
616
+ after the function call. It even keeps track of whether to close the file
617
+ handle or not based on whether it had to open the file or the input was
618
+ already open. So, the decorated function does not need to include any
619
+ code to open or close files.
620
+
621
+ 3) The maps applied can process multiple arguments. For example,
622
+ you could swap two arguments using a mapping, or transform
623
+ them to their sum and their difference. This was included to allow
624
+ a decorator in the `quality.py` module that checks that an input
625
+ `partition` is a valid partition of the nodes of the input graph `G`.
626
+ In this example, the map has inputs `(G, partition)`. After checking
627
+ for a valid partition, the map either raises an exception or leaves
628
+ the inputs unchanged. Thus many functions that make this check can
629
+ use the decorator rather than copy the checking code into each function.
630
+ More complicated nested argument structures are described below.
631
+
632
+ The remaining notes describe the code structure and methods for this
633
+ class in broad terms to aid in understanding how to use it.
634
+
635
+ Instantiating an `argmap` object simply stores the mapping function and
636
+ the input identifiers of which arguments to map. The resulting decorator
637
+ is ready to use this map to decorate any function. Calling that object
638
+ (`argmap.__call__`, but usually done via `@my_decorator`) a lazily
639
+ compiled thin wrapper of the decorated function is constructed,
640
+ wrapped with the necessary function dunder attributes like `__doc__`
641
+ and `__name__`. That thinly wrapped function is returned as the
642
+ decorated function. When that decorated function is called, the thin
643
+ wrapper of code calls `argmap._lazy_compile` which compiles the decorated
644
+ function (using `argmap.compile`) and replaces the code of the thin
645
+ wrapper with the newly compiled code. This saves the compilation step
646
+ every import of networkx, at the cost of compiling upon the first call
647
+ to the decorated function.
648
+
649
+ When the decorated function is compiled, the code is recursively assembled
650
+ using the `argmap.assemble` method. The recursive nature is needed in
651
+ case of nested decorators. The result of the assembly is a number of
652
+ useful objects.
653
+
654
+ sig : the function signature of the original decorated function as
655
+ constructed by :func:`argmap.signature`. This is constructed
656
+ using `inspect.signature` but enhanced with attribute
657
+ strings `sig_def` and `sig_call`, and other information
658
+ specific to mapping arguments of this function.
659
+ This information is used to construct a string of code defining
660
+ the new decorated function.
661
+
662
+ wrapped_name : a unique internally used name constructed by argmap
663
+ for the decorated function.
664
+
665
+ functions : a dict of the functions used inside the code of this
666
+ decorated function, to be used as `globals` in `exec`.
667
+ This dict is recursively updated to allow for nested decorating.
668
+
669
+ mapblock : code (as a list of strings) to map the incoming argument
670
+ values to their mapped values.
671
+
672
+ finallys : code (as a list of strings) to provide the possibly nested
673
+ set of finally clauses if needed.
674
+
675
+ mutable_args : a bool indicating whether the `sig.args` tuple should be
676
+ converted to a list so mutation can occur.
677
+
678
+ After this recursive assembly process, the `argmap.compile` method
679
+ constructs code (as strings) to convert the tuple `sig.args` to a list
680
+ if needed. It joins the defining code with appropriate indents and
681
+ compiles the result. Finally, this code is evaluated and the original
682
+ wrapper's implementation is replaced with the compiled version (see
683
+ `argmap._lazy_compile` for more details).
684
+
685
+ Other `argmap` methods include `_name` and `_count` which allow internally
686
+ generated names to be unique within a python session.
687
+ The methods `_flatten` and `_indent` process the nested lists of strings
688
+ into properly indented python code ready to be compiled.
689
+
690
+ More complicated nested tuples of arguments also allowed though
691
+ usually not used. For the simple 2 argument case, the argmap
692
+ input ("a", "b") implies the mapping function will take 2 arguments
693
+ and return a 2-tuple of mapped values. A more complicated example
694
+ with argmap input `("a", ("b", "c"))` requires the mapping function
695
+ take 2 inputs, with the second being a 2-tuple. It then must output
696
+ the 3 mapped values in the same nested structure `(newa, (newb, newc))`.
697
+ This level of generality is not often needed, but was convenient
698
+ to implement when handling the multiple arguments.
699
+
700
+ See Also
701
+ --------
702
+ not_implemented_for
703
+ open_file
704
+ nodes_or_number
705
+ py_random_state
706
+ networkx.algorithms.community.quality.require_partition
707
+
708
+ """
709
+
710
+ def __init__(self, func, *args, try_finally=False):
711
+ self._func = func
712
+ self._args = args
713
+ self._finally = try_finally
714
+
715
+ @staticmethod
716
+ def _lazy_compile(func):
717
+ """Compile the source of a wrapped function
718
+
719
+ Assemble and compile the decorated function, and intrusively replace its
720
+ code with the compiled version's. The thinly wrapped function becomes
721
+ the decorated function.
722
+
723
+ Parameters
724
+ ----------
725
+ func : callable
726
+ A function returned by argmap.__call__ which is in the process
727
+ of being called for the first time.
728
+
729
+ Returns
730
+ -------
731
+ func : callable
732
+ The same function, with a new __code__ object.
733
+
734
+ Notes
735
+ -----
736
+ It was observed in NetworkX issue #4732 [1] that the import time of
737
+ NetworkX was significantly bloated by the use of decorators: over half
738
+ of the import time was being spent decorating functions. This was
739
+ somewhat improved by a change made to the `decorator` library, at the
740
+ cost of a relatively heavy-weight call to `inspect.Signature.bind`
741
+ for each call to the decorated function.
742
+
743
+ The workaround we arrived at is to do minimal work at the time of
744
+ decoration. When the decorated function is called for the first time,
745
+ we compile a function with the same function signature as the wrapped
746
+ function. The resulting decorated function is faster than one made by
747
+ the `decorator` library, so that the overhead of the first call is
748
+ 'paid off' after a small number of calls.
749
+
750
+ References
751
+ ----------
752
+
753
+ [1] https://github.com/networkx/networkx/issues/4732
754
+
755
+ """
756
+ real_func = func.__argmap__.compile(func.__wrapped__)
757
+ func.__code__ = real_func.__code__
758
+ func.__globals__.update(real_func.__globals__)
759
+ func.__dict__.update(real_func.__dict__)
760
+ return func
761
+
762
+ def __call__(self, f):
763
+ """Construct a lazily decorated wrapper of f.
764
+
765
+ The decorated function will be compiled when it is called for the first time,
766
+ and it will replace its own __code__ object so subsequent calls are fast.
767
+
768
+ Parameters
769
+ ----------
770
+ f : callable
771
+ A function to be decorated.
772
+
773
+ Returns
774
+ -------
775
+ func : callable
776
+ The decorated function.
777
+
778
+ See Also
779
+ --------
780
+ argmap._lazy_compile
781
+ """
782
+
783
+ def func(*args, __wrapper=None, **kwargs):
784
+ return argmap._lazy_compile(__wrapper)(*args, **kwargs)
785
+
786
+ # standard function-wrapping stuff
787
+ func.__name__ = f.__name__
788
+ func.__doc__ = f.__doc__
789
+ func.__defaults__ = f.__defaults__
790
+ func.__kwdefaults__.update(f.__kwdefaults__ or {})
791
+ func.__module__ = f.__module__
792
+ func.__qualname__ = f.__qualname__
793
+ func.__dict__.update(f.__dict__)
794
+ func.__wrapped__ = f
795
+
796
+ # now that we've wrapped f, we may have picked up some __dict__ or
797
+ # __kwdefaults__ items that were set by a previous argmap. Thus, we set
798
+ # these values after those update() calls.
799
+
800
+ # If we attempt to access func from within itself, that happens through
801
+ # a closure -- which trips an error when we replace func.__code__. The
802
+ # standard workaround for functions which can't see themselves is to use
803
+ # a Y-combinator, as we do here.
804
+ func.__kwdefaults__["_argmap__wrapper"] = func
805
+
806
+ # this self-reference is here because functools.wraps preserves
807
+ # everything in __dict__, and we don't want to mistake a non-argmap
808
+ # wrapper for an argmap wrapper
809
+ func.__self__ = func
810
+
811
+ # this is used to variously call self.assemble and self.compile
812
+ func.__argmap__ = self
813
+
814
+ if hasattr(f, "__argmap__"):
815
+ func.__is_generator = f.__is_generator
816
+ else:
817
+ func.__is_generator = inspect.isgeneratorfunction(f)
818
+
819
+ if self._finally and func.__is_generator:
820
+ raise nx.NetworkXError("argmap cannot decorate generators with try_finally")
821
+
822
+ return func
823
+
824
+ __count = 0
825
+
826
+ @classmethod
827
+ def _count(cls):
828
+ """Maintain a globally-unique identifier for function names and "file" names
829
+
830
+ Note that this counter is a class method reporting a class variable
831
+ so the count is unique within a Python session. It could differ from
832
+ session to session for a specific decorator depending on the order
833
+ that the decorators are created. But that doesn't disrupt `argmap`.
834
+
835
+ This is used in two places: to construct unique variable names
836
+ in the `_name` method and to construct unique fictitious filenames
837
+ in the `_compile` method.
838
+
839
+ Returns
840
+ -------
841
+ count : int
842
+ An integer unique to this Python session (simply counts from zero)
843
+ """
844
+ cls.__count += 1
845
+ return cls.__count
846
+
847
+ _bad_chars = re.compile("[^a-zA-Z0-9_]")
848
+
849
+ @classmethod
850
+ def _name(cls, f):
851
+ """Mangle the name of a function to be unique but somewhat human-readable
852
+
853
+ The names are unique within a Python session and set using `_count`.
854
+
855
+ Parameters
856
+ ----------
857
+ f : str or object
858
+
859
+ Returns
860
+ -------
861
+ name : str
862
+ The mangled version of `f.__name__` (if `f.__name__` exists) or `f`
863
+
864
+ """
865
+ f = f.__name__ if hasattr(f, "__name__") else f
866
+ fname = re.sub(cls._bad_chars, "_", f)
867
+ return f"argmap_{fname}_{cls._count()}"
868
+
869
+ def compile(self, f):
870
+ """Compile the decorated function.
871
+
872
+ Called once for a given decorated function -- collects the code from all
873
+ argmap decorators in the stack, and compiles the decorated function.
874
+
875
+ Much of the work done here uses the `assemble` method to allow recursive
876
+ treatment of multiple argmap decorators on a single decorated function.
877
+ That flattens the argmap decorators, collects the source code to construct
878
+ a single decorated function, then compiles/executes/returns that function.
879
+
880
+ The source code for the decorated function is stored as an attribute
881
+ `_code` on the function object itself.
882
+
883
+ Note that Python's `compile` function requires a filename, but this
884
+ code is constructed without a file, so a fictitious filename is used
885
+ to describe where the function comes from. The name is something like:
886
+ "argmap compilation 4".
887
+
888
+ Parameters
889
+ ----------
890
+ f : callable
891
+ The function to be decorated
892
+
893
+ Returns
894
+ -------
895
+ func : callable
896
+ The decorated file
897
+
898
+ """
899
+ sig, wrapped_name, functions, mapblock, finallys, mutable_args = self.assemble(
900
+ f
901
+ )
902
+
903
+ call = f"{sig.call_sig.format(wrapped_name)}#"
904
+ mut_args = f"{sig.args} = list({sig.args})" if mutable_args else ""
905
+ body = argmap._indent(sig.def_sig, mut_args, mapblock, call, finallys)
906
+ code = "\n".join(body)
907
+
908
+ locl = {}
909
+ globl = dict(functions.values())
910
+ filename = f"{self.__class__} compilation {self._count()}"
911
+ compiled = compile(code, filename, "exec")
912
+ exec(compiled, globl, locl)
913
+ func = locl[sig.name]
914
+ func._code = code
915
+ return func
916
+
917
+ def assemble(self, f):
918
+ """Collects components of the source for the decorated function wrapping f.
919
+
920
+ If `f` has multiple argmap decorators, we recursively assemble the stack of
921
+ decorators into a single flattened function.
922
+
923
+ This method is part of the `compile` method's process yet separated
924
+ from that method to allow recursive processing. The outputs are
925
+ strings, dictionaries and lists that collect needed info to
926
+ flatten any nested argmap-decoration.
927
+
928
+ Parameters
929
+ ----------
930
+ f : callable
931
+ The function to be decorated. If f is argmapped, we assemble it.
932
+
933
+ Returns
934
+ -------
935
+ sig : argmap.Signature
936
+ The function signature as an `argmap.Signature` object.
937
+ wrapped_name : str
938
+ The mangled name used to represent the wrapped function in the code
939
+ being assembled.
940
+ functions : dict
941
+ A dictionary mapping id(g) -> (mangled_name(g), g) for functions g
942
+ referred to in the code being assembled. These need to be present
943
+ in the ``globals`` scope of ``exec`` when defining the decorated
944
+ function.
945
+ mapblock : list of lists and/or strings
946
+ Code that implements mapping of parameters including any try blocks
947
+ if needed. This code will precede the decorated function call.
948
+ finallys : list of lists and/or strings
949
+ Code that implements the finally blocks to post-process the
950
+ arguments (usually close any files if needed) after the
951
+ decorated function is called.
952
+ mutable_args : bool
953
+ True if the decorator needs to modify positional arguments
954
+ via their indices. The compile method then turns the argument
955
+ tuple into a list so that the arguments can be modified.
956
+ """
957
+
958
+ # first, we check if f is already argmapped -- if that's the case,
959
+ # build up the function recursively.
960
+ # > mapblock is generally a list of function calls of the sort
961
+ # arg = func(arg)
962
+ # in addition to some try-blocks if needed.
963
+ # > finallys is a recursive list of finally blocks of the sort
964
+ # finally:
965
+ # close_func_1()
966
+ # finally:
967
+ # close_func_2()
968
+ # > functions is a dict of functions used in the scope of our decorated
969
+ # function. It will be used to construct globals used in compilation.
970
+ # We make functions[id(f)] = name_of_f, f to ensure that a given
971
+ # function is stored and named exactly once even if called by
972
+ # nested decorators.
973
+ if hasattr(f, "__argmap__") and f.__self__ is f:
974
+ (
975
+ sig,
976
+ wrapped_name,
977
+ functions,
978
+ mapblock,
979
+ finallys,
980
+ mutable_args,
981
+ ) = f.__argmap__.assemble(f.__wrapped__)
982
+ functions = dict(functions) # shallow-copy just in case
983
+ else:
984
+ sig = self.signature(f)
985
+ wrapped_name = self._name(f)
986
+ mapblock, finallys = [], []
987
+ functions = {id(f): (wrapped_name, f)}
988
+ mutable_args = False
989
+
990
+ if id(self._func) in functions:
991
+ fname, _ = functions[id(self._func)]
992
+ else:
993
+ fname, _ = functions[id(self._func)] = self._name(self._func), self._func
994
+
995
+ # this is a bit complicated -- we can call functions with a variety of
996
+ # nested arguments, so long as their input and output are tuples with
997
+ # the same nested structure. e.g. ("a", "b") maps arguments a and b.
998
+ # A more complicated nesting like (0, (3, 4)) maps arguments 0, 3, 4
999
+ # expecting the mapping to output new values in the same nested shape.
1000
+ # The ability to argmap multiple arguments was necessary for
1001
+ # the decorator `nx.algorithms.community.quality.require_partition`, and
1002
+ # while we're not taking full advantage of the ability to handle
1003
+ # multiply-nested tuples, it was convenient to implement this in
1004
+ # generality because the recursive call to `get_name` is necessary in
1005
+ # any case.
1006
+ applied = set()
1007
+
1008
+ def get_name(arg, first=True):
1009
+ nonlocal mutable_args
1010
+ if isinstance(arg, tuple):
1011
+ name = ", ".join(get_name(x, False) for x in arg)
1012
+ return name if first else f"({name})"
1013
+ if arg in applied:
1014
+ raise nx.NetworkXError(f"argument {arg} is specified multiple times")
1015
+ applied.add(arg)
1016
+ if arg in sig.names:
1017
+ return sig.names[arg]
1018
+ elif isinstance(arg, str):
1019
+ if sig.kwargs is None:
1020
+ raise nx.NetworkXError(
1021
+ f"name {arg} is not a named parameter and this function doesn't have kwargs"
1022
+ )
1023
+ return f"{sig.kwargs}[{arg!r}]"
1024
+ else:
1025
+ if sig.args is None:
1026
+ raise nx.NetworkXError(
1027
+ f"index {arg} not a parameter index and this function doesn't have args"
1028
+ )
1029
+ mutable_args = True
1030
+ return f"{sig.args}[{arg - sig.n_positional}]"
1031
+
1032
+ if self._finally:
1033
+ # here's where we handle try_finally decorators. Such a decorator
1034
+ # returns a mapped argument and a function to be called in a
1035
+ # finally block. This feature was required by the open_file
1036
+ # decorator. The below generates the code
1037
+ #
1038
+ # name, final = func(name) #<--append to mapblock
1039
+ # try: #<--append to mapblock
1040
+ # ... more argmapping and try blocks
1041
+ # return WRAPPED_FUNCTION(...)
1042
+ # ... more finally blocks
1043
+ # finally: #<--prepend to finallys
1044
+ # final() #<--prepend to finallys
1045
+ #
1046
+ for a in self._args:
1047
+ name = get_name(a)
1048
+ final = self._name(name)
1049
+ mapblock.append(f"{name}, {final} = {fname}({name})")
1050
+ mapblock.append("try:")
1051
+ finallys = ["finally:", f"{final}()#", "#", finallys]
1052
+ else:
1053
+ mapblock.extend(
1054
+ f"{name} = {fname}({name})" for name in map(get_name, self._args)
1055
+ )
1056
+
1057
+ return sig, wrapped_name, functions, mapblock, finallys, mutable_args
1058
+
1059
+ @classmethod
1060
+ def signature(cls, f):
1061
+ r"""Construct a Signature object describing `f`
1062
+
1063
+ Compute a Signature so that we can write a function wrapping f with
1064
+ the same signature and call-type.
1065
+
1066
+ Parameters
1067
+ ----------
1068
+ f : callable
1069
+ A function to be decorated
1070
+
1071
+ Returns
1072
+ -------
1073
+ sig : argmap.Signature
1074
+ The Signature of f
1075
+
1076
+ Notes
1077
+ -----
1078
+ The Signature is a namedtuple with names:
1079
+
1080
+ name : a unique version of the name of the decorated function
1081
+ signature : the inspect.signature of the decorated function
1082
+ def_sig : a string used as code to define the new function
1083
+ call_sig : a string used as code to call the decorated function
1084
+ names : a dict keyed by argument name and index to the argument's name
1085
+ n_positional : the number of positional arguments in the signature
1086
+ args : the name of the VAR_POSITIONAL argument if any, i.e. \*theseargs
1087
+ kwargs : the name of the VAR_KEYWORDS argument if any, i.e. \*\*kwargs
1088
+
1089
+ These named attributes of the signature are used in `assemble` and `compile`
1090
+ to construct a string of source code for the decorated function.
1091
+
1092
+ """
1093
+ sig = inspect.signature(f, follow_wrapped=False)
1094
+ def_sig = []
1095
+ call_sig = []
1096
+ names = {}
1097
+
1098
+ kind = None
1099
+ args = None
1100
+ kwargs = None
1101
+ npos = 0
1102
+ for i, param in enumerate(sig.parameters.values()):
1103
+ # parameters can be position-only, keyword-or-position, keyword-only
1104
+ # in any combination, but only in the order as above. we do edge
1105
+ # detection to add the appropriate punctuation
1106
+ prev = kind
1107
+ kind = param.kind
1108
+ if prev == param.POSITIONAL_ONLY != kind:
1109
+ # the last token was position-only, but this one isn't
1110
+ def_sig.append("/")
1111
+ if (
1112
+ param.VAR_POSITIONAL
1113
+ != prev
1114
+ != param.KEYWORD_ONLY
1115
+ == kind
1116
+ != param.VAR_POSITIONAL
1117
+ ):
1118
+ # param is the first keyword-only arg and isn't starred
1119
+ def_sig.append("*")
1120
+
1121
+ # star arguments as appropriate
1122
+ if kind == param.VAR_POSITIONAL:
1123
+ name = "*" + param.name
1124
+ args = param.name
1125
+ count = 0
1126
+ elif kind == param.VAR_KEYWORD:
1127
+ name = "**" + param.name
1128
+ kwargs = param.name
1129
+ count = 0
1130
+ else:
1131
+ names[i] = names[param.name] = param.name
1132
+ name = param.name
1133
+ count = 1
1134
+
1135
+ # assign to keyword-only args in the function call
1136
+ if kind == param.KEYWORD_ONLY:
1137
+ call_sig.append(f"{name} = {name}")
1138
+ else:
1139
+ npos += count
1140
+ call_sig.append(name)
1141
+
1142
+ def_sig.append(name)
1143
+
1144
+ fname = cls._name(f)
1145
+ def_sig = f"def {fname}({', '.join(def_sig)}):"
1146
+
1147
+ call_sig = f"return {{}}({', '.join(call_sig)})"
1148
+
1149
+ return cls.Signature(fname, sig, def_sig, call_sig, names, npos, args, kwargs)
1150
+
1151
+ Signature = collections.namedtuple(
1152
+ "Signature",
1153
+ [
1154
+ "name",
1155
+ "signature",
1156
+ "def_sig",
1157
+ "call_sig",
1158
+ "names",
1159
+ "n_positional",
1160
+ "args",
1161
+ "kwargs",
1162
+ ],
1163
+ )
1164
+
1165
+ @staticmethod
1166
+ def _flatten(nestlist, visited):
1167
+ """flattens a recursive list of lists that doesn't have cyclic references
1168
+
1169
+ Parameters
1170
+ ----------
1171
+ nestlist : iterable
1172
+ A recursive list of objects to be flattened into a single iterable
1173
+
1174
+ visited : set
1175
+ A set of object ids which have been walked -- initialize with an
1176
+ empty set
1177
+
1178
+ Yields
1179
+ ------
1180
+ Non-list objects contained in nestlist
1181
+
1182
+ """
1183
+ for thing in nestlist:
1184
+ if isinstance(thing, list):
1185
+ if id(thing) in visited:
1186
+ raise ValueError("A cycle was found in nestlist. Be a tree.")
1187
+ else:
1188
+ visited.add(id(thing))
1189
+ yield from argmap._flatten(thing, visited)
1190
+ else:
1191
+ yield thing
1192
+
1193
+ _tabs = " " * 64
1194
+
1195
+ @staticmethod
1196
+ def _indent(*lines):
1197
+ """Indent list of code lines to make executable Python code
1198
+
1199
+ Indents a tree-recursive list of strings, following the rule that one
1200
+ space is added to the tab after a line that ends in a colon, and one is
1201
+ removed after a line that ends in an hashmark.
1202
+
1203
+ Parameters
1204
+ ----------
1205
+ *lines : lists and/or strings
1206
+ A recursive list of strings to be assembled into properly indented
1207
+ code.
1208
+
1209
+ Returns
1210
+ -------
1211
+ code : str
1212
+
1213
+ Examples
1214
+ --------
1215
+
1216
+ argmap._indent(*["try:", "try:", "pass#", "finally:", "pass#", "#",
1217
+ "finally:", "pass#"])
1218
+
1219
+ renders to
1220
+
1221
+ '''try:
1222
+ try:
1223
+ pass#
1224
+ finally:
1225
+ pass#
1226
+ #
1227
+ finally:
1228
+ pass#'''
1229
+ """
1230
+ depth = 0
1231
+ for line in argmap._flatten(lines, set()):
1232
+ yield f"{argmap._tabs[:depth]}{line}"
1233
+ depth += (line[-1:] == ":") - (line[-1:] == "#")