获取Django项目使用的python包的列表 [英] Get a list of python packages used by a Django Project

查看:92
本文介绍了获取Django项目使用的python包的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有看过snakefood和这个问题,但在django环境中似乎都没有很好地发挥。



理想情况下,我正在寻找一个可以从python shell或bash中执行的命令,列出所有不支持django本机的pypy支持的依赖项。

解决方案

这不是一个完整的答案,但希望它会成为一个明智的起点。



从我可以看出,django项目的依赖关系(除了django本身及其依赖项 * )包括:


  1. 您的django项目导入的模块

  2. 您的项目通过 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:

  1. Modules imported by your django project
  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆