mirror of
https://github.com/pallets-eco/flask-debugtoolbar.git
synced 2026-01-07 14:09:41 -06:00
Display installed packages and versions in Versions panel (requires Yolk)
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
from distutils.sysconfig import get_python_lib
|
||||
import sys
|
||||
|
||||
from flask import __version__ as flask_version
|
||||
from flask_debugtoolbar.panels import DebugPanel
|
||||
|
||||
@@ -8,7 +11,7 @@ class VersionDebugPanel(DebugPanel):
|
||||
Panel that displays the Flask version.
|
||||
"""
|
||||
name = 'Version'
|
||||
has_content = False
|
||||
has_content = True
|
||||
|
||||
def nav_title(self):
|
||||
return _('Versions')
|
||||
@@ -23,6 +26,27 @@ class VersionDebugPanel(DebugPanel):
|
||||
return _('Versions')
|
||||
|
||||
def content(self):
|
||||
return None
|
||||
try:
|
||||
from yolk import yolklib
|
||||
except ImportError:
|
||||
"Requires yolk to provide package information"
|
||||
context = self.context.copy()
|
||||
context.update({
|
||||
'packages': [],
|
||||
'paths': sys.path
|
||||
})
|
||||
else:
|
||||
dist = yolklib.Distributions()
|
||||
active_packages = dist.get_packages('active')
|
||||
_pkgs = dict([(p.project_name, p) for p in active_packages])
|
||||
packages = [_pkgs[key] for key in sorted(_pkgs.iterkeys())]
|
||||
for package in packages:
|
||||
package.develop_mode = not (package.location.lower().startswith(get_python_lib().lower()))
|
||||
|
||||
context = self.context.copy()
|
||||
context.update({
|
||||
'packages': packages,
|
||||
'paths': sys.path,
|
||||
})
|
||||
|
||||
return self.render('panels/versions.html', context)
|
||||
28
flask_debugtoolbar/templates/panels/versions.html
Normal file
28
flask_debugtoolbar/templates/panels/versions.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<h4>Installed Packages</h4>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Package</th>
|
||||
<th>Version</th>
|
||||
<th>Develop?</th>
|
||||
<th>Installed Path</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for package in packages %}
|
||||
<tr class="{{ loop.cycle('flDebugOdd' 'flDebugEven') }}">
|
||||
<td>{{ package.project_name }}</td>
|
||||
<td>{{ package.version }}</td>
|
||||
<td>{{ package.develop_mode }}</td>
|
||||
<td>{{ package.location }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td>yolk</td>
|
||||
<td>NOT INSTALLED</td>
|
||||
<td> </td>
|
||||
<td>Install Yolk to display installed packages and version information</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
Reference in New Issue
Block a user