Skip to content

Commit

Permalink
add cmd.parse_deps to parse dependencies of a project directory, an…
Browse files Browse the repository at this point in the history
…d find circular dependencies.
  • Loading branch information
lidong committed Jan 11, 2025
1 parent 4161e62 commit f278c4a
Show file tree
Hide file tree
Showing 5 changed files with 363 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 1.1.9 (2024-12-11)
1. add `snippets.sql.SqliteSQL` as Sqlite SQL generator
2. add `cmd.parse_deps` to parse dependencies of a project directory, and find circular dependencies.

### 1.1.8 (2024-12-11)
1. add `utils.i2b` and `utils.b2i`, integer and fixed-length byte strings conversion.
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,19 @@ print(morebuiltins.__file__)
11.5 `handle_tk2` - Function to tkinter UI.


## 12. morebuiltins.snippets.event
## 12. morebuiltins.cmd.parse_deps

12.1 `EventTemplate` - Event template for event sourcing
12.1 `parse_deps` - Parse dependencies of a project directory.


## 13. morebuiltins.snippets.sql
## 13. morebuiltins.snippets.event

13.1 `SqliteSQL` - Sqlite SQL generator
13.1 `EventTemplate` - Event template for event sourcing


## 14. morebuiltins.snippets.sql

14.1 `SqliteSQL` - Sqlite SQL generator


<!-- end -->
Expand Down
112 changes: 108 additions & 4 deletions doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -2236,11 +2236,115 @@
---


## 12. morebuiltins.snippets.event
## 12. morebuiltins.cmd.parse_deps



12.1 `EventTemplate` - Event template for event sourcing
12.1 `parse_deps` - Parse dependencies of a project directory.


```python

Args:
project_dir (str): Path to the project directory.
ignore_stds (bool, optional): Whether to ignore dependencies from the standard library. Defaults to True.
format_path (bool, optional): Whether to format the paths. Defaults to True.
pattern_list (tuple, optional): List of patterns to match files. Defaults to ("*.py",).
Returns:
dict: A dictionary containing the project directory, circular dependencies, and dependencies.

Demo::

import json
import multiprocessing
from pathlib import Path

project_dir = Path(multiprocessing.__file__).parent
result = parse_deps(
project_dir,
ignore_stds=True,
format_path=True,
pattern_list=("*.py",),
)
dependencies = sorted(
result["dependencies"].items(),
key=lambda i: (len(i[1]), i[0]),
reverse=True,
)
print("project_dir:", project_dir.as_posix(), flush=True)
print("circular_dependency:", result["circular_dependency"], flush=True)
for source, deps in dependencies:
print(source, f"({len(deps)})", flush=True)
for i in deps:
print("\t", i, flush=True)
# project_dir: D:/python311/Lib/multiprocessing
# circular_dependency: [('./connection.py', './context.py'), ('./context.py', './forkserver.py'), ('./context.py', './managers.py'), ('./context.py', './popen_forkserver.py'), ('./context.py', './popen_spawn_posix.py'), ('./context.py', './popen_spawn_win32.py'), ('./context.py', './sharedctypes.py'), ('./context.py', './spawn.py'), ('./dummy/__init__.py', './pool.py')]
# ./context.py (13)
# ./connection.py
# ./forkserver.py
# ./managers.py
# ./pool.py
# ./popen_fork.py
# ./popen_forkserver.py
# ./popen_spawn_posix.py
# ./popen_spawn_win32.py
# ./queues.py
# ./sharedctypes.py
# ./spawn.py
# ./synchronize.py
# ./util.py
# ./synchronize.py (2)
# ./heap.py
# ./resource_tracker.py
# ./resource_sharer.py (2)
# ./connection.py
# ./context.py
# ./queues.py (2)
# ./synchronize.py
# ./util.py
# ./pool.py (2)
# ./connection.py
# ./dummy/__init__.py
# ./dummy/__init__.py (2)
# ./dummy/connection.py
# ./pool.py
# ./util.py (1)
# test
# ./spawn.py (1)
# ./context.py
# ./sharedctypes.py (1)
# ./context.py
# ./reduction.py (1)
# ./resource_sharer.py
# ./process.py (1)
# ./context.py
# ./popen_spawn_win32.py (1)
# ./context.py
# ./popen_spawn_posix.py (1)
# ./context.py
# ./popen_forkserver.py (1)
# ./context.py
# ./managers.py (1)
# ./context.py
# ./heap.py (1)
# ./context.py
# ./forkserver.py (1)
# ./context.py
# ./connection.py (1)
# ./context.py


```


---


## 13. morebuiltins.snippets.event



13.1 `EventTemplate` - Event template for event sourcing



Expand All @@ -2249,11 +2353,11 @@
---


## 13. morebuiltins.snippets.sql
## 14. morebuiltins.snippets.sql



13.1 `SqliteSQL` - Sqlite SQL generator
14.1 `SqliteSQL` - Sqlite SQL generator



Expand Down
1 change: 1 addition & 0 deletions morebuiltins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"morebuiltins.cmd.log_server",
"morebuiltins.cmd.proxy_checker",
"morebuiltins.cmd.ui",
"morebuiltins.cmd.parse_deps",
"morebuiltins.snippets.event",
"morebuiltins.snippets.sql",
]
Loading

0 comments on commit f278c4a

Please sign in to comment.