扫描python项目以查找所有已安装的第三方pip库,并生成基于requirements.txt的输出。
pip-module-scanner的Python项目详细描述
PIP模块扫描仪
扫描python项目以查找所有已安装的使用的第三方pip库,并生成基于requirements.txt的输出。
安装
安装扫描仪很简单,可以克隆存储库并运行脚本,也可以通过pip安装,如下所示:
$ pip install pip-module-scanner
用法
使用扫描仪非常简单。打开一个终端,导航到你的项目文件夹,运行脚本,看着魔术发生在你眼前。示例:
$ cd ~/projects/my-awesome-project/ $ pip-module-scanner foo==1.0.0 bar==2.1.0 baz==0.0.1
指定自定义路径
可以使用-p
或--path
参数指定要在其中运行脚本的自定义路径。示例:
$ pip-module-scanner --path ~/projects/my-awesome-project/ foo==1.0.0 bar==2.1.0 baz==0.0.1
将输出写入文件
可以使用-o
或--out
参数将脚本的输出写入文件。示例:
$ cd ~/projects/my-awesome-project/ $ pip-module-scanner -o requirements.txt $ cat requirements.txt foo==1.0.0 bar==2.1.0 baz==0.0.1
在项目中集成代码
您可以很容易地将scanner代码集成到您自己的项目中,这样您就可以自己获得scanner的输出,或者修改类以满足您自己的需要。为此,您可以这样使用:
frompip_module_scanner.scannerimportScannerscanner=Scanner()scanner.run()# do whatever you want with the results here# example:forlibinscanner.libraries_found:print("Found module %s at version %s"%(lib.key,lib.version))
指定路径的工作方式与此类似,请确保同时导入ScannerException
,因为它将检查您指定的路径是否为实际路径:
frompip_module_scanner.scannerimportScanner,ScannerExceptiontry:scanner=Scanner(path="~/projects/my-awesome-project/")scanner.run()# do whatever you want with the results here# example:forlibinscanner.libraries_found:print("Found module %s at version %s"%(lib.key,lib.version))exceptScannerExceptionase:print("Error: %s"%str(e))
对于那些喜欢一行程序的人(像我一样),你也可以用这个漂亮的小程序获得所有的库(我很体贴)
frompip_module_scanner.scannerimportScannerlibs=Scanner().run().libraries_found# Isn't it beautiful?
类定义
pip_module_scanner.scanner.scanner([string path[,string output]])
Method | Argument | Type | Required | Description |
---|---|---|---|---|
__init__ | path | string | no | Directory to recursively scan through, defaults to current working directory. |
output | string | no | Output path to write the resutlts from ^{ | |
run | Runs the scan, output will be stored in ^{ | |||
output | Writes the output to the console or a path specified in the constructor |
Property | Type | Description |
---|---|---|
libraries_found | list<pip._vendor.pkg_resources.EggInfoDistribution> | List of all found pip libraries in your project, result from ^{ |
许可证
麻省理工学院许可证
版权所有(c)2016 Luke Paris
兹免费准许任何人取得副本 本软件和相关文档文件(“软件”)的 在软件中不受限制,包括但不限于 使用、复制、修改、合并、发布、分发、再授权和/或出售 软件的副本,并允许软件的用户 在满足以下条件的情况下,可以这样做:
上述版权公告及本许可公告须包括在 软件的拷贝或大部分。
本软件按“原样”提供,无任何形式的保证,明示或 默示的,包括但不限于适销性保证, 适合特定目的和不侵权。在任何情况下 作者或版权所有者应对任何索赔、损害或其他 责任,无论是在合同诉讼、侵权诉讼或其他诉讼中, 不属于或与本软件有关,或使用或与本软件的其他交易有关。 软件。