Skip to content

Commit

Permalink
fix tox -e pydeps
Browse files Browse the repository at this point in the history
  • Loading branch information
boromir674 committed Dec 26, 2023
1 parent b7d209d commit 115903d
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions tox.ini
Expand Up @@ -379,47 +379,40 @@ commands_post =


## GENERATE ARCHITECTURE GRAPHS

[testenv:graphs]
description = Visualise the dependency graphs (roughly which module imports which), by examining the
Python code. The dependency graph(s) are rendered in .svg file(s) and saved on the disk. By default, the generated
files are stored in the 'pydoer-graphs' directory, inside the project's root folder. You can use the PYDOER_GRAPHS
environment variable to determine the directory location to store the files. If the directory does not exist
it gets created. Requires that the 'dot' executable is in your PATH. Installing the graphviz library should make
the dot executable available in your PATH. Installing 'graphviz':
* For Linux users using Debian-based distributions (ie Ubuntu, Debian, Mint), please run "sudo apt install graphviz"
* For MacOS users with Homebrew, please run "brew install graphviz"
basepython = {env:TOXPYTHON:python3.8}
# on ubuntu: sudo apt-get install graphviz && tox -e pydeps
# on mac: brew install graphviz && tox -e pydeps
[testenv:pydeps]
description =
Visualize Code, by drawing Python Imports as a Graph, and store as *.svg
For every import statement a link between 2 nodes is created.
Requires 'dot' executable, which is part of the graphviz package.
* On Linux: `sudo apt install graphviz`
* On mac: `brew install graphviz`
basepython = {env:TOXPYTHON:python3.10}
passenv =
HOME
PYDOER_GRAPHS
deps =
pydeps==1.9.13
PWD
PYDEPS_DIR
deps = pydeps==1.11.0
usedevelop = true
changedir = {toxinidir}
commands_pre =
python -c 'import os; p = "{env:PYDOER_GRAPHS:pydoer-graphs}"; exec("if not os.path.exists(p):\n os.mkdir(p)");'
# Create $PWD/$PYDEPS_DIR Folder, if it does not exist
python -c 'from pathlib import Path; import os; p = Path(os.environ["PWD"]) / os.getenv("PYDEPS_DIR", "pydeps"); p.mkdir(parents=True, exist_ok=True);'
commands =
pydeps --version

# --max-bacon : exclude nodes that are more than n hops away
# (default=2, 0 -> infinite)

# --min-cluster-size : the minimum number of nodes a dependency must have before being clustered (default=0)

# --max-cluster-size : the maximum number of nodes a dependency can have before the cluster is collapsed to a single node (default=0)
# --keep-target-cluster : draw target module as a cluster

# Draw only the source code package inner dependencies
pydeps src{/}{env:PY_PACKAGE} --only {env:PY_PACKAGE} --noshow -o {env:PYDOER_GRAPHS:pydoer-graphs}{/}deps_inner.svg
pydeps src{/}{env:PY_PACKAGE} --only {env:PY_PACKAGE} --noshow -o {env:PWD}{/}{env:PYDEPS_DIR:pydeps}{/}deps_inner.svg

# Draw the source code package inner and external dependencies
pydeps src{/}{env:PY_PACKAGE} --cluster --noshow -o {env:PYDOER_GRAPHS:pydoer-graphs}{/}deps_all.svg
pydeps src{/}{env:PY_PACKAGE} --cluster --noshow -o {env:PWD}{/}{env:PYDEPS_DIR:pydeps}{/}deps_all.svg

# Visualize the package inner dependencies and abstract the external (eg with numpy, pandas, etc) ones
# Draw the source code package inner and minimum external dependencies
pydeps src{/}{env:PY_PACKAGE} --max-cluster-size=2 --keep-target-cluster --noshow -o {env:PYDOER_GRAPHS:pydoer-graphs}{/}deps_ktc-mcs_2.svg
pydeps src{/}{env:PY_PACKAGE} --max-cluster-size=2 --keep-target-cluster --noshow -o {env:PWD}{/}{env:PYDEPS_DIR:pydeps}{/}deps_ktc-mcs_2.svg

# Draw the source code package inner and all external dependencies
pydeps src{/}{env:PY_PACKAGE} --keep-target-cluster --noshow -o {env:PYDOER_GRAPHS:pydoer-graphs}{/}deps_ktc.svg
pydeps src{/}{env:PY_PACKAGE} --keep-target-cluster --noshow -o {env:PWD}{/}{env:PYDEPS_DIR:pydeps}{/}deps_ktc.svg

python -c 'import os; print("\nGenerated dependency graph(s), as .svg files."); print("The graph(s) reside in the \"" + os.path.join("{toxinidir}", "{env:PYDOER_GRAPHS:pydoer-graphs}") + "\" directory and you can now view them ie in your browser.\n")'
### DONE ###
# Print List of SVGs, and show NEXT STEPS
python -c 'from pathlib import Path; import os; p = Path(os.environ["PWD"]) / os.getenv("PYDEPS_DIR", "pydeps"); print(f"\n [DONE] Generated .svg files inside folder: \"\{str(p.absolute())\}\".\n"); print("\n".join(os.listdir(p))); print(f"\n [NEXT STEPS]:\n--- Run:\nbrave-browser \{str(p.absolute())\}"); print("--- Ideas:\n- Integrate as part of Documentatoin Building.\n- Identify Spaghetti Code -> solve with better Design/Pattern.\n");'

0 comments on commit 115903d

Please sign in to comment.