Skip to content

Commit

Permalink
fix: pyinstrument dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Aug 11, 2021
1 parent ccfc95f commit 820bc34
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ combine_as_imports = true
include_trailing_comma = true
line_length = 88
known_first_party = superset
known_third_party =alembic,apispec,backoff,bleach,cachelib,celery,click,colorama,cron_descriptor,croniter,cryptography,dateutil,deprecation,flask,flask_appbuilder,flask_babel,flask_caching,flask_compress,flask_jwt_extended,flask_login,flask_migrate,flask_sqlalchemy,flask_talisman,flask_testing,flask_wtf,freezegun,geohash,geopy,graphlib,holidays,humanize,isodate,jinja2,jwt,markdown,markupsafe,marshmallow,marshmallow_enum,msgpack,numpy,pandas,parameterized,parsedatetime,pgsanity,pkg_resources,polyline,prison,progress,pyarrow,pyhive,pyinstrument,pyparsing,pytest,pytest_mock,pytz,redis,requests,selenium,setuptools,simplejson,slack,sqlalchemy,sqlalchemy_utils,sqlparse,tabulate,typing_extensions,werkzeug,wtforms,wtforms_json,yaml
known_third_party =alembic,apispec,backoff,bleach,cachelib,celery,click,colorama,cron_descriptor,croniter,cryptography,dateutil,deprecation,flask,flask_appbuilder,flask_babel,flask_caching,flask_compress,flask_jwt_extended,flask_login,flask_migrate,flask_sqlalchemy,flask_talisman,flask_testing,flask_wtf,freezegun,geohash,geopy,graphlib,holidays,humanize,isodate,jinja2,jwt,markdown,markupsafe,marshmallow,marshmallow_enum,msgpack,numpy,pandas,parameterized,parsedatetime,pgsanity,pkg_resources,polyline,prison,progress,pyarrow,pyhive,pyparsing,pytest,pytest_mock,pytz,redis,requests,selenium,setuptools,simplejson,slack,sqlalchemy,sqlalchemy_utils,sqlparse,tabulate,typing_extensions,werkzeug,wtforms,wtforms_json,yaml
multi_line_output = 3
order_by_type = false

Expand Down
9 changes: 8 additions & 1 deletion superset/utils/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
from typing import Any, Callable
from unittest import mock

from pyinstrument import Profiler
from werkzeug.wrappers import Request, Response

try:
from pyinstrument import Profiler
except ModuleNotFoundError:
Profiler = None


class SupersetProfiler:
"""
Expand All @@ -41,6 +45,9 @@ def __call__(self, request: Request) -> Response:
if request.args.get("_instrument") != "1":
return Response.from_app(self.app, request.environ)

if Profiler is None:
raise Exception("The module pyinstrument is not installed.")

profiler = Profiler(interval=self.interval)

# call original request
Expand Down

0 comments on commit 820bc34

Please sign in to comment.