Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated pkg_resources with stdlib #239

Merged
merged 1 commit into from Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 4 additions & 15 deletions src/flask_debugtoolbar/panels/versions.py
Expand Up @@ -17,16 +17,6 @@
_ = lambda x: x


def relpath(location, python_lib):
location = os.path.normpath(location)
relative = os.path.relpath(location, python_lib)
if relative == os.path.curdir:
return ''
elif relative.startswith(os.path.pardir):
return location
return relative


class VersionDebugPanel(DebugPanel):
"""
Panel that displays the Flask version.
Expand All @@ -48,15 +38,14 @@ def title(self):

def content(self):
try:
import pkg_resources
import importlib.metadata
except ImportError:
packages = []
else:
packages = sorted(pkg_resources.working_set,
key=lambda p: p.project_name.lower())
packages_metadata = [p.metadata for p in importlib.metadata.distributions()]
packages = sorted(packages_metadata, key=lambda p: p['Name'].lower())

return self.render('panels/versions.html', {
'packages': packages,
'python_lib': os.path.normpath(get_path('platlib')),
'relpath': relpath,
'python_lib_dir': os.path.normpath(get_path('platlib')),
})
18 changes: 10 additions & 8 deletions src/flask_debugtoolbar/templates/panels/versions.html
@@ -1,32 +1,34 @@
<h4>Installed Packages</h4>

<p>
Installation paths relative to:
Current Site Packages Directory:
</p>
<pre>
{{ python_lib }}
{{ python_lib_dir }}
</pre>

<table>
<thead>
<tr>
<th>Package</th>
<th>Version</th>
<th>Installed Path</th>
<th>Homepage</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
{% for package in packages %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ package.project_name }}</td>
<td>{{ package.version }}</td>
<td>{{ relpath(package.location, python_lib) }}</td>
<td>{{ package.get('Name') }}</td>
<td>{{ package.get('Version') }}</td>
<td>{{ package.get('Home-page') }}</td>
<td>{{ package.get('Summary') }}</td>
</tr>
{% else %}
<tr>
<td>setuptools</td>
<td>Python 3.8</td>
<td>NOT INSTALLED</td>
<td>Install setuptools to display installed packages and version information</td>
<td>This panel requires Python >= 3.8 in order to display installed packages and version information.</td>
</tr>
{% endfor %}
</tbody>
Expand Down