Skip to content

Commit

Permalink
Reformat code with black and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Beitner committed Jan 14, 2021
1 parent a82f2c2 commit 2902f5b
Show file tree
Hide file tree
Showing 24 changed files with 696 additions and 377 deletions.
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
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
231 changes: 231 additions & 0 deletions Untitled.ipynb
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
}
4 changes: 2 additions & 2 deletions modvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"""A simple import analyzer. Visualize dependencies between modules."""

import ast
import os
import logging
from glob import glob
import logging
from optparse import OptionParser # TODO: migrate to argparse
import os

import pyan.node
import pyan.visgraph
Expand Down
8 changes: 4 additions & 4 deletions pyan/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from typing import Union, List
import io
from glob import glob
import io
from typing import List, Union

from .main import main # noqa: F401, for export only.
from .analyzer import CallGraphVisitor
from .writers import SVGWriter, HTMLWriter, DotWriter
from .main import main # noqa: F401, for export only.
from .visgraph import VisualGraph
from .writers import DotWriter, HTMLWriter, SVGWriter

__version__ = "1.1.2"

Expand Down
Loading

0 comments on commit 2902f5b

Please sign in to comment.