digdep 0.0.3__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.
digdep-0.0.3/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shine Jayakumar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
digdep-0.0.3/PKG-INFO ADDED
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: digdep
3
+ Version: 0.0.3
4
+ Summary: Analyze Python import dependencies.
5
+ Author: Shine Jayakumar
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/shine-jayakumar/digdep
8
+ Project-URL: Repository, https://github.com/shine-jayakumar/digdep
9
+ Project-URL: Issues, https://github.com/shine-jayakumar/digdep/issues
10
+ Keywords: python,dependency,dependencies,import,imports,dependency-analyzer,static-analysis,code-analysis,ast,cli
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Topic :: Software Development :: Quality Assurance
20
+ Classifier: Topic :: Utilities
21
+ Requires-Python: >=3.11
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: rich>=14.0.0
25
+ Dynamic: license-file
26
+
27
+ # DigDep
28
+
29
+ ![Version](https://img.shields.io/static/v1?label=version&message=v.0.0.3&color=blue)
30
+ ![License](https://img.shields.io/static/v1?label=license&message=MIT&color=green)
31
+ ![Status](https://img.shields.io/badge/status-alpha-yellow.svg)
32
+ ![Open Source](https://img.shields.io/static/v1?label=OpenSource&message=Yes&color=brightgreen)
33
+ ![GitHub issues](https://img.shields.io/github/issues/shine-jayakumar/docdsl)
34
+ ![Last Commit](https://img.shields.io/github/last-commit/shine-jayakumar/docdsl)
35
+
36
+ A lightweight Python dependency analyzer that scans Python projects and visualizes import relationships.
37
+
38
+ ---
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ pip install digdep
44
+ ```
45
+ ---
46
+
47
+ ## Quick Start (CLI)
48
+
49
+ List all imported packages:
50
+
51
+ ```bash
52
+ digdep packages ./myproject
53
+ ```
54
+
55
+ Show the File → Dependency tree:
56
+
57
+ ```bash
58
+ digdep file-tree ./myproject
59
+ ```
60
+
61
+ Show the Dependency → File tree:
62
+
63
+ ```bash
64
+ digdep dep-tree ./myproject
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Sample Output
70
+
71
+ ### File → Dependency Tree
72
+
73
+ ```text
74
+ Root (/projects/example)
75
+
76
+ ├── main.py → requests, pathlib
77
+ ├── config.py → json
78
+
79
+ ├── modules/
80
+ │ ├── logger.py → logging
81
+ │ ├── parser.py → re, typing
82
+
83
+ └── utils/
84
+ └── helpers.py → functools
85
+ ```
86
+
87
+ ### Dependency → File Tree
88
+
89
+ ```text
90
+ requests
91
+ ├── main.py
92
+
93
+ re
94
+ ├── modules/
95
+ │ └── parser.py
96
+
97
+ logging
98
+ ├── modules/
99
+ │ └── logger.py
100
+ ```
101
+
102
+ ---
103
+
104
+ ## Filtering
105
+
106
+ Filter dependencies by type.
107
+
108
+ Show only standard library imports:
109
+
110
+ ```bash
111
+ digdep file-tree ./myproject --type stdlib
112
+ ```
113
+
114
+ Show both standard library and third-party imports:
115
+
116
+ ```bash
117
+ digdep file-tree ./myproject --type stdlib,third-party
118
+ ```
119
+
120
+ Show only local imports:
121
+
122
+ ```bash
123
+ digdep file-tree ./myproject --type local
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Ignoring Files and Directories
129
+
130
+ Skip directories or files while scanning:
131
+
132
+ ```bash
133
+ digdep file-tree ./myproject --ignore venv __pycache__ tests
134
+ ```
135
+
136
+ ---
137
+
138
+ ## Redirecting Output
139
+
140
+ Save the generated tree to a file:
141
+
142
+ ```bash
143
+ digdep dep-tree ./myproject > dependencies.txt
144
+ ```
145
+
146
+ ---
147
+
148
+ ## Commands
149
+
150
+ | Command | Description |
151
+ |---------|-------------|
152
+ | `packages` | List all imported packages |
153
+ | `file-tree` | Show the File → Dependency tree |
154
+ | `dep-tree` | Show the Dependency → File tree |
155
+
156
+ Run `digdep <command> --help` for command-specific options.
157
+
158
+ ---
159
+
160
+ ## Using as a Python Library
161
+
162
+ ```python
163
+ from digdep import DepAnalyzer, DepType
164
+
165
+ analyzer = DepAnalyzer()
166
+
167
+ # Ignoring directories
168
+ analyzer.ignore([
169
+ "__pycache__",
170
+ "venv",
171
+ "build",
172
+ "tests"
173
+ ])
174
+
175
+ analyzer.scan("./myproject")
176
+
177
+ # List imported packages
178
+ packages = analyzer.get_packages()
179
+
180
+ # Get the File -> Dependency tree
181
+ filedep_tree = analyzer.get_filedep_tree()
182
+
183
+ # Get the Dependency -> File tree
184
+ depfile_tree = analyzer.get_depfile_tree()
185
+
186
+ ```
187
+
188
+ Filter dependencies by type:
189
+
190
+ ```python
191
+ from digdep import DepAnalyzer, DepType
192
+
193
+ analyzer = DepAnalyzer()
194
+ analyzer.scan("./myproject")
195
+
196
+ # Show only standard library imports
197
+ filedep_tree = analyzer.get_filedep_tree(
198
+ filters=DepType.STDLIB
199
+ )
200
+
201
+ # Show standard library and third-party imports
202
+ depfile_tree = analyzer.get_depfile_tree(
203
+ filters=DepType.STDLIB | DepType.THIRD_PARTY
204
+ )
205
+ ```
206
+
207
+ ---
208
+ ## Roadmap
209
+
210
+ - Local module detection
211
+ - Dependency statistics
212
+ - JSON export
213
+ - Circular dependency detection
214
+ - Unused dependency detection
215
+
216
+ ---
217
+
218
+ ## Requirements
219
+
220
+ - Python 3.11+
221
+
222
+ ---
223
+
224
+ ## License
225
+
226
+ Released under the MIT License.
227
+
228
+ ---
digdep-0.0.3/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # DigDep
2
+
3
+ ![Version](https://img.shields.io/static/v1?label=version&message=v.0.0.3&color=blue)
4
+ ![License](https://img.shields.io/static/v1?label=license&message=MIT&color=green)
5
+ ![Status](https://img.shields.io/badge/status-alpha-yellow.svg)
6
+ ![Open Source](https://img.shields.io/static/v1?label=OpenSource&message=Yes&color=brightgreen)
7
+ ![GitHub issues](https://img.shields.io/github/issues/shine-jayakumar/docdsl)
8
+ ![Last Commit](https://img.shields.io/github/last-commit/shine-jayakumar/docdsl)
9
+
10
+ A lightweight Python dependency analyzer that scans Python projects and visualizes import relationships.
11
+
12
+ ---
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pip install digdep
18
+ ```
19
+ ---
20
+
21
+ ## Quick Start (CLI)
22
+
23
+ List all imported packages:
24
+
25
+ ```bash
26
+ digdep packages ./myproject
27
+ ```
28
+
29
+ Show the File → Dependency tree:
30
+
31
+ ```bash
32
+ digdep file-tree ./myproject
33
+ ```
34
+
35
+ Show the Dependency → File tree:
36
+
37
+ ```bash
38
+ digdep dep-tree ./myproject
39
+ ```
40
+
41
+ ---
42
+
43
+ ## Sample Output
44
+
45
+ ### File → Dependency Tree
46
+
47
+ ```text
48
+ Root (/projects/example)
49
+
50
+ ├── main.py → requests, pathlib
51
+ ├── config.py → json
52
+
53
+ ├── modules/
54
+ │ ├── logger.py → logging
55
+ │ ├── parser.py → re, typing
56
+
57
+ └── utils/
58
+ └── helpers.py → functools
59
+ ```
60
+
61
+ ### Dependency → File Tree
62
+
63
+ ```text
64
+ requests
65
+ ├── main.py
66
+
67
+ re
68
+ ├── modules/
69
+ │ └── parser.py
70
+
71
+ logging
72
+ ├── modules/
73
+ │ └── logger.py
74
+ ```
75
+
76
+ ---
77
+
78
+ ## Filtering
79
+
80
+ Filter dependencies by type.
81
+
82
+ Show only standard library imports:
83
+
84
+ ```bash
85
+ digdep file-tree ./myproject --type stdlib
86
+ ```
87
+
88
+ Show both standard library and third-party imports:
89
+
90
+ ```bash
91
+ digdep file-tree ./myproject --type stdlib,third-party
92
+ ```
93
+
94
+ Show only local imports:
95
+
96
+ ```bash
97
+ digdep file-tree ./myproject --type local
98
+ ```
99
+
100
+ ---
101
+
102
+ ## Ignoring Files and Directories
103
+
104
+ Skip directories or files while scanning:
105
+
106
+ ```bash
107
+ digdep file-tree ./myproject --ignore venv __pycache__ tests
108
+ ```
109
+
110
+ ---
111
+
112
+ ## Redirecting Output
113
+
114
+ Save the generated tree to a file:
115
+
116
+ ```bash
117
+ digdep dep-tree ./myproject > dependencies.txt
118
+ ```
119
+
120
+ ---
121
+
122
+ ## Commands
123
+
124
+ | Command | Description |
125
+ |---------|-------------|
126
+ | `packages` | List all imported packages |
127
+ | `file-tree` | Show the File → Dependency tree |
128
+ | `dep-tree` | Show the Dependency → File tree |
129
+
130
+ Run `digdep <command> --help` for command-specific options.
131
+
132
+ ---
133
+
134
+ ## Using as a Python Library
135
+
136
+ ```python
137
+ from digdep import DepAnalyzer, DepType
138
+
139
+ analyzer = DepAnalyzer()
140
+
141
+ # Ignoring directories
142
+ analyzer.ignore([
143
+ "__pycache__",
144
+ "venv",
145
+ "build",
146
+ "tests"
147
+ ])
148
+
149
+ analyzer.scan("./myproject")
150
+
151
+ # List imported packages
152
+ packages = analyzer.get_packages()
153
+
154
+ # Get the File -> Dependency tree
155
+ filedep_tree = analyzer.get_filedep_tree()
156
+
157
+ # Get the Dependency -> File tree
158
+ depfile_tree = analyzer.get_depfile_tree()
159
+
160
+ ```
161
+
162
+ Filter dependencies by type:
163
+
164
+ ```python
165
+ from digdep import DepAnalyzer, DepType
166
+
167
+ analyzer = DepAnalyzer()
168
+ analyzer.scan("./myproject")
169
+
170
+ # Show only standard library imports
171
+ filedep_tree = analyzer.get_filedep_tree(
172
+ filters=DepType.STDLIB
173
+ )
174
+
175
+ # Show standard library and third-party imports
176
+ depfile_tree = analyzer.get_depfile_tree(
177
+ filters=DepType.STDLIB | DepType.THIRD_PARTY
178
+ )
179
+ ```
180
+
181
+ ---
182
+ ## Roadmap
183
+
184
+ - Local module detection
185
+ - Dependency statistics
186
+ - JSON export
187
+ - Circular dependency detection
188
+ - Unused dependency detection
189
+
190
+ ---
191
+
192
+ ## Requirements
193
+
194
+ - Python 3.11+
195
+
196
+ ---
197
+
198
+ ## License
199
+
200
+ Released under the MIT License.
201
+
202
+ ---
@@ -0,0 +1,12 @@
1
+ """
2
+ Copyright (c) 2026 Shine Jayakumar
3
+ SPDX-License-Identifier: MIT
4
+
5
+ Licensed under the MIT License.
6
+ See the LICENSE file in the project root for the full license text.
7
+ """
8
+
9
+ from .analyzer import DepAnalyzer, DepType
10
+ from ._version import __version__
11
+
12
+
@@ -0,0 +1,13 @@
1
+ """
2
+ Copyright (c) 2026 Shine Jayakumar
3
+ SPDX-License-Identifier: MIT
4
+
5
+ Licensed under the MIT License.
6
+ See the LICENSE file in the project root for the full license text.
7
+
8
+ DigDep version
9
+ """
10
+
11
+ __version__ = "0.0.3"
12
+
13
+
@@ -0,0 +1,228 @@
1
+ """
2
+ Copyright (c) 2026 Shine Jayakumar
3
+ SPDX-License-Identifier: MIT
4
+
5
+ Licensed under the MIT License.
6
+ See the LICENSE file in the project root for the full license text.
7
+
8
+ Core dependency analyzer
9
+ """
10
+
11
+ import ast
12
+ from pathlib import Path
13
+ from rich.console import Console
14
+ from enum import Flag, auto
15
+ import sys
16
+ from .visitors import DependencyVisitor
17
+ from .utils import walkpath
18
+
19
+
20
+ class DepType(Flag):
21
+ NONE = 0
22
+ STDLIB = auto()
23
+ THIRD_PARTY = auto()
24
+ LOCAL = auto()
25
+ UNKNOWN = auto()
26
+ ALL = STDLIB | THIRD_PARTY | LOCAL
27
+
28
+
29
+ class DepAnalyzer:
30
+
31
+ def __init__(self, is_ascii: bool = False) -> None:
32
+ self._root: Path = None
33
+ self._filedep_tree = {}
34
+ self._depfile_tree = {}
35
+ self._dep_type_map: dict[str, DepType] = {}
36
+ self._ignorelist: set[str] = set()
37
+ self._path_dep_map: dict[Path, set[str]] = {}
38
+ self._is_ascii: bool = is_ascii
39
+ self._tree_prefix_char = (
40
+ "├──" if not self._is_ascii else "|__"
41
+ )
42
+ self._console = Console()
43
+
44
+ def ignore(self, ignorelist: list[str]) -> None:
45
+ """Adds files/directories to ignorelist"""
46
+ self._ignorelist = set(ignorelist)
47
+
48
+ def _get_file_deps(self, fpath: str) -> list[str]:
49
+ """Get dependencies in a file"""
50
+ try:
51
+ with open(fpath, "r", encoding="utf-8") as fh:
52
+ source = fh.read()
53
+ tree = ast.parse(source)
54
+ visitor = DependencyVisitor()
55
+ visitor.visit(tree)
56
+ return visitor.packages
57
+ except Exception as ex:
58
+ print(
59
+ (
60
+ f"Failed to read: {fpath}\n"
61
+ f"{ex.__class__.__name__} - {str(ex)}"
62
+ )
63
+ )
64
+ return []
65
+
66
+ def _get_deptype(self, dep: str) -> DepType:
67
+ """Get the dependency type"""
68
+ if dep in sys.stdlib_module_names:
69
+ return DepType.STDLIB
70
+ return DepType.THIRD_PARTY
71
+
72
+ def _update_deptype_map(self, deps: set[str]) -> None:
73
+ """Update dependency in dependency-type mapping"""
74
+ new_deps = deps.difference(self._dep_type_map.keys())
75
+ self._dep_type_map.update({
76
+ dep: self._get_deptype(dep) for dep in new_deps
77
+ })
78
+
79
+ def _reset_vars(self) -> None:
80
+ """Resets variables"""
81
+ self._filedep_tree = {}
82
+ self._depfile_tree = {}
83
+ self._dep_type_map = {}
84
+ self._path_dep_map = {}
85
+
86
+ def scan(self, root: str = ".") -> None:
87
+ """Scans a python file(s) in a directory/sub-directory"""
88
+ self._reset_vars()
89
+ self._root = Path(root)
90
+ for path in walkpath(root, self._ignorelist):
91
+ deps = self._get_file_deps(str(path.resolve()))
92
+ deps = set(deps) if deps else set()
93
+ relpath = path.relative_to(self._root)
94
+ self._path_dep_map[relpath] = deps
95
+ self._update_deptype_map(deps)
96
+
97
+ def get_packages(self, filters: DepType = DepType.ALL) -> tuple[str]:
98
+ deps = self._get_filtered_deps(filters)
99
+ return tuple(deps)
100
+
101
+ def show_packages(self, filters: DepType = DepType.ALL) -> None:
102
+ print("\n".join(dep for dep in self.get_packages(filters)))
103
+
104
+ def _tree_prefix(self, indent: int = 0) -> str:
105
+ """Generates tree prefix with indentation"""
106
+ spaces = " " * indent
107
+ return f"{spaces}{self._tree_prefix_char}"
108
+
109
+ def _vertical_spacer(self, indent: int = 0) -> str:
110
+ """Generates a vertical spacer"""
111
+ spaces = " " * indent
112
+ return f"{spaces}|"
113
+
114
+ def _print(self, text: str) -> None:
115
+ """Coloured print"""
116
+ self._console.print(text)
117
+
118
+ def _gen_filedeps_tree(self) -> None:
119
+ """Generate file dependency tree"""
120
+ if self._filedep_tree:
121
+ return self._filedep_tree
122
+ self._filedep_tree = {"files": []}
123
+ for path, deps in self._path_dep_map.items():
124
+ dirparts = path.parent.parts
125
+ branch = self._filedep_tree
126
+ for part in dirparts:
127
+ branch = branch.setdefault(part, {"files": []})
128
+ branch["files"].append((path.name, deps))
129
+
130
+ def _gen_depfiles_tree(self) -> None:
131
+ """Generate dependency file tree"""
132
+ if self._depfile_tree:
133
+ return self._depfile_tree
134
+ self._depfile_tree = {}
135
+ for path, deps in self._path_dep_map.items():
136
+ dirparts = path.parent.parts
137
+ for dep in deps:
138
+ branch = self._depfile_tree.setdefault(dep, {"files": []})
139
+ for part in dirparts:
140
+ branch = branch.setdefault(part, {"files": []})
141
+ branch["files"].append(path.name)
142
+
143
+ def _get_filtered_deps(self, filters: DepType) -> set[str]:
144
+ """Filter dependencies by type"""
145
+ return {
146
+ dep
147
+ for dep, deptype in self._dep_type_map.items()
148
+ if filters & deptype
149
+ }
150
+
151
+ def get_filedep_tree(self, filters: DepType = DepType.ALL) -> dict:
152
+ """Get the file-dependency tree"""
153
+ self._gen_filedeps_tree()
154
+ return self._filedep_tree
155
+
156
+ def file_dependency_tree(self, filters: DepType = DepType.ALL) -> None:
157
+ """Show file and dependencies"""
158
+ self._gen_filedeps_tree()
159
+ relevant_deps = (
160
+ self._get_filtered_deps(filters) if filters else set()
161
+ )
162
+ def showdep(branch: dict, indent=0):
163
+ files = branch.get("files", [])
164
+ tree_prefix = self._tree_prefix(indent)
165
+ maxwidth = (
166
+ max(len(file) for file, _ in files) if files else 0
167
+ )
168
+ for file, deps in files:
169
+ deps = deps.intersection(relevant_deps)
170
+ deps = ", ".join(sorted(deps))
171
+ deps = f" → [bold cyan]{deps}[/bold cyan]" if deps else ""
172
+ self._print(f"{tree_prefix} {file:<{maxwidth}}{deps}")
173
+
174
+ dirs = {k:v for k,v in branch.items() if isinstance(v, dict)}
175
+ for _dir, val in dirs.items():
176
+ print(self._vertical_spacer(indent))
177
+ self._print(f"{tree_prefix} [blue]{_dir}[/blue]/")
178
+ showdep(val, indent + 4)
179
+
180
+ self._print(f"[bold magenta]Root ({self._root})[/bold magenta]")
181
+ showdep(self._filedep_tree)
182
+
183
+ def get_depfile_tree(self, filters: DepType = DepType.ALL) -> dict:
184
+ """Get the dependency-file tree"""
185
+ self._gen_depfiles_tree()
186
+ return self._depfile_tree
187
+
188
+ def dependency_file_tree(self, filters: DepType = DepType.ALL) -> None:
189
+ """Show dependency and files"""
190
+ self._gen_depfiles_tree()
191
+ relevant_deps = (
192
+ self._get_filtered_deps(filters) if filters else set()
193
+ )
194
+ def showfiles(branch: dict, indent=0):
195
+ files = branch.get("files", [])
196
+ tree_prefix = self._tree_prefix(indent)
197
+ for file in files:
198
+ print(f"{tree_prefix} {file}")
199
+
200
+ dirs = {k:v for k,v in branch.items() if isinstance(v, dict)}
201
+ for _dir, val in dirs.items():
202
+ print(self._vertical_spacer(indent))
203
+ self._print(f"{tree_prefix} [blue]{_dir}[/blue]/")
204
+ showfiles(val, indent + 4)
205
+
206
+ filtered_deps = (
207
+ set(self._depfile_tree.keys()).intersection(relevant_deps)
208
+ )
209
+ for dep in filtered_deps:
210
+ deptree = self._depfile_tree.get(dep)
211
+ self._print(f"[bold cyan]{dep}[/bold cyan]")
212
+ showfiles(deptree)
213
+ print("\n")
214
+
215
+
216
+ if __name__ == "__main__":
217
+ pass
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+