获取Django项目使用的python包的列表 [英] Get a list of python packages used by a Django Project
问题描述
我有看过snakefood和这个问题,但在django环境中似乎都没有很好地发挥。
理想情况下,我正在寻找一个可以从python shell或bash中执行的命令,列出所有不支持django本机的pypy支持的依赖项。
这不是一个完整的答案,但希望它会成为一个明智的起点。
从我可以看出,django项目的依赖关系(除了django本身及其依赖项 *
)包括:
- 您的django项目导入的模块
- 您的项目通过
settings.INSTALLED_APPS
(及其依赖项)
#1项目导入的模块
您可以使用 snakefood 发现这一点。 p>
#2通过 settings.INSTALLED_APPS加载的应用程序
运行以下脚本应该给出 INSTALLED_APPS
中列出的应用程序的路径:
#!/ usr / bin / env python
从设置导入INSTALLED_APPS
从django.utils.importlib import import_module
import os
app_names =(x for x in INSTALLED_APPS如果不是x.startswith('django'))
app_paths =(os.path.dirname(os.path .abspath(import_module(x).__ file__))for x in app_names
print\\\
.join(x for app in app_paths if not x.startswith(os.getcwd()))
然后,您可以将其传递给 snakefood
以发现他们依赖关系。
*
要彻底,应该可以从设置
中发现各种后端(db / cache / auth / etc),并将相关模块包含在您的依赖关系列表中。
Is there any easy way to get a list of python packages used by a Django project?
I've looked at snakefood and this question, but neither seem to play nicely within the django environment.
Ideally I'm looking for a command I can execute from the python shell or from bash to list all of the pypy supported dependencies that aren't native to django.
This isn't a complete answer but hopefully it'll make a sensible starting point.
From what I can tell, the dependencies of a django project (apart from django itself and its dependencies*
) consists of:
- Modules imported by your django project
- Apps loaded by your project via
settings.INSTALLED_APPS
(and their dependencies)
#1 Modules imported by your project
You can probably discover this using snakefood.
#2 Apps loaded via settings.INSTALLED_APPS
Running the following script should give the path to apps listed in INSTALLED_APPS
:
#!/usr/bin/env python
from settings import INSTALLED_APPS
from django.utils.importlib import import_module
import os
app_names = (x for x in INSTALLED_APPS if not x.startswith('django'))
app_paths = (os.path.dirname(os.path.abspath(import_module(x).__file__)) for x in app_names)
print "\n".join(x for x in app_paths if not x.startswith(os.getcwd()))
You can then pass this on to snakefood
to discover their dependencies.
*
To be thorough, it should be possible to discover the various backends (db/cache/auth/etc.) from settings
and include the associated modules into your list of dependencies.
这篇关于获取Django项目使用的python包的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!