-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Beitner
committed
Jan 14, 2021
1 parent
a82f2c2
commit 2902f5b
Showing
24 changed files
with
696 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# See https://pre-commit.com for more information | ||
# See https://pre-commit.com/hooks.html for more hooks | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v3.3.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- repo: https://gitlab.com/pycqa/flake8 | ||
rev: "" | ||
hooks: | ||
- id: flake8 | ||
- repo: https://github.com/pre-commit/mirrors-isort | ||
rev: v5.6.4 | ||
hooks: | ||
- id: isort | ||
- repo: https://github.com/psf/black | ||
rev: 20.8b1 | ||
hooks: | ||
- id: black |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"scrolled": true | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"['../qvc/pricing/pricing/data/assets.py']\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import pyan as p\n", | ||
"from glob import glob\n", | ||
"import importlib\n", | ||
"importlib.reload(p)\n", | ||
"\n", | ||
"filenames = glob(f\"../qvc/pricing/pricing/data/assets.py\", recursive=True)\n", | ||
"print(filenames)\n", | ||
"import logging\n", | ||
"logging.basicConfig(level=logging.ERROR)\n", | ||
"visitor = p.analyzer.CallGraphVisitor(filenames, logging.getLogger())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[<Node function:pricing.data.assets.price_history_with_cost>]" | ||
] | ||
}, | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"def get_related_nodes(visitor, node, namespace=\"pricing\", i=10):\n", | ||
" new_nodes = [node]\n", | ||
" if i < 0:\n", | ||
" return new_nodes\n", | ||
"\n", | ||
" for n in visitor.uses_edges.get(node, []):\n", | ||
" if n in visitor.uses_edges and n not in new_nodes and n.namespace.startswith(namespace):\n", | ||
" new_nodes.extend(get_related_nodes(visitor, n, namespace=namespace, i=i - 1))\n", | ||
"\n", | ||
" for n in visitor.defines_edges.get(node, []):\n", | ||
" if n in visitor.defines_edges and n not in new_nodes and n.namespace.startswith(namespace):\n", | ||
" new_nodes.extend(get_related_nodes(visitor, n, namespace=namespace, i=i - 1))\n", | ||
" return new_nodes\n", | ||
"\n", | ||
"node = [\n", | ||
" n\n", | ||
" for n in visitor.uses_edges.keys()\n", | ||
" if repr(n.flavor) == \"function\" and n.namespace.startswith(\"pricing.data.assets\")\n", | ||
" ][1]\n", | ||
"node\n", | ||
"get_related_nodes(visitor, node)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"<Node function:pricing.data.assets.price_history_with_cost>" | ||
] | ||
}, | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"node" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{<Node ---:*.products>: None,\n", | ||
" <Node ???:*.astype>: None,\n", | ||
" <Node ???:*.dict>: None,\n", | ||
" <Node ---:*.^^^argument^^^>: None,\n", | ||
" <Node ???:*.dtype>: None,\n", | ||
" <Node ???:*.drop>: None}" | ||
] | ||
}, | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"{n: n.namespace for n in visitor.uses_edges[node]}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"ename": "KeyError", | ||
"evalue": "<Node function:pricing.data.assets.price_history_with_cost>", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", | ||
"\u001b[0;32m<ipython-input-10-a891d0fbc3e7>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;34m{\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnamespace\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mn\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mvisitor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdefines_edges\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mnode\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | ||
"\u001b[0;31mKeyError\u001b[0m: <Node function:pricing.data.assets.price_history_with_cost>" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"{n: n.namespace for n in visitor.defines_edges[node]}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 106, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"{'func': <_ast.Attribute object at 0x7fc0e18d7048>, 'args': [<_ast.Name object at 0x7fc0e18d70b8>], 'keywords': [], 'lineno': 285, 'col_offset': 8}\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"def print_func(f):\n", | ||
" if isinstance(f, list):\n", | ||
" for s in f:\n", | ||
" print_func(s)\n", | ||
" else:\n", | ||
" print(f.__dict__)\n", | ||
"print_func(node.ast_node.body[2].value.func.value)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 35, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"['../qvc/pricing/pricing/data/assets.py']" | ||
] | ||
}, | ||
"execution_count": 35, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"node.ast_node" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 18, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"ename": "AssertionError", | ||
"evalue": "", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", | ||
"\u001b[0;32m<ipython-input-18-95fa35472356>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mvisitor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_node_of_current_namespace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | ||
"\u001b[0;32m~/Documents/Github/pyan/pyan/analyzer.py\u001b[0m in \u001b[0;36mget_node_of_current_namespace\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1105\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mno\u001b[0m \u001b[0massociated\u001b[0m \u001b[0mAST\u001b[0m \u001b[0mnode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1106\u001b[0m \"\"\"\n\u001b[0;32m-> 1107\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname_stack\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# name_stack should never be empty (always at least module name)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1108\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1109\u001b[0m \u001b[0mnamespace\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'.'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname_stack\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
"\u001b[0;31mAssertionError\u001b[0m: " | ||
] | ||
} | ||
], | ||
"source": [ | ||
"visitor.get_node_of_current_namespace()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.