Skip to content

Commit

Permalink
trailing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
parmentelat committed Sep 17, 2020
1 parent 32e037d commit 957ffa7
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 168 deletions.
16 changes: 8 additions & 8 deletions nbautoeval/callrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class Call:
def __init__(self, function, args: ArgsTupleDict):
self.function = function
self.args = args


#
class CallRenderer:

def __init__(self, *,
is_code=True, show_function=True, prefix="", postfix="",
def __init__(self, *,
is_code=True, show_function=True, prefix="", postfix="",
max_width=0, css_properties=None):

self.is_code = is_code
Expand All @@ -33,7 +33,7 @@ def __repr__(self):
if self.prefix: result += f" pre={self.prefix}"
if self.postfix: result += f" post={self.postfix}"
result += ">"
return result
return result


def visible_function_name(self, call):
Expand All @@ -43,7 +43,7 @@ def visible_function_name(self, call):
if function_name is True:
function_name = call.function.__name__
return function_name


def render(self, call: Call):
text = ', '.join(call.args.tokens())
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(self, width=80, indent=2, compact=True, *args, **kwds):
self.compact = compact
super().__init__(*args, **kwds)


def render(self, call: Call):
# try to render with no width limit, if it fits it's OK
raw_content = super().render(call)
Expand Down Expand Up @@ -127,7 +127,7 @@ def pretty_slice(generator_args):
else:
return f"iters →{end}/{step}"
return f"ERROR: unknown islice {generator_args.islice}"

# by design this should be called on Call objects
# whose Args instance is a GeneratorArgs
def render(self, generator_call):
Expand All @@ -138,4 +138,4 @@ def render(self, generator_call):
# xxx not super clean...
default_content.text += f"\n<b>{self.pretty_slice(generator_args)}</b>"
return default_content

60 changes: 30 additions & 30 deletions nbautoeval/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,53 @@
from ipywidgets import HTML, HTMLMath, Layout

class Content:

"""
this class is what a renderer returns
it models what will ultimately go into a visible Area, that is to say
. css properties
. classes
. a layout (in the ipywidgets sense), here we model this as a dictionary
the most useful verions of this is TextContent, that has
. a textual contents
. whether it is code
. whether it is code
. whether it contains math
this is materialized by its widget() method that should return an ipywidget
"""

def __init__(self, *, css_properties=None, classes=None, layout_dict=None):
self.css_properties = css_properties or {}
self.classes = classes or []
self.layout_dict = layout_dict or {}
self._widget_instance = None

def __repr__(self):
return (f"<{type(self).__name__} with {len(self.css_properties)} css props "
f"{len(self.classes)} classes> "
f"and {len(self.layout_dict)} items in its ipywidgets layout")

def style(self):
return "".join(f"{k}:{v};" for (k, v) in self.css_properties.items())
def style_attribute(self):
return f'style="{self.style()}"' if self.css_properties else ''



def add_css_properties(self, css_properties: dict):
self.css_properties.update(css_properties)
return self

def add_class(self, cls):
self.classes.append(cls)
return self

def add_classes(self, classes):
self.classes.extend(classes)
return self

def add_layout(self, layout_dict):
self.layout_dict.update(layout_dict)
return self
Expand All @@ -62,28 +62,28 @@ def widget(self):
"""
this generic code is only about caching
each subclass should provide their _widget_(self) method
"""
"""
if self._widget_instance is None:
self._widget_instance = self._widget_() # pylint: disable=no-member
return self._widget_instance



class TextContent(Content):
'''
the generic mechanics to turn a text into a widget
several settings are available, which by default
are all turned off
is_code: will cause the whole content to be taken as code
needs_math: will create a HTMLMath widget instead of plain HTML
has_markdown: text first goes through a markdown stage
'''
def __init__(self, text,
def __init__(self, text,
is_code=False, needs_math=False, has_markdown=False,
**kwds):
super().__init__(**kwds)
# make yaml more robust, especially with answers like 'no'
# make yaml more robust, especially with answers like 'no'
# that, when not quoted in yaml, produce False that is a bool
if not isinstance(text, str):
print(f"WARNING: building a TextContent from non-str {text}")
Expand All @@ -92,8 +92,8 @@ def __init__(self, text,
self.is_code = is_code
self.needs_math = needs_math
self.has_markdown = has_markdown
# used in particular in quiz's sanity checks

# used in particular in quiz's sanity checks
def __str__(self):
return self.text

Expand All @@ -104,11 +104,11 @@ def set_is_code(self, is_code):
"""
self.is_code = is_code
return self

def set_needs_math(self, needs_math):
self.needs_math = needs_math
return self

def set_has_markdown(self, has_markdown):
self.has_markdown = has_markdown
return self
Expand All @@ -131,13 +131,13 @@ def _widget_(self):

# get predefined settings just by the class name
class CodeContent(TextContent):

def __init__(self, text, **kwds):
super().__init__(text, **kwds)
self.is_code = True

class MathContent(TextContent):

def __init__(self, text, **kwds):
super().__init__(text, **kwds)
self.needs_math = True
Expand All @@ -159,14 +159,14 @@ def __init__(self, text, **kwds):

class CssContent(Content):
"""
dedicated to inject CSS into HTML through
dedicated to inject CSS into HTML through
a <style> tag that has display='none'
"""

def __init__(self, plain_css, **kwds):
self.plain_css = plain_css
super().__init__(**kwds)

def __repr__(self):
return f"<CssContent {self.plain_css}>"

Expand All @@ -176,13 +176,13 @@ def _widget_(self):


class ResultContent(Content):

def __init__(self, boolean, **kwds):
self.boolean = boolean
super().__init__(**kwds)
self.css_properties['align-self'] = 'center'


def _widget_(self):
symbol = "fa-check" if self.boolean else "fa-close"

Expand All @@ -193,7 +193,7 @@ def _widget_(self):
for cls in self.classes:
result.add_class(cls)
return result


def the_class(self):
return 'ok' if self.boolean else 'ko'
Loading

0 comments on commit 957ffa7

Please sign in to comment.