Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
some flake8 for repl
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Nov 25, 2020
1 parent 020bd59 commit 64efc98
Show file tree
Hide file tree
Showing 19 changed files with 240 additions and 229 deletions.
15 changes: 9 additions & 6 deletions src/sage/repl/attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
load_debug_mode = False
attach_debug_mode = True


def load_attach_mode(load_debug=None, attach_debug=None):
"""
Get or modify the current debug mode for the behavior of
Expand Down Expand Up @@ -131,14 +132,15 @@ def load_attach_mode(load_debug=None, attach_debug=None):
global load_debug_mode, attach_debug_mode
if load_debug is None and attach_debug is None:
return (load_debug_mode, attach_debug_mode)
if not load_debug is None:
if load_debug is not None:
load_debug_mode = load_debug
if not attach_debug is None:
if attach_debug is not None:
attach_debug_mode = attach_debug


search_paths = []


def load_attach_path(path=None, replace=False):
"""
Get or modify the current search path for :func:`load` and
Expand Down Expand Up @@ -169,7 +171,7 @@ def load_attach_path(path=None, replace=False):
sage: with open(fullpath, 'w') as f:
....: _ = f.write("print(37 * 3)")
We put SAGE_TMP on the attach path for testing (otherwise this will
We put ``SAGE_TMP`` on the attach path for testing (otherwise this will
load ``test.py`` from the current working directory if that happens
to exist)::
Expand Down Expand Up @@ -226,8 +228,7 @@ def load_attach_path(path=None, replace=False):

def reset_load_attach_path():
"""
Resets the current search path for :func:`load` and
:func:`attach`.
Reset the current search path for :func:`load` and :func:`attach`.
The default path is ``'.'`` plus any paths specified in the
environment variable ``SAGE_LOAD_ATTACH_PATH``.
Expand Down Expand Up @@ -266,6 +267,7 @@ def reset_load_attach_path():
for path in os.environ.get('SAGE_LOAD_ATTACH_PATH', '').split(':'):
load_attach_path(path=path)


# Set up the initial search path for loading and attaching files. A
# user can modify the path with the function load_attach_path.
reset_load_attach_path()
Expand Down Expand Up @@ -310,7 +312,7 @@ def attach(*files):
.. SEEALSO::
:meth:`~sage.repl.load.load` is the same as :func:`attach`, but
doesn't automatically reload a file when it changes.
does not automatically reload a file when it changes.
EXAMPLES:
Expand Down Expand Up @@ -487,6 +489,7 @@ def detach(filename):
if not attached:
sage.repl.inputhook.uninstall()


def reset():
"""
Remove all the attached files from the list of attached files.
Expand Down
8 changes: 2 additions & 6 deletions src/sage/repl/display/fancy_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""
Representations of objects
"""

# ****************************************************************************
# Copyright (C) 2014 Volker Braun <vbraun.name@gmail.com>
#
Expand All @@ -20,10 +19,10 @@
_type_pprinters,
)

_baseclass_reprs = (object.__repr__,)

from sage.repl.display.util import format_list

_baseclass_reprs = (object.__repr__,)


class ObjectReprABC(object):
"""
Expand Down Expand Up @@ -216,7 +215,6 @@ def __call__(self, obj, p, cycle):
return True



class PlainPythonRepr(ObjectReprABC):
"""
The ordinary Python representation
Expand Down Expand Up @@ -360,5 +358,3 @@ def __call__(self, obj, p, cycle):
return False
p.text(output)
return True


7 changes: 3 additions & 4 deletions src/sage/repl/display/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
:class:`~sage.typeset.ascii_art.AsciiArt` object (see and
:meth:`sage.structure.sage_object.SageObject._ascii_art_`). """

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2014 Volker Braun <vbraun.name@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

from io import StringIO

Expand Down Expand Up @@ -290,4 +290,3 @@ def __call__(self, obj):
printer.pretty(obj)
printer.flush()
return stream.getvalue()

27 changes: 12 additions & 15 deletions src/sage/repl/display/jsmol_iframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
from sage.misc.cachefunc import cached_method


INNER_HTML_TEMPLATE = \
"""
INNER_HTML_TEMPLATE = """
<html>
<head>
<style>
Expand All @@ -38,7 +37,7 @@
padding: 0;
overflow: hidden;
}}
body, html {{
body, html {{
height: 100%;
width: 100%;
}}
Expand Down Expand Up @@ -67,18 +66,16 @@
"""


IFRAME_TEMPLATE = \
"""
<iframe srcdoc="{escaped_inner_html}"
IFRAME_TEMPLATE = """
<iframe srcdoc="{escaped_inner_html}"
width="{width}"
height="{height}"
style="border: 0;">
</iframe>
"""


OUTER_HTML_TEMPLATE = \
"""
OUTER_HTML_TEMPLATE = """
<html>
<head>
<title>JSmol 3D Scene</title>
Expand All @@ -102,7 +99,7 @@ def __init__(self, jmol, path_to_jsmol=None, width='100%', height='100%'):
- ``path_to_jsmol`` -- string (optional, default is
``'/nbextensions/jsmol'``). The path (relative or absolute)
where ``JSmol.min.js`` is served on the web server.
where ``JSmol.min.js`` is served on the web server.
- ``width`` -- integer or string (optional, default:
``'100%'``). The width of the JSmol applet using CSS
Expand Down Expand Up @@ -176,7 +173,7 @@ def js_script(self):
Since the many shortcomings of Javascript include multi-line
strings, this actually returns Javascript code to reassemble
the script from a list of strings.
OUTPUT:
String. Javascript code that evaluates to :meth:`script` as
Expand All @@ -199,13 +196,13 @@ def js_script(self):
script += [r" '{0}',".format(line)]
script += [r"].join('\n');"]
return '\n'.join(script)

def _repr_(self):
"""
Return as string representation
OUTPUT:
String.
EXAMPLES::
Expand Down Expand Up @@ -242,15 +239,15 @@ def inner_html(self):
height=self._height,
path_to_jsmol=self._path,
)

def iframe(self):
"""
Return HTML iframe
OUTPUT:
String.
EXAMPLES::
sage: from sage.repl.display.jsmol_iframe import JSMolHtml
Expand Down
19 changes: 10 additions & 9 deletions src/sage/repl/display/pretty_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
- Volker Braun (2013): refactored into DisplayHookBase
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2014 Volker Braun <vbraun.name@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************


from IPython.lib.pretty import PrettyPrinter

from sage.repl.display.fancy_repr import *


from sage.repl.display.fancy_repr import (TallListRepr, PlainPythonRepr,
LargeMatrixHelpRepr,
SomeIPythonRepr)


class SagePrettyPrinter(PrettyPrinter):
Expand Down Expand Up @@ -139,9 +139,11 @@ def pretty(self, obj):
try:
ok = False
for representation in self.pretty_repr:
if self.DEBUG: print('Trying {0}'.format(representation))
if self.DEBUG:
print('Trying {0}'.format(representation))
ok = representation(obj, self, cycle)
if self.DEBUG: print('ok = {0}'.format(ok))
if self.DEBUG:
print('ok = {0}'.format(ok))
if ok not in [True, False]:
raise RuntimeError('printer failed to return boolean')
if ok:
Expand All @@ -151,4 +153,3 @@ def pretty(self, obj):
finally:
self.end_group()
self.stack.pop()

18 changes: 9 additions & 9 deletions src/sage/repl/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
<class 'sage.repl.image.Image'>
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2015 Volker Braun <vbraun.name@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

import io

Expand All @@ -48,7 +48,7 @@ def __init__(self, mode, size, color='white'):
- ``mode`` -- string. The mode to use for the new image. Valid
options are:
* ``'1'`` (1-bit pixels, black and white, stored with
one pixel per byte)
Expand Down Expand Up @@ -85,7 +85,7 @@ def __init__(self, mode, size, color='white'):
initialised.
OUTPUT:
A new :class:`Image` object.
EXAMPLES::
Expand All @@ -100,7 +100,7 @@ def __init__(self, mode, size, color='white'):
def pil(self):
"""
Access the wrapped PIL(low) Image
OUTPUT:
The underlying ``PIL.Image.Image object``.
Expand Down Expand Up @@ -131,7 +131,7 @@ def pixels(self):
<PixelAccess object at 0x...>
"""
return self._pil.load()

def _repr_(self):
"""
Return string representation.
Expand Down Expand Up @@ -169,7 +169,7 @@ def _repr_(self):
def mode(self):
"""
Return the color mode
OUTPUT:
String. As given when constructing the image.
Expand Down Expand Up @@ -201,7 +201,7 @@ def width(self):
34
"""
return self.pil.size[0]

def height(self):
"""
Return the vertical dimension in pixels
Expand Down
2 changes: 1 addition & 1 deletion src/sage/repl/inputhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def sage_inputhook(context):
while True:
sage.repl.attach.reload_attached_files_if_modified()
try:
r, w, e = select.select([f], [], [], TIMEOUT)
r, _, _ = select.select([f], [], [], TIMEOUT)
if f in r:
return # IPython signalled us to stop
except select.error as e:
Expand Down

0 comments on commit 64efc98

Please sign in to comment.