-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored to make IPython/Djnango imports optional
- Loading branch information
Aidan Houlihan
committed
Sep 29, 2019
1 parent
ac9830d
commit e0b3025
Showing
7 changed files
with
111 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,6 @@ venv.bak/ | |
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
# VS Code | ||
.vscode/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from datetime import datetime | ||
|
||
from humanize import naturaldelta | ||
|
||
## | ||
# Defined hook classes for framework independent integrations. | ||
# At the moment only supports Django, but implementers can substitute | ||
# their own mixins for different use cases. | ||
## | ||
|
||
|
||
class BaseHookMixin: | ||
""" | ||
Base mixin supporting two break out methods for montiroing code execution | ||
within the selected context. Can be overridden depending on hook to provide | ||
enhanced functionality. | ||
""" | ||
started = None | ||
time_take = None | ||
|
||
def enter_section_hook(self): | ||
self.started = datetime.now() | ||
return | ||
|
||
def exit_section_hook(self, default_kwargs): | ||
self.time_taken = naturaldelta(datetime.now() - self.started) | ||
|
||
default_kwargs['title'] = ( | ||
f'Excecuted context in {self.time_taken}.' | ||
) | ||
|
||
return default_kwargs | ||
|
||
## | ||
# Set django as default hook if available. | ||
# Use a basic generic mixin if not. | ||
## | ||
|
||
|
||
try: | ||
from django import db | ||
|
||
class DjangoHookMixin(BaseHookMixin): | ||
""" | ||
Django specific hook, enhances the end flame graph with an output of | ||
total database queries. | ||
""" | ||
|
||
def enter_section_hook(self): | ||
super().enter_section_hook() | ||
db.reset_queries() | ||
|
||
def exit_section_hook(self, default_kwargs): | ||
super().exit_section_hook(default_kwargs) | ||
num_sql_queries = len(db.connection.queries) | ||
|
||
default_kwargs['title'] = ( | ||
f'Executed context in {self.time_taken}. ' | ||
f'Made {num_sql_queries} SQL queries.' | ||
) | ||
|
||
return default_kwargs | ||
|
||
SetHookMixin = DjangoHookMixin | ||
|
||
except ImportError: | ||
SetHookMixin = BaseHookMixin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,17 @@ | |
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) | ||
|
||
setup( | ||
name = 'publons-flame', | ||
version = '0.1', | ||
packages = ['publons_flame'], | ||
include_package_data = True, | ||
license = 'MIT License', | ||
description = 'A small Django and IPython compatible application for benchmarking database and IO heavy work.', | ||
long_description = README, | ||
url = 'https://github.com/pulbons/publons-flame', | ||
author = 'Matthew Betts, Aidan Houlihan', | ||
author_email = '[email protected]', | ||
classifiers =[ | ||
name='publons-flame', | ||
version='0.1', | ||
packages=['publons_flame'], | ||
include_package_data=True, | ||
license='MIT License', | ||
description='A small Django and IPython compatible application for benchmarking database and IO heavy work.', | ||
long_description=README, | ||
url='https://github.com/pulbons/publons-flame', | ||
author='Matthew Betts, Aidan Houlihan', | ||
author_email='[email protected]', | ||
classifiers=[ | ||
'Environment :: Web Environment', | ||
'Framework :: Django', | ||
'Intended Audience :: Developers', | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.