pipforester 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ ## Changes
2
+
3
+ ### 1.0.0 (2023-05-16)
4
+
5
+ - fix the cyclic dependency display to show all edges of a cycle in dark violet. [@jensens]
6
+ - fix graph of cycles not to show graph multiple times. [@jensens]
7
+
8
+ ### 1.0.0a1 (2023-05-15)
9
+
10
+ - initial code [jensens]
@@ -0,0 +1,26 @@
1
+ # License
2
+
3
+ Copyright (c) 2022-2023, mxstack Contributors
4
+
5
+ All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this
11
+ list of conditions and the following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above copyright notice, this
14
+ list of conditions and the following disclaimer in the documentation and/or
15
+ other materials provided with the distribution.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.1
2
+ Name: pipforester
3
+ Version: 1.0.0
4
+ Summary: A tool to analyze the dependency graph of a pip package.
5
+ Author-email: Jens Klein et al <jk@kleinundpartner.at>
6
+ License: BSD 2-Clause License
7
+ Project-URL: Homepage, https://github.com/collective/pipforester
8
+ Project-URL: Bug Reports, https://github.com/collective/pipforester/issues
9
+ Project-URL: Source, https://github.com/collective/pipforester/
10
+ Keywords: pip,graph,analysis
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Build Tools
14
+ Classifier: License :: OSI Approved :: BSD License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3.7
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Requires-Python: >=3.7
23
+ Description-Content-Type: text/markdown
24
+ Provides-Extra: test
25
+ License-File: LICENSE.md
26
+
27
+ # pipforester
28
+
29
+ Forester tools for [pipdeptree](https://pypi.org/project/pipdeptree/) outputs to analyze the dependency graph of a pip package.
30
+
31
+ ## Features
32
+
33
+ - clean up a graph to remove direct dependencies if a transitive dependency exists
34
+ - detect transitive cyclic dependencies (and color them in output)
35
+
36
+ ## Usage
37
+
38
+ Important: *pipdeptree* **MUST** be installed in an environment together with the dependencies you want to check. If you install *pipdeptree* in virtual environment 1 and then call it in the directory of virtual environment 2, it will only report on its own dependencies, which is not very useful.
39
+
40
+ First, call *pipdeptree* to create a JSON file of the installed dependencies,
41
+ and second call *pipforester* to create a cleaned-up dot file.
42
+
43
+ ```shell
44
+ pipdeptree -j >forest.json
45
+ pipforester -i forest.json -o forest.dot
46
+ ```
47
+
48
+ Finally use a Graphviz DOT-file visualizer, i.e. *xdot* on Linux, to view the graph.
49
+ Or use the *dot* command line program to generate an svg or png:
50
+
51
+ ```
52
+ dot -Tsvg -o forest.svg forest.dot
53
+ dot -Tpng -o forest.png forest.dot
54
+ ```
55
+
56
+ To generate a graph containing only cyclic transitive dependencies, use the `--cycles` option:
57
+
58
+ ```shell
59
+ pipdeptree -j >forest.json
60
+ pipforester -i forest.json -o forest.dot --cycles
61
+ ```
62
+
63
+ To detect cyclic transitive dependencies and exit with `1` if there is at least one, use the `--check-cycles` option.
64
+ It does not generate an output graph and is meant for usage in CI.
65
+
66
+ ```shell
67
+ pipdeptree -j >forest.json
68
+ pipforester -i forest.json --check-cycles
69
+ ```
70
+
71
+ See `pipforester --help` for details.
72
+
73
+
74
+ ## Changes
75
+
76
+ ### 1.0.0 (2023-05-16)
77
+
78
+ - fix the cyclic dependency display to show all edges of a cycle in dark violet. [@jensens]
79
+ - fix graph of cycles not to show graph multiple times. [@jensens]
80
+
81
+ ### 1.0.0a1 (2023-05-15)
82
+
83
+ - initial code [jensens]
84
+ # License
85
+
86
+ Copyright (c) 2022-2023, mxstack Contributors
87
+
88
+ All rights reserved.
89
+
90
+ Redistribution and use in source and binary forms, with or without
91
+ modification, are permitted provided that the following conditions are met:
92
+
93
+ * Redistributions of source code must retain the above copyright notice, this
94
+ list of conditions and the following disclaimer.
95
+
96
+ * Redistributions in binary form must reproduce the above copyright notice, this
97
+ list of conditions and the following disclaimer in the documentation and/or
98
+ other materials provided with the distribution.
99
+
100
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
101
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
102
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
103
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
104
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
105
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
106
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
107
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
108
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
109
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,46 @@
1
+ # pipforester
2
+
3
+ Forester tools for [pipdeptree](https://pypi.org/project/pipdeptree/) outputs to analyze the dependency graph of a pip package.
4
+
5
+ ## Features
6
+
7
+ - clean up a graph to remove direct dependencies if a transitive dependency exists
8
+ - detect transitive cyclic dependencies (and color them in output)
9
+
10
+ ## Usage
11
+
12
+ Important: *pipdeptree* **MUST** be installed in an environment together with the dependencies you want to check. If you install *pipdeptree* in virtual environment 1 and then call it in the directory of virtual environment 2, it will only report on its own dependencies, which is not very useful.
13
+
14
+ First, call *pipdeptree* to create a JSON file of the installed dependencies,
15
+ and second call *pipforester* to create a cleaned-up dot file.
16
+
17
+ ```shell
18
+ pipdeptree -j >forest.json
19
+ pipforester -i forest.json -o forest.dot
20
+ ```
21
+
22
+ Finally use a Graphviz DOT-file visualizer, i.e. *xdot* on Linux, to view the graph.
23
+ Or use the *dot* command line program to generate an svg or png:
24
+
25
+ ```
26
+ dot -Tsvg -o forest.svg forest.dot
27
+ dot -Tpng -o forest.png forest.dot
28
+ ```
29
+
30
+ To generate a graph containing only cyclic transitive dependencies, use the `--cycles` option:
31
+
32
+ ```shell
33
+ pipdeptree -j >forest.json
34
+ pipforester -i forest.json -o forest.dot --cycles
35
+ ```
36
+
37
+ To detect cyclic transitive dependencies and exit with `1` if there is at least one, use the `--check-cycles` option.
38
+ It does not generate an output graph and is meant for usage in CI.
39
+
40
+ ```shell
41
+ pipdeptree -j >forest.json
42
+ pipforester -i forest.json --check-cycles
43
+ ```
44
+
45
+ See `pipforester --help` for details.
46
+
@@ -0,0 +1,27 @@
1
+ from . import deptree
2
+
3
+ import click
4
+ import json
5
+
6
+
7
+ @click.command()
8
+ @click.option("--input", "-i", type=click.File("r"))
9
+ @click.option("--output", "-o")
10
+ @click.option("--cycles", is_flag=True)
11
+ @click.option("--check-cycles", is_flag=True)
12
+ def main(input, output, cycles, check_cycles):
13
+ deptreedata = json.load(input)
14
+ graph = deptree.graph_from_json(deptreedata)
15
+ if check_cycles:
16
+ bad_edges = deptree.detect_cyclic_edges(graph)
17
+ if bad_edges:
18
+ print("Cyclic dependencies detected")
19
+ exit(1)
20
+ elif cycles:
21
+ graph = deptree.extract_cyclic_graph(graph)
22
+ else:
23
+ bad_edges = deptree.detect_cyclic_edges(graph)
24
+ deptree.remove_cyclic_edges(graph, bad_edges)
25
+ deptree.remove_direct_edges(graph, ignore=bad_edges)
26
+ deptree.add_cyclic_edges(graph, bad_edges)
27
+ deptree.write_dotfile(graph, output)
@@ -0,0 +1,86 @@
1
+ import json
2
+ import networkx as nx
3
+
4
+
5
+ def read_deptree(filepath):
6
+ with open(filepath) as f:
7
+ data = json.load(f)
8
+ return data
9
+
10
+
11
+ def write_dotfile(G, filepath):
12
+ nx.nx_agraph.write_dot(G, filepath)
13
+
14
+
15
+ def graph_from_json(data):
16
+ G = nx.DiGraph()
17
+ for pkgdef in data:
18
+ pkg = pkgdef["package"]
19
+ G.add_node(
20
+ pkg["key"],
21
+ installed_version=pkg["installed_version"],
22
+ name=pkg["package_name"],
23
+ )
24
+ for dep in pkgdef["dependencies"]:
25
+ G.add_edge(pkg["key"], dep["key"])
26
+ return G
27
+
28
+
29
+ def detect_cyclic_edges(G):
30
+ print("Detecting cyclic edges")
31
+ bad_edges = set()
32
+ cycles = nx.simple_cycles(G)
33
+ for cycle in cycles:
34
+ for idx in range(len(cycle) - 1):
35
+ print(f"found edge {cycle[idx]} -> {cycle[idx + 1]}")
36
+ bad_edges.add((cycle[idx], cycle[idx + 1]))
37
+ bad_edges.add((cycle[-1], cycle[0]))
38
+ return bad_edges
39
+
40
+
41
+ def extract_cyclic_graph(G):
42
+ print("Extracting cyclic edges")
43
+ CG = nx.DiGraph()
44
+ bad_edges = set()
45
+ for num, cycle in enumerate(nx.simple_cycles(G)):
46
+ if (cycle[-1], cycle[0]) in bad_edges:
47
+ continue
48
+ for idx in range(len(cycle) - 1):
49
+ CG.add_edge(f"{cycle[idx]} ({num})", f"{cycle[idx + 1]} ({num})")
50
+ CG.add_edge(f"{cycle[-1]} ({num})", f"{cycle[0]} ({num})")
51
+ bad_edges.add((cycle[-1], cycle[0]))
52
+ return CG
53
+
54
+ def remove_cyclic_edges(G, bad_edges):
55
+ print("Removing cyclic edges")
56
+ for edge in bad_edges:
57
+ G.remove_edge(edge[0], edge[1])
58
+
59
+
60
+ def add_cyclic_edges(G, bad_edges):
61
+ print("Adding cyclic edges")
62
+ for edge in bad_edges:
63
+ G.add_edge(edge[0], edge[1])
64
+ G.edges[edge[0], edge[1]]["color"] = "darkviolet"
65
+
66
+
67
+ def remove_direct_edges(G, ignore=None):
68
+ print("Removing direct edges")
69
+ if ignore is None:
70
+ ignore = []
71
+ for node in G.nodes():
72
+ # get all edges origin in node
73
+ print(f" Node: {node}")
74
+ out_edges = list(G.out_edges(node))
75
+ for out_edge in out_edges:
76
+ if tuple(out_edge) in ignore:
77
+ print(f" Ignore cyclic: {node}")
78
+ continue
79
+ print(f" Out edge to {out_edge[1]}")
80
+ for path in nx.all_simple_paths(G, node, out_edge[1]):
81
+ # if there is a path from node to out_edge[1] that is longer than 1,
82
+ # then remove the edge
83
+ if len(path) > 2:
84
+ print(" -> remove")
85
+ G.remove_edge(out_edge[0], out_edge[1])
86
+ break
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.1
2
+ Name: pipforester
3
+ Version: 1.0.0
4
+ Summary: A tool to analyze the dependency graph of a pip package.
5
+ Author-email: Jens Klein et al <jk@kleinundpartner.at>
6
+ License: BSD 2-Clause License
7
+ Project-URL: Homepage, https://github.com/collective/pipforester
8
+ Project-URL: Bug Reports, https://github.com/collective/pipforester/issues
9
+ Project-URL: Source, https://github.com/collective/pipforester/
10
+ Keywords: pip,graph,analysis
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Build Tools
14
+ Classifier: License :: OSI Approved :: BSD License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3.7
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Requires-Python: >=3.7
23
+ Description-Content-Type: text/markdown
24
+ Provides-Extra: test
25
+ License-File: LICENSE.md
26
+
27
+ # pipforester
28
+
29
+ Forester tools for [pipdeptree](https://pypi.org/project/pipdeptree/) outputs to analyze the dependency graph of a pip package.
30
+
31
+ ## Features
32
+
33
+ - clean up a graph to remove direct dependencies if a transitive dependency exists
34
+ - detect transitive cyclic dependencies (and color them in output)
35
+
36
+ ## Usage
37
+
38
+ Important: *pipdeptree* **MUST** be installed in an environment together with the dependencies you want to check. If you install *pipdeptree* in virtual environment 1 and then call it in the directory of virtual environment 2, it will only report on its own dependencies, which is not very useful.
39
+
40
+ First, call *pipdeptree* to create a JSON file of the installed dependencies,
41
+ and second call *pipforester* to create a cleaned-up dot file.
42
+
43
+ ```shell
44
+ pipdeptree -j >forest.json
45
+ pipforester -i forest.json -o forest.dot
46
+ ```
47
+
48
+ Finally use a Graphviz DOT-file visualizer, i.e. *xdot* on Linux, to view the graph.
49
+ Or use the *dot* command line program to generate an svg or png:
50
+
51
+ ```
52
+ dot -Tsvg -o forest.svg forest.dot
53
+ dot -Tpng -o forest.png forest.dot
54
+ ```
55
+
56
+ To generate a graph containing only cyclic transitive dependencies, use the `--cycles` option:
57
+
58
+ ```shell
59
+ pipdeptree -j >forest.json
60
+ pipforester -i forest.json -o forest.dot --cycles
61
+ ```
62
+
63
+ To detect cyclic transitive dependencies and exit with `1` if there is at least one, use the `--check-cycles` option.
64
+ It does not generate an output graph and is meant for usage in CI.
65
+
66
+ ```shell
67
+ pipdeptree -j >forest.json
68
+ pipforester -i forest.json --check-cycles
69
+ ```
70
+
71
+ See `pipforester --help` for details.
72
+
73
+
74
+ ## Changes
75
+
76
+ ### 1.0.0 (2023-05-16)
77
+
78
+ - fix the cyclic dependency display to show all edges of a cycle in dark violet. [@jensens]
79
+ - fix graph of cycles not to show graph multiple times. [@jensens]
80
+
81
+ ### 1.0.0a1 (2023-05-15)
82
+
83
+ - initial code [jensens]
84
+ # License
85
+
86
+ Copyright (c) 2022-2023, mxstack Contributors
87
+
88
+ All rights reserved.
89
+
90
+ Redistribution and use in source and binary forms, with or without
91
+ modification, are permitted provided that the following conditions are met:
92
+
93
+ * Redistributions of source code must retain the above copyright notice, this
94
+ list of conditions and the following disclaimer.
95
+
96
+ * Redistributions in binary form must reproduce the above copyright notice, this
97
+ list of conditions and the following disclaimer in the documentation and/or
98
+ other materials provided with the distribution.
99
+
100
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
101
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
102
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
103
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
104
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
105
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
106
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
107
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
108
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
109
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,13 @@
1
+ CHANGES.md
2
+ LICENSE.md
3
+ README.md
4
+ pyproject.toml
5
+ pipforester/__init__.py
6
+ pipforester/deptree.py
7
+ pipforester.egg-info/PKG-INFO
8
+ pipforester.egg-info/SOURCES.txt
9
+ pipforester.egg-info/dependency_links.txt
10
+ pipforester.egg-info/entry_points.txt
11
+ pipforester.egg-info/not-zip-safe
12
+ pipforester.egg-info/requires.txt
13
+ pipforester.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pipforester = pipforester:main
@@ -0,0 +1,7 @@
1
+ click
2
+ networkx
3
+ pipdeptree
4
+ pygraphviz
5
+
6
+ [test]
7
+ pytest
@@ -0,0 +1 @@
1
+ pipforester
@@ -0,0 +1,86 @@
1
+ [project]
2
+ name = "pipforester"
3
+ description = "A tool to analyze the dependency graph of a pip package."
4
+ version = "1.0.0"
5
+ keywords = ["pip", "graph", "analysis"]
6
+ authors = [
7
+ {name = "Jens Klein et al", email = "jk@kleinundpartner.at" }
8
+ ]
9
+ requires-python = ">=3.7"
10
+ license = { text = "BSD 2-Clause License" }
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Intended Audience :: Developers",
14
+ "Topic :: Software Development :: Build Tools",
15
+ "License :: OSI Approved :: BSD License",
16
+ "Operating System :: OS Independent",
17
+ "Programming Language :: Python",
18
+ "Programming Language :: Python :: 3.7",
19
+ "Programming Language :: Python :: 3.8",
20
+ "Programming Language :: Python :: 3.9",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ ]
24
+ dependencies = [
25
+ "click",
26
+ "networkx",
27
+ "pipdeptree",
28
+ "pygraphviz",
29
+ ]
30
+ dynamic = ["readme"]
31
+
32
+ [project.optional-dependencies]
33
+ test = [
34
+ "pytest",
35
+ ]
36
+
37
+ [project.urls]
38
+ Homepage = "https://github.com/collective/pipforester"
39
+ "Bug Reports" = "https://github.com/collective/pipforester/issues"
40
+ Source = "https://github.com/collective/pipforester/"
41
+
42
+ [project.scripts]
43
+ pipforester = "pipforester:main"
44
+
45
+ [build-system]
46
+ requires = ["setuptools"]
47
+ build-backend = "setuptools.build_meta"
48
+
49
+ [tool.setuptools]
50
+ zip-safe = false
51
+ packages = ["pipforester"]
52
+
53
+ [tool.setuptools.dynamic]
54
+ readme = {file = ["README.md", "CHANGES.md", "LICENSE.md"], content-type = "text/markdown"}
55
+
56
+ [tool.pytest.ini_options]
57
+ minversion = "6.0"
58
+ addopts = "-ra -q"
59
+ testpaths = [
60
+ "src",
61
+ ]
62
+
63
+ [tool.isort]
64
+ profile = "black"
65
+ force_alphabetical_sort = true
66
+ force_single_line = true
67
+ lines_after_imports = 2
68
+
69
+ [tool.mypy]
70
+ ignore_missing_imports = true
71
+
72
+ [tool.flake8]
73
+ # Excludes due to known issues or incompatibilities with black:
74
+ # BLK100: Black would make changes. https://pypi.org/project/flake8-black/
75
+ # W503: https://github.com/psf/black/search?q=W503&unscoped_q=W503
76
+ # E231: https://github.com/psf/black/issues/1202
77
+ ignore = "BLK100,E231,W503,D100,D101,D102,D102,D103,D104,D105,D106,D107,D202,D205"
78
+ statistics = 1
79
+ # black official is 88, but can get longer
80
+ max-line-length = 120
81
+
82
+ [tool.doc8]
83
+ # TODO: Remove current max-line-lengh ignore in follow-up and adopt black limit.
84
+ # max-line-length = 88
85
+ ignore = "D001"
86
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+