Skip to content

Commit

Permalink
Update for Python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
transientlunatic committed Dec 15, 2022
1 parent e6be6ab commit 5f15b8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
26 changes: 18 additions & 8 deletions otter/otter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Otter():
reports for long-running or complex jobs where and iPython
notebook would be an impractical way of presenting information.
"""
def __init__(self, filename, config_file=None, **kwargs):
def __init__(self, filename, theme_location=None, config_file=None, **kwargs):
"""
An Otter report is created by this class.
Expand Down Expand Up @@ -50,15 +50,25 @@ def __init__(self, filename, config_file=None, **kwargs):
self.meta[option] = config.get('meta', option)
for option in kwargs.items():
self.meta[option[0]] = option[1]

try:
theme = config.get("theme", "location")
except:
print("Cannot find theme in the config file. Using the default theme.")

if theme_location:
theme = theme_location

elif config.has_option("theme", "name"):
try:
import importlib
theme = importlib.import_module(config.get("theme", "name"))
except:
pass
else:
try:
theme = resource_filename(__name__, "themes/default/")
theme = config.get("theme", "location")
except:
print("No theme files found.")
print("Cannot find theme in the config file. Using the default theme.")
try:
theme = resource_filename(__name__, "themes/default/")
except:
print("No theme files found.")

self.env = Environment(loader=FileSystemLoader(theme))

Expand Down
2 changes: 1 addition & 1 deletion otter/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, figure, filename=None, dpi=300):
if filename==None:
figure.savefig(self.image, dpi=dpi)

self.bitstring = base64.encodestring(self.image.getvalue())
self.bitstring = base64.encodebytes(self.image.getvalue())

def __repr__(self):
html_str= r"""<img src="data:image/png;base64,{}" style="max-width: 100%;" class="img-responsive"/>""".format(self.bitstring.decode("utf-8"))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
description="The simple HTML report generator for Python jobs.",
long_description=readme + '\n\n' + history,
author="Daniel Williams",
author_email='daniel.williams@gla.ac.uk',
author_email='daniel.williams@glasgow.ac.uk',
url='https://github.com/transientlunatic/otter',
packages=[
'otter',
Expand Down

0 comments on commit 5f15b8b

Please sign in to comment.