investigate source based propagation
"metadata": {},
"outputs": [],
"source": [
- "import ast\n",
- "import pathlib"
+ "import networkx"
]
},
{
"metadata": {},
"outputs": [],
"source": [
- "module_dependencies"
+ "def is_stable_public_api(module_name):\n",
+ " not_stable_api_keys = ['._', 'beta', 'tests', 'docs', 'cli', 'experimental']\n",
+ " for key in not_stable_api_keys:\n",
+ " if key in module_name:\n",
+ " return False\n",
+ "\n",
+ " return True"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "public_modules = [\n",
+ " key for key in module_dependencies.keys()\n",
+ " if is_stable_public_api(key)\n",
+ "]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# TODO:\n",
+ "\n",
+ "# Get each publicly exposed API function/class.\n",
+ "# Draw a dependency tree for those publicly exposed APIs.\n",
+ "# Have a tree per API.\n",
+ "\n",
+ "# The below doesn't achieve that yet."
]
},
{
"metadata": {},
"outputs": [],
"source": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "public_modules"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def append_module_dependencies_to_graph(di_graph, modules, dependency_map):\n",
+ " new_modules_to_traverse = set()\n",
+ " for module in modules:\n",
+ " if module not in di_graph:\n",
+ " di_graph.add_node(module)\n",
+ " for dependency in dependency_map[module]:\n",
+ " if dependency not in di_graph and dependency not in modules:\n",
+ " di_graph.add_node(dependency)\n",
+ " \n",
+ " if dependency in dependency_map.keys():\n",
+ " new_modules_to_traverse.add(dependency)\n",
+ " \n",
+ " di_graph.add_edge(module, dependency)\n",
+ " \n",
+ " return di_graph, new_modules_to_traverse "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "di_graph = networkx.DiGraph()\n",
+ "modules_to_traverse = public_modules\n",
+ "\n",
+ "while modules_to_traverse:\n",
+ " di_graph, modules_to_traverse = append_module_dependencies_to_graph(\n",
+ " di_graph, modules_to_traverse, module_dependencies)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "networkx.draw(di_graph)"
+ ]
}
],
"metadata": {
