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.
- package/package.json +1 -1
- package/runtime/BUILD.json +2 -2
- package/runtime/prompts/profiles/_common-contract.md +1 -1
- package/runtime/python/okstra_ctl/graphify_cmd.py +225 -0
- package/runtime/python/okstra_ctl/resolve_task_key.py +15 -9
- package/runtime/python/okstra_project/__init__.py +2 -0
- package/runtime/python/okstra_project/state.py +36 -0
- package/runtime/python/okstra_vendor/__init__.py +41 -0
- package/runtime/python/okstra_vendor/graphify/.vendored-version +1 -0
- package/runtime/python/okstra_vendor/graphify/__init__.py +28 -0
- package/runtime/python/okstra_vendor/graphify/__main__.py +1371 -0
- package/runtime/python/okstra_vendor/graphify/analyze.py +540 -0
- package/runtime/python/okstra_vendor/graphify/benchmark.py +129 -0
- package/runtime/python/okstra_vendor/graphify/build.py +107 -0
- package/runtime/python/okstra_vendor/graphify/cache.py +169 -0
- package/runtime/python/okstra_vendor/graphify/cluster.py +137 -0
- package/runtime/python/okstra_vendor/graphify/detect.py +510 -0
- package/runtime/python/okstra_vendor/graphify/export.py +1014 -0
- package/runtime/python/okstra_vendor/graphify/extract.py +3277 -0
- package/runtime/python/okstra_vendor/graphify/hooks.py +220 -0
- package/runtime/python/okstra_vendor/graphify/ingest.py +297 -0
- package/runtime/python/okstra_vendor/graphify/manifest.py +4 -0
- package/runtime/python/okstra_vendor/graphify/report.py +175 -0
- package/runtime/python/okstra_vendor/graphify/security.py +203 -0
- package/runtime/python/okstra_vendor/graphify/serve.py +373 -0
- package/runtime/python/okstra_vendor/graphify/skill-aider.md +1184 -0
- package/runtime/python/okstra_vendor/graphify/skill-claw.md +1184 -0
- package/runtime/python/okstra_vendor/graphify/skill-codex.md +1242 -0
- package/runtime/python/okstra_vendor/graphify/skill-copilot.md +1268 -0
- package/runtime/python/okstra_vendor/graphify/skill-droid.md +1239 -0
- package/runtime/python/okstra_vendor/graphify/skill-kiro.md +1183 -0
- package/runtime/python/okstra_vendor/graphify/skill-opencode.md +1238 -0
- package/runtime/python/okstra_vendor/graphify/skill-trae.md +1208 -0
- package/runtime/python/okstra_vendor/graphify/skill-vscode.md +253 -0
- package/runtime/python/okstra_vendor/graphify/skill-windows.md +1245 -0
- package/runtime/python/okstra_vendor/graphify/skill.md +1319 -0
- package/runtime/python/okstra_vendor/graphify/transcribe.py +182 -0
- package/runtime/python/okstra_vendor/graphify/validate.py +72 -0
- package/runtime/python/okstra_vendor/graphify/watch.py +188 -0
- package/runtime/python/okstra_vendor/graphify/wiki.py +214 -0
- package/runtime/python/okstra_vendor/networkx/__init__.py +62 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/__init__.py +134 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/__init__.py +26 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clique.py +259 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clustering_coefficient.py +71 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/connectivity.py +412 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/density.py +396 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/distance_measures.py +150 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/dominating_set.py +149 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/kcomponents.py +369 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/matching.py +44 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/maxcut.py +143 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/ramsey.py +53 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/steinertree.py +265 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py +41 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_clique.py +112 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_connectivity.py +199 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_density.py +146 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_distance_measures.py +59 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_dominating_set.py +78 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_kcomponents.py +303 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_matching.py +8 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_maxcut.py +94 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_ramsey.py +31 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_steinertree.py +306 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_traveling_salesman.py +1014 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_treewidth.py +274 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_vertex_cover.py +68 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/traveling_salesman.py +1508 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/treewidth.py +255 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/vertex_cover.py +83 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/__init__.py +5 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/connectivity.py +122 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/correlation.py +302 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/mixing.py +255 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/neighbor_degree.py +160 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/pairs.py +127 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/base_test.py +81 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_connectivity.py +143 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_correlation.py +122 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_mixing.py +174 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_neighbor_degree.py +107 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_pairs.py +87 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/asteroidal.py +164 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/__init__.py +88 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/basic.py +322 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/centrality.py +290 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/cluster.py +289 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/covering.py +57 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/edgelist.py +360 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/extendability.py +105 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/generators.py +603 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/link_analysis.py +316 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matching.py +590 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matrix.py +232 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/projection.py +526 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/redundancy.py +112 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/spectral.py +69 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_basic.py +125 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_centrality.py +192 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_cluster.py +84 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_covering.py +33 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_edgelist.py +240 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_extendability.py +334 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_generators.py +407 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_link_analysis.py +218 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matching.py +327 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matrix.py +138 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_project.py +409 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_redundancy.py +35 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py +80 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/boundary.py +168 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bridges.py +205 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/broadcasting.py +164 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/__init__.py +20 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness.py +591 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness_subset.py +236 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/closeness.py +282 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness.py +364 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness_subset.py +227 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_closeness.py +96 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/degree_alg.py +150 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/dispersion.py +107 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/eigenvector.py +357 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/flow_matrix.py +130 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/group.py +787 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/harmonic.py +88 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/katz.py +331 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/laplacian.py +150 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/load.py +200 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/percolation.py +128 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/reaching.py +209 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/second_order.py +141 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/subgraph_alg.py +361 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality.py +923 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality_subset.py +354 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_closeness_centrality.py +274 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py +259 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality_subset.py +147 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_closeness.py +43 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_degree_centrality.py +144 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_dispersion.py +73 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py +186 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_group.py +277 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_harmonic_centrality.py +122 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_katz_centrality.py +345 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_laplacian_centrality.py +220 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_load_centrality.py +344 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_percolation_centrality.py +87 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_reaching.py +140 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_second_order_centrality.py +82 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_subgraph.py +110 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_trophic.py +302 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_voterank.py +64 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/trophic.py +181 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/voterank_alg.py +95 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/chains.py +172 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/chordal.py +443 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/clique.py +818 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/cluster.py +732 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/coloring/__init__.py +4 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/coloring/equitable_coloring.py +505 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/coloring/greedy_coloring.py +565 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/test_coloring.py +863 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/communicability_alg.py +163 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/__init__.py +28 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/asyn_fluid.py +153 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/bipartitions.py +354 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/centrality.py +171 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/community_utils.py +30 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/divisive.py +216 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/kclique.py +79 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/label_propagation.py +338 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/leiden.py +162 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/local.py +220 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/louvain.py +384 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/lukes.py +227 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/modularity_max.py +452 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/quality.py +347 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_asyn_fluid.py +147 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_bipartitions.py +157 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_centrality.py +85 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_divisive.py +106 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_kclique.py +91 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_label_propagation.py +241 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_leiden.py +138 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_local.py +76 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_louvain.py +264 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_lukes.py +152 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_modularity_max.py +340 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_quality.py +139 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_utils.py +26 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/__init__.py +6 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/attracting.py +115 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/biconnected.py +394 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/connected.py +282 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/semiconnected.py +71 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/strongly_connected.py +359 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_attracting.py +70 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_biconnected.py +248 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_connected.py +138 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_semiconnected.py +55 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_strongly_connected.py +193 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_weakly_connected.py +96 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/weakly_connected.py +196 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/__init__.py +11 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/connectivity.py +811 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/cuts.py +616 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/disjoint_paths.py +408 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_augmentation.py +1270 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_kcomponents.py +592 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcomponents.py +220 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcutsets.py +235 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/stoerwagner.py +152 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_connectivity.py +421 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_cuts.py +309 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_disjoint_paths.py +249 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_augmentation.py +502 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py +488 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcomponents.py +323 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcutsets.py +280 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_stoer_wagner.py +102 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/utils.py +88 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/core.py +588 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/covering.py +142 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/cuts.py +416 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/cycles.py +1234 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/d_separation.py +677 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/dag.py +1392 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/distance_measures.py +1095 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/distance_regular.py +272 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/dominance.py +142 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/dominating.py +268 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/efficiency_measures.py +167 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/euler.py +470 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/__init__.py +11 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/boykovkolmogorov.py +370 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/capacityscaling.py +407 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/dinitz_alg.py +238 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/edmondskarp.py +241 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/gomory_hu.py +178 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/maxflow.py +611 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/mincost.py +356 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/networksimplex.py +662 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/preflowpush.py +425 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/shortestaugmentingpath.py +300 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gl1.gpickle.bz2 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gw1.gpickle.bz2 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/netgen-2.gpickle.bz2 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_gomory_hu.py +128 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow.py +573 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow_large_graph.py +155 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_mincost.py +475 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_networksimplex.py +481 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/wlm3.gpickle.bz2 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/utils.py +194 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/graph_hashing.py +435 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/graphical.py +483 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/hierarchy.py +57 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/hybrid.py +196 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isolate.py +107 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/__init__.py +7 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/ismags.py +1306 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorph.py +336 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorphvf2.py +1262 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/matchhelpers.py +352 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/temporalisomorphvf2.py +308 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.A99 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.B99 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.A99 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.B99 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_ismags.py +719 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphism.py +103 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py +490 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_match_helpers.py +64 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py +212 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py +202 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp.py +1655 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp_helpers.py +3118 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py +196 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tree_isomorphism.py +264 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2pp.py +1102 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2userfunc.py +192 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/__init__.py +2 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/hits_alg.py +337 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/pagerank_alg.py +498 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_hits.py +77 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_pagerank.py +213 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/link_prediction.py +687 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/lowest_common_ancestors.py +280 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/matching.py +1148 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/minors/__init__.py +27 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/minors/contraction.py +738 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/minors/tests/test_contraction.py +544 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/mis.py +78 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/moral.py +59 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/node_classification.py +219 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/non_randomness.py +155 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/__init__.py +4 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/all.py +324 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/binary.py +468 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/product.py +633 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_all.py +328 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_binary.py +451 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_product.py +491 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_unary.py +55 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/unary.py +77 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/perfect_graph.py +73 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/planar_drawing.py +464 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/planarity.py +1463 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/polynomials.py +306 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/reciprocity.py +98 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/regular.py +167 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/richclub.py +138 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/__init__.py +5 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/astar.py +239 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/dense.py +264 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/generic.py +716 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_astar.py +254 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense.py +212 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py +88 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_generic.py +511 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_unweighted.py +149 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_weighted.py +983 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/unweighted.py +625 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/weighted.py +2542 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/similarity.py +2107 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/simple_paths.py +966 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/smallworld.py +404 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/smetric.py +30 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/sparsifiers.py +296 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/structuralholes.py +374 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/summarization.py +564 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/swap.py +406 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_asteroidal.py +23 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_boundary.py +154 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_bridges.py +144 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_broadcasting.py +109 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chains.py +136 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chordal.py +129 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_clique.py +300 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cluster.py +678 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_communicability.py +80 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_core.py +266 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_covering.py +85 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cuts.py +171 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cycles.py +984 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_d_separation.py +340 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dag.py +835 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_measures.py +831 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_regular.py +85 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominance.py +299 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominating.py +115 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_efficiency.py +58 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_euler.py +314 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graph_hashing.py +872 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graphical.py +163 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hierarchy.py +46 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hybrid.py +24 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_isolate.py +26 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_link_prediction.py +615 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_lowest_common_ancestors.py +459 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_matching.py +556 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_max_weight_clique.py +179 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_mis.py +62 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_moral.py +15 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_node_classification.py +140 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_non_randomness.py +60 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_perfect_graph.py +27 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planar_drawing.py +274 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planarity.py +556 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_polynomials.py +57 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_reciprocity.py +37 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_regular.py +88 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_richclub.py +149 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_similarity.py +1158 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_simple_paths.py +803 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smallworld.py +76 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smetric.py +8 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_sparsifiers.py +138 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_structuralholes.py +191 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_summarization.py +642 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_swap.py +179 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_threshold.py +270 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_time_dependent.py +431 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_tournament.py +161 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_triads.py +248 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_vitality.py +41 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_voronoi.py +103 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_walks.py +54 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_wiener.py +157 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/threshold.py +981 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/time_dependent.py +142 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tournament.py +406 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/__init__.py +5 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/beamsearch.py +90 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/breadth_first_search.py +576 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/depth_first_search.py +529 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgebfs.py +185 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgedfs.py +182 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_beamsearch.py +25 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_bfs.py +203 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_dfs.py +307 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgebfs.py +147 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgedfs.py +131 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/__init__.py +7 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/branchings.py +1042 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/coding.py +413 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/decomposition.py +88 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/distance_measures.py +219 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/mst.py +1281 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/operations.py +106 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/recognition.py +273 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_branchings.py +624 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_coding.py +114 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_decomposition.py +79 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_distance_measures.py +99 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_mst.py +934 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_operations.py +53 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_recognition.py +174 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/triads.py +500 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/vitality.py +76 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/voronoi.py +86 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/walks.py +77 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/wiener.py +278 -0
- package/runtime/python/okstra_vendor/networkx/classes/__init__.py +13 -0
- package/runtime/python/okstra_vendor/networkx/classes/coreviews.py +435 -0
- package/runtime/python/okstra_vendor/networkx/classes/digraph.py +1363 -0
- package/runtime/python/okstra_vendor/networkx/classes/filters.py +95 -0
- package/runtime/python/okstra_vendor/networkx/classes/function.py +1549 -0
- package/runtime/python/okstra_vendor/networkx/classes/graph.py +2082 -0
- package/runtime/python/okstra_vendor/networkx/classes/graphviews.py +269 -0
- package/runtime/python/okstra_vendor/networkx/classes/multidigraph.py +977 -0
- package/runtime/python/okstra_vendor/networkx/classes/multigraph.py +1294 -0
- package/runtime/python/okstra_vendor/networkx/classes/reportviews.py +1447 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/dispatch_interface.py +192 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/historical_tests.py +476 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_coreviews.py +362 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph.py +331 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph_historical.py +110 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_filters.py +177 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_function.py +1045 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph.py +950 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph_historical.py +12 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_graphviews.py +349 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_multidigraph.py +459 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_multigraph.py +528 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_reportviews.py +1421 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_special.py +131 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_subgraphviews.py +371 -0
- package/runtime/python/okstra_vendor/networkx/conftest.py +261 -0
- package/runtime/python/okstra_vendor/networkx/convert.py +502 -0
- package/runtime/python/okstra_vendor/networkx/convert_matrix.py +1314 -0
- package/runtime/python/okstra_vendor/networkx/drawing/__init__.py +7 -0
- package/runtime/python/okstra_vendor/networkx/drawing/layout.py +2036 -0
- package/runtime/python/okstra_vendor/networkx/drawing/nx_agraph.py +470 -0
- package/runtime/python/okstra_vendor/networkx/drawing/nx_latex.py +570 -0
- package/runtime/python/okstra_vendor/networkx/drawing/nx_pydot.py +361 -0
- package/runtime/python/okstra_vendor/networkx/drawing/nx_pylab.py +2978 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_complex.png +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_empty_graph.png +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_house_with_colors.png +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_labels_and_colors.png +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_shortest_path.png +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_house_with_colors.png +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_agraph.py +237 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_image_comparison_pylab_mpl.py +229 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_latex.py +285 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_layout.py +631 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pydot.py +146 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pylab.py +1582 -0
- package/runtime/python/okstra_vendor/networkx/exception.py +131 -0
- package/runtime/python/okstra_vendor/networkx/generators/__init__.py +34 -0
- package/runtime/python/okstra_vendor/networkx/generators/atlas.dat.gz +0 -0
- package/runtime/python/okstra_vendor/networkx/generators/atlas.py +227 -0
- package/runtime/python/okstra_vendor/networkx/generators/classic.py +1091 -0
- package/runtime/python/okstra_vendor/networkx/generators/cographs.py +68 -0
- package/runtime/python/okstra_vendor/networkx/generators/community.py +1070 -0
- package/runtime/python/okstra_vendor/networkx/generators/degree_seq.py +886 -0
- package/runtime/python/okstra_vendor/networkx/generators/directed.py +572 -0
- package/runtime/python/okstra_vendor/networkx/generators/duplication.py +174 -0
- package/runtime/python/okstra_vendor/networkx/generators/ego.py +66 -0
- package/runtime/python/okstra_vendor/networkx/generators/expanders.py +499 -0
- package/runtime/python/okstra_vendor/networkx/generators/geometric.py +1037 -0
- package/runtime/python/okstra_vendor/networkx/generators/harary_graph.py +163 -0
- package/runtime/python/okstra_vendor/networkx/generators/internet_as_graphs.py +443 -0
- package/runtime/python/okstra_vendor/networkx/generators/intersection.py +125 -0
- package/runtime/python/okstra_vendor/networkx/generators/interval_graph.py +70 -0
- package/runtime/python/okstra_vendor/networkx/generators/joint_degree_seq.py +664 -0
- package/runtime/python/okstra_vendor/networkx/generators/lattice.py +405 -0
- package/runtime/python/okstra_vendor/networkx/generators/line.py +501 -0
- package/runtime/python/okstra_vendor/networkx/generators/mycielski.py +110 -0
- package/runtime/python/okstra_vendor/networkx/generators/nonisomorphic_trees.py +259 -0
- package/runtime/python/okstra_vendor/networkx/generators/random_clustered.py +117 -0
- package/runtime/python/okstra_vendor/networkx/generators/random_graphs.py +1416 -0
- package/runtime/python/okstra_vendor/networkx/generators/small.py +1070 -0
- package/runtime/python/okstra_vendor/networkx/generators/social.py +554 -0
- package/runtime/python/okstra_vendor/networkx/generators/spectral_graph_forge.py +120 -0
- package/runtime/python/okstra_vendor/networkx/generators/stochastic.py +54 -0
- package/runtime/python/okstra_vendor/networkx/generators/sudoku.py +131 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_atlas.py +75 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_classic.py +642 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_cographs.py +20 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_community.py +362 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_degree_seq.py +224 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_directed.py +189 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_duplication.py +103 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_ego.py +39 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_expanders.py +182 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_geometric.py +488 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_harary_graph.py +133 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_internet_as_graphs.py +221 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_intersection.py +28 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_interval_graph.py +144 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_joint_degree_seq.py +125 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_lattice.py +264 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_line.py +316 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_mycielski.py +30 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_nonisomorphic_trees.py +82 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_clustered.py +33 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_graphs.py +495 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_small.py +220 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_spectral_graph_forge.py +49 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_stochastic.py +72 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_sudoku.py +92 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_time_series.py +64 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_trees.py +195 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_triads.py +15 -0
- package/runtime/python/okstra_vendor/networkx/generators/time_series.py +74 -0
- package/runtime/python/okstra_vendor/networkx/generators/trees.py +1070 -0
- package/runtime/python/okstra_vendor/networkx/generators/triads.py +94 -0
- package/runtime/python/okstra_vendor/networkx/lazy_imports.py +188 -0
- package/runtime/python/okstra_vendor/networkx/linalg/__init__.py +13 -0
- package/runtime/python/okstra_vendor/networkx/linalg/algebraicconnectivity.py +650 -0
- package/runtime/python/okstra_vendor/networkx/linalg/attrmatrix.py +466 -0
- package/runtime/python/okstra_vendor/networkx/linalg/bethehessianmatrix.py +77 -0
- package/runtime/python/okstra_vendor/networkx/linalg/graphmatrix.py +168 -0
- package/runtime/python/okstra_vendor/networkx/linalg/laplacianmatrix.py +512 -0
- package/runtime/python/okstra_vendor/networkx/linalg/modularitymatrix.py +166 -0
- package/runtime/python/okstra_vendor/networkx/linalg/spectrum.py +186 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_algebraic_connectivity.py +400 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_attrmatrix.py +108 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_bethehessian.py +40 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_graphmatrix.py +275 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_laplacian.py +334 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_modularity.py +86 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_spectrum.py +70 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/__init__.py +17 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/adjlist.py +330 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/edgelist.py +489 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/gexf.py +1084 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/gml.py +879 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/graph6.py +427 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/graphml.py +1053 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/__init__.py +19 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/adjacency.py +156 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/cytoscape.py +190 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/node_link.py +261 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_adjacency.py +78 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_cytoscape.py +78 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_node_link.py +109 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_tree.py +48 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tree.py +137 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/leda.py +108 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/multiline_adjlist.py +393 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/p2g.py +113 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/pajek.py +286 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/sparse6.py +379 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_adjlist.py +354 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_edgelist.py +318 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gexf.py +612 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gml.py +744 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graph6.py +181 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graphml.py +1531 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_leda.py +30 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_p2g.py +63 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_pajek.py +128 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_sparse6.py +166 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_text.py +1742 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/text.py +851 -0
- package/runtime/python/okstra_vendor/networkx/relabel.py +285 -0
- package/runtime/python/okstra_vendor/networkx/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_all_random_functions.py +248 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_convert.py +321 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_convert_numpy.py +531 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_convert_pandas.py +349 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_convert_scipy.py +281 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_exceptions.py +40 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_import.py +11 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_lazy_imports.py +96 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_relabel.py +349 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_removed_functions_exception_messages.py +8 -0
- package/runtime/python/okstra_vendor/networkx/utils/__init__.py +8 -0
- package/runtime/python/okstra_vendor/networkx/utils/backends.py +2171 -0
- package/runtime/python/okstra_vendor/networkx/utils/configs.py +396 -0
- package/runtime/python/okstra_vendor/networkx/utils/decorators.py +1233 -0
- package/runtime/python/okstra_vendor/networkx/utils/heaps.py +338 -0
- package/runtime/python/okstra_vendor/networkx/utils/mapped_queue.py +297 -0
- package/runtime/python/okstra_vendor/networkx/utils/misc.py +703 -0
- package/runtime/python/okstra_vendor/networkx/utils/random_sequence.py +198 -0
- package/runtime/python/okstra_vendor/networkx/utils/rcm.py +159 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test__init.py +11 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_backends.py +225 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_config.py +263 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_decorators.py +510 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_heaps.py +131 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_mapped_queue.py +268 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_misc.py +393 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_random_sequence.py +53 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_rcm.py +63 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_unionfind.py +55 -0
- package/runtime/python/okstra_vendor/networkx/utils/union_find.py +106 -0
- package/runtime/skills/okstra-graphify/SKILL.md +161 -0
- package/runtime/skills/okstra-inspect/SKILL.md +17 -9
- package/runtime/templates/reports/settings.template.json +4 -0
- package/src/cli-registry.mjs +7 -0
- package/src/commands/graphify.mjs +32 -0
- package/src/commands/lifecycle/doctor.mjs +9 -0
- 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:] == "#")
|