收集源代码的模块依赖关系
项目描述
模块依赖关系
简要概述
module_dependencies
Python模块允许您收集源代码中特定模块的依赖关系。它分为两个主要部分:Module
和Source
。
前者,Module
,支持将模块名称映射到开源存储库中该模块的使用情况的功能。当我们感兴趣的是确定Python模块中哪些部分使用最频繁时,这非常有用。例如
from module_dependencies import Module
from pprint import pprint
# Attempt to find 1000 imports of the "nltk" module
# in both Python files and Jupyter Notebooks each
module = Module("nltk", count="1000")
print(module.usage())
module.plot()
此程序输出
[2022-01-03 14:14:39,127] [module_dependencies.module.session] [INFO ] - Fetching Python source code containing imports of `nltk`...
[2022-01-03 14:14:42,824] [module_dependencies.module.session] [INFO ] - Fetched Python source code containing imports of `nltk` (status code 200)
[2022-01-03 14:14:42,825] [module_dependencies.module.session] [INFO ] - Parsing 6,830,859 bytes of Python source code as JSON...
[2022-01-03 14:14:42,865] [module_dependencies.module.session] [INFO ] - Parsed 6,830,859 bytes of Python source code as JSON...
[2022-01-03 14:14:42,866] [module_dependencies.module.session] [INFO ] - Extracting dependencies of 725 files of Python source code...
Parsing Files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 725/725 [00:02<00:00, 258.48files/s]
[2022-01-03 14:14:45,702] [module_dependencies.module.session] [INFO ] - Extracted dependencies of 725 files of Python source code.
[2022-01-03 14:14:45,703] [module_dependencies.module.session] [INFO ] - Fetching Jupyter Notebook source code containing imports of `nltk`...
[2022-01-03 14:14:48,726] [module_dependencies.module.session] [INFO ] - Fetched Jupyter Notebook source code containing imports of `nltk` (status code 200)
[2022-01-03 14:14:48,726] [module_dependencies.module.session] [INFO ] - Parsing 25,713,281 bytes of Jupyter Notebook source code as JSON...
[2022-01-03 14:14:48,886] [module_dependencies.module.session] [INFO ] - Parsed 25,713,281 bytes of Jupyter Notebook source code as JSON...
[2022-01-03 14:14:48,888] [module_dependencies.module.session] [INFO ] - Extracting dependencies of 495 files of Jupyter Notebook source code...
Parsing Files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 495/495 [00:02<00:00, 167.09files/s]
[2022-01-03 14:14:51,851] [module_dependencies.module.session] [INFO ] - Extracted dependencies of 495 files of Jupyter Notebook source code.
[('nltk.tokenize.word_tokenize', 327),
('nltk.download', 298),
('nltk.corpus.stopwords.words', 257),
('nltk.tokenize.sent_tokenize', 126),
('nltk.stem.porter.PorterStemmer', 115),
('nltk.stem.wordnet.WordNetLemmatizer', 99),
('nltk.tag.pos_tag', 75),
('nltk.stem.snowball.SnowballStemmer', 48),
('nltk.data.path.append', 42),
('nltk.probability.FreqDist', 42),
('nltk.tokenize.RegexpTokenizer', 42),
('nltk.tokenize.TweetTokenizer', 35),
('nltk.corpus.wordnet.synsets', 33),
('nltk.data.load', 32),
('nltk.translate.bleu_score.corpus_bleu', 29)]
然后打开以下图表的交互式版本:
(注意,真正的图表 是交互式的,但这个GitHub的副本只是一个png文件)
使用Module
类提供的方法,可以轻松地看到哪些代码部分经常被使用,允许您优先考虑这些部分,而不是很少使用的部分。
module_dependencies
还提供了Source
,它实现了将Python源代码映射到该文件中的依赖关系和导入的功能。例如
from module_dependencies import Source
from pprint import pprint
# This creates a Source instance for this file itself
src = Source.from_file(__file__)
pprint(src.dependencies())
pprint(src.imports())
此程序输出
['module_dependencies.Source.from_file', 'pprint.pprint']
['module_dependencies', 'pprint']
文档
更详细的文档,包括示例和API参考,可以在在线文档中找到。
安装
module_dependencies
可以通过pip直接安装。建议在安装之前设置虚拟环境,尽管这不是强制性的。
安装module_dependencies
的命令是
pip install module_dependencies
注意module_dependencies
需要Python 3.7及以上版本。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
module_dependencies-0.2.5.tar.gz (21.4 kB 查看哈希值)
构建分发
关闭
module_dependencies-0.2.5.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b598699bc2c17a156b9f17eb1001af64021d337aa71d82c010574f04d92f4f7f |
|
MD5 | e33c0d69f5355f9126ea8487d24ee539 |
|
BLAKE2b-256 | 04718d3b3501c4951cf39732ec106f9f90d753de076c0026ef1c4bf17726dbd5 |
关闭
module_dependencies-0.2.5-py2.py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a2530f5f7a4234708ff52b6f331e66c700a4c0fa9dead111d7b142acbd17d641 |
|
MD5 | 17769ffb6fa1474f94646e927943cf7e |
|
BLAKE2b-256 | a5928b58bb0d90460b130ec5812836d01a7b86cd545f747acd85b309d200e3a3 |