Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
macnewbold authored Apr 18, 2024
2 parents 05f2343 + 7012193 commit b139c60
Show file tree
Hide file tree
Showing 15 changed files with 14,698 additions and 1,087 deletions.
6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

Expand Down
10 changes: 9 additions & 1 deletion src/flask_debugtoolbar/panels/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
else:
try:
from flask_sqlalchemy.record_queries import get_recorded_queries
debug_enables_record_queries = False
except ImportError:
# For flask_sqlalchemy < 3.0.0
from flask_sqlalchemy import get_debug_queries as get_recorded_queries

# flask_sqlalchemy < 3.0.0 automatically enabled
# SQLALCHEMY_RECORD_QUERIES in debug or test mode
debug_enables_record_queries = True

location_property = 'context'
else:
location_property = 'location'
Expand Down Expand Up @@ -62,7 +67,10 @@ def extension_used():


def recording_enabled():
return (current_app.debug or current_app.config.get('SQLALCHEMY_RECORD_QUERIES'))
return (
(debug_enables_record_queries and current_app.debug) or
current_app.config.get('SQLALCHEMY_RECORD_QUERIES')
)


def is_available():
Expand Down
31 changes: 15 additions & 16 deletions src/flask_debugtoolbar/panels/versions.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import os
from distutils.sysconfig import get_python_lib
from sysconfig import get_path

from flask import __version__ as flask_version
from flask_debugtoolbar.panels import DebugPanel

_ = lambda x: x
try:
# Python 3.8+
from importlib.metadata import version

flask_version = version('flask')

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
except ImportError:
import pkg_resources

flask_version = pkg_resources.get_distribution('flask').version

_ = lambda x: x


class VersionDebugPanel(DebugPanel):
Expand All @@ -38,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_python_lib()),
'relpath': relpath,
'python_lib_dir': os.path.normpath(get_path('platlib')),
})
Loading

0 comments on commit b139c60

Please sign in to comment.