From d31301dfe08076e5d229175b2cd093c6fe60a6d5 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 2 Aug 2021 14:15:39 +0530 Subject: gnu: Add python-pyan3. * gnu/packages/python-xyz.scm (python-pyan3): New variable. * gnu/packages/patches/python-pyan3-fix-absolute-path-bug.patch, gnu/packages/patches/python-pyan3-fix-positional-arguments.patch: New files. * gnu/local.mk: Register them. --- gnu/local.mk | 2 + .../python-pyan3-fix-absolute-path-bug.patch | 160 +++++++++++++++++++++ .../python-pyan3-fix-positional-arguments.patch | 22 +++ gnu/packages/python-xyz.scm | 42 ++++++ 4 files changed, 226 insertions(+) create mode 100644 gnu/packages/patches/python-pyan3-fix-absolute-path-bug.patch create mode 100644 gnu/packages/patches/python-pyan3-fix-positional-arguments.patch diff --git a/gnu/local.mk b/gnu/local.mk index 6dda311743..8c69ddc907 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1649,6 +1649,8 @@ dist_patch_DATA = \ %D%/packages/patches/python-paste-remove-timing-test.patch \ %D%/packages/patches/python-pycrypto-CVE-2013-7459.patch \ %D%/packages/patches/python-pycrypto-time-clock.patch \ + %D%/packages/patches/python-pyan3-fix-absolute-path-bug.patch \ + %D%/packages/patches/python-pyan3-fix-positional-arguments.patch \ %D%/packages/patches/python-pydot-regression-test.patch \ %D%/packages/patches/python2-pygobject-2-deprecation.patch \ %D%/packages/patches/python-pygpgme-fix-pinentry-tests.patch \ diff --git a/gnu/packages/patches/python-pyan3-fix-absolute-path-bug.patch b/gnu/packages/patches/python-pyan3-fix-absolute-path-bug.patch new file mode 100644 index 0000000000..0b6a083fa3 --- /dev/null +++ b/gnu/packages/patches/python-pyan3-fix-absolute-path-bug.patch @@ -0,0 +1,160 @@ +From ac1bd55d07fd1bad2f4a92dc0809607c407d9140 Mon Sep 17 00:00:00 2001 +From: "Maciej A. Czyzewski" +Date: Wed, 9 Jun 2021 15:29:18 +0200 +Subject: [PATCH] feature: new params for graphviz + solves #70 + +- solve abs path bug #70 +- new params for graphviz (ranksep; layout) +- tested layout `dot`; `fdp` (square graph) +- updated `.gitignore` (files gen. after `visualize_pyan_architecture.sh`) +--- + .gitignore | 5 ++++ + README.md | 6 ++-- + pyan/main.py | 55 +++++++++++++++++++++++++++++++--- + visualize_pyan_architecture.sh | 5 ++++ + 4 files changed, 64 insertions(+), 7 deletions(-) + +diff --git a/.gitignore b/.gitignore +index 990fdc0c..93313aaf 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -162,3 +162,8 @@ htmlcov + .idea/ + .history/ + .vscode/ ++ ++# our vis. of architecture ++architecture.dot ++architecture.html ++architecture.svg +diff --git a/README.md b/README.md +index d1f19dcf..9e6919a3 100644 +--- a/README.md ++++ b/README.md +@@ -48,7 +48,7 @@ See `pyan3 --help`. + + Example: + +-`pyan *.py --uses --no-defines --colored --grouped --annotated --dot >myuses.dot` ++`pyan3 *.py --uses --no-defines --colored --grouped --annotated --dot >myuses.dot` + + Then render using your favorite GraphViz filter, mainly `dot` or `fdp`: + +@@ -56,11 +56,11 @@ Then render using your favorite GraphViz filter, mainly `dot` or `fdp`: + + Or use directly + +-`pyan *.py --uses --no-defines --colored --grouped --annotated --svg >myuses.svg` ++`pyan3 *.py --uses --no-defines --colored --grouped --annotated --svg >myuses.svg` + + You can also export as an interactive HTML + +-`pyan *.py --uses --no-defines --colored --grouped --annotated --html > myuses.html` ++`pyan3 *.py --uses --no-defines --colored --grouped --annotated --html > myuses.html` + + Alternatively, you can call `pyan` from a script + +diff --git a/pyan/main.py b/pyan/main.py +index 5d079714..b1a16f63 100644 +--- a/pyan/main.py ++++ b/pyan/main.py +@@ -141,6 +141,31 @@ def main(cli_args=None): + ), + ) + ++ parser.add_argument( ++ "--dot-ranksep", ++ default="0.5", ++ dest="ranksep", ++ help=( ++ "specifies the dot graph 'ranksep' property for " ++ "controlling desired rank separation, in inches. " ++ "Allowed values: [0.02 .. 1000.0]. " ++ "[dot only]" ++ ), ++ ) ++ ++ parser.add_argument( ++ "--graphviz-layout", ++ default="dot", ++ dest="layout", ++ help=( ++ "specifies the graphviz 'layout' property for " ++ "the name of the layout algorithm to use. " ++ "Allowed values: ['dot', 'neato', 'fdp', 'sfdp', 'twopi', 'circo']. " ++ "Recommended values: ['dot', 'fdp']. " ++ "[graphviz only]" ++ ), ++ ) ++ + parser.add_argument( + "-a", + "--annotated", +@@ -159,7 +184,12 @@ def main(cli_args=None): + + known_args, unknown_args = parser.parse_known_args(cli_args) + +- filenames = [fn2 for fn in unknown_args for fn2 in glob(fn, recursive=True)] ++ ++ filenames = [] ++ for fn in unknown_args: ++ for fn2 in glob(fn, recursive=True): ++ abs_fn2 = os.path.abspath(fn2) ++ filenames.append(abs_fn2) + + # determine root + if known_args.root is not None: +@@ -203,6 +233,11 @@ def main(cli_args=None): + handler = logging.FileHandler(known_args.logname) + logger.addHandler(handler) + ++ logger.debug(f"[files] {unknown_args}") ++ ++ if root: ++ root = os.path.abspath(root) ++ + v = CallGraphVisitor(filenames, logger=logger, root=root) + + if known_args.function or known_args.namespace: +@@ -222,13 +257,25 @@ def main(cli_args=None): + writer = None + + if known_args.dot: +- writer = DotWriter(graph, options=["rankdir=" + known_args.rankdir], output=known_args.filename, logger=logger) ++ writer = DotWriter(graph, options=[ ++ "rankdir=" + known_args.rankdir, ++ "ranksep=" + known_args.ranksep, ++ "layout=" + known_args.layout, ++ ], output=known_args.filename, logger=logger) + + if known_args.html: +- writer = HTMLWriter(graph, options=["rankdir=" + known_args.rankdir], output=known_args.filename, logger=logger) ++ writer = HTMLWriter(graph, options=[ ++ "rankdir=" + known_args.rankdir, ++ "ranksep=" + known_args.ranksep, ++ "layout=" + known_args.layout, ++ ], output=known_args.filename, logger=logger) + + if known_args.svg: +- writer = SVGWriter(graph, options=["rankdir=" + known_args.rankdir], output=known_args.filename, logger=logger) ++ writer = SVGWriter(graph, options=[ ++ "rankdir=" + known_args.rankdir, ++ "ranksep=" + known_args.ranksep, ++ "layout=" + known_args.layout, ++ ], output=known_args.filename, logger=logger) + + if known_args.tgf: + writer = TgfWriter(graph, output=known_args.filename, logger=logger) +diff --git a/visualize_pyan_architecture.sh b/visualize_pyan_architecture.sh +index 22c63342..81b6ca24 100755 +--- a/visualize_pyan_architecture.sh ++++ b/visualize_pyan_architecture.sh +@@ -2,3 +2,8 @@ + echo -ne "Pyan architecture: generating architecture.{dot,svg}\n" + python3 -m pyan pyan/*.py --no-defines --uses --colored --annotate --dot -V >architecture.dot 2>architecture.log + dot -Tsvg architecture.dot >architecture.svg ++echo -ne "Pyan architecture: generating architecture.{html,graphviz=fdp}\n" ++python3 -m pyan pyan/*.py --no-defines --uses \ ++ --grouped --nested-groups \ ++ --graphviz-layout fdp \ ++ --colored --html > architecture.html diff --git a/gnu/packages/patches/python-pyan3-fix-positional-arguments.patch b/gnu/packages/patches/python-pyan3-fix-positional-arguments.patch new file mode 100644 index 0000000000..81923d7a41 --- /dev/null +++ b/gnu/packages/patches/python-pyan3-fix-positional-arguments.patch @@ -0,0 +1,22 @@ +From 37404bb039bd9c5509b4aec8f61e360dfba50715 Mon Sep 17 00:00:00 2001 +From: Wenxin Ling +Date: Mon, 1 Mar 2021 15:21:16 +0100 +Subject: [PATCH] Fix positional arguments issue for CallGraphVisitor + +--- + pyan/main.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/pyan/main.py b/pyan/main.py +index 18821a14..5d079714 100644 +--- a/pyan/main.py ++++ b/pyan/main.py +@@ -203,7 +203,7 @@ def main(cli_args=None): + handler = logging.FileHandler(known_args.logname) + logger.addHandler(handler) + +- v = CallGraphVisitor(filenames, logger, root=root) ++ v = CallGraphVisitor(filenames, logger=logger, root=root) + + if known_args.function or known_args.namespace: + diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm index 56920f68c3..87a90ab680 100644 --- a/gnu/packages/python-xyz.scm +++ b/gnu/packages/python-xyz.scm @@ -26232,3 +26232,45 @@ for the Go language tool chain; it adapts to different calling conventions and application binary interfaces (ABIs); it takes care of register allocation; it supports x86_64 instructions up to AVX-512 and SHA.") (license license:bsd-2)))) + +(define-public python-pyan3 + (package + (name "python-pyan3") + (version "1.2.0") + (source + (origin + ;; Source tarball on PyPI lacks tests. + (method git-fetch) + (uri (git-reference + (url "https://github.com/Technologicat/pyan") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) + (sha256 + (base32 + "1367x25rcy2y8f0x9c2dbxl2qgdln3arr7ddyzybz2c28g6jrv5z")) + (patches (search-patches "python-pyan3-fix-positional-arguments.patch" + "python-pyan3-fix-absolute-path-bug.patch")))) + (build-system python-build-system) + (arguments + `(#:phases + (modify-phases %standard-phases + (replace 'check + (lambda* (#:key tests? #:allow-other-keys) + (when tests? + ;; Extend PYTHONPATH so the built package will be found. + (setenv "PYTHONPATH" + (string-append (getcwd) ":" (getenv "PYTHONPATH"))) + (invoke "pytest"))))))) + (native-inputs + `(("python-pytest" ,python-pytest) + ("python-pytest-cov" ,python-pytest-cov) + ("python-wheel" ,python-wheel))) + (propagated-inputs + `(("python-jinja2" ,python-jinja2))) + (home-page "https://github.com/Technologicat/pyan") + (synopsis "Offline call graph generator for Python 3") + (description "Pyan takes one or more Python source files, performs +a (rather superficial) static analysis, and constructs a directed graph of the +objects in the combined source, and how they define or use each other. The +graph can be output for rendering by GraphViz or yEd.") + (license license:gpl2))) -- cgit v1.2.3