From 3b28597486951c225239c220def190377ee1739f Mon Sep 17 00:00:00 2001 From: Aniket21mathur Date: Sat, 6 Jul 2019 12:29:22 +0530 Subject: [PATCH] flake8 fixes --- src/sugar3/activity/activityinstance.py | 3 +- src/sugar3/activity/widgets.py | 6 ++-- src/sugar3/bundle/__init__.py | 37 ++++++++++++++++++------ src/sugar3/bundle/bundleversion.py | 3 +- src/sugar3/dispatch/saferef.py | 3 +- src/sugar3/graphics/alert.py | 3 +- src/sugar3/graphics/colorbutton.py | 6 ++-- src/sugar3/graphics/icon.py | 13 ++++----- src/sugar3/graphics/notebook.py | 6 ++-- src/sugar3/graphics/objectchooser.py | 15 ++++++---- src/sugar3/graphics/palettewindow.py | 2 +- src/sugar3/graphics/scrollingdetector.py | 8 ++--- src/sugar3/graphics/toolbox.py | 3 +- src/sugar3/graphics/xocolor.py | 3 +- src/sugar3/mime.py | 3 +- src/sugar3/profile.py | 22 +++++++------- src/sugar3/util.py | 3 +- 17 files changed, 87 insertions(+), 52 deletions(-) diff --git a/src/sugar3/activity/activityinstance.py b/src/sugar3/activity/activityinstance.py index b60ac104..5c1bebf8 100644 --- a/src/sugar3/activity/activityinstance.py +++ b/src/sugar3/activity/activityinstance.py @@ -135,7 +135,8 @@ def main(): command = bundle.get_command() if command.startswith('sugar-activity'): if not command.startswith('sugar-activity3'): - logging.warning("Activity written for Python 2, consider porting to Python 3.") + logging.warning("Activity written for Python 2,\ + consider porting to Python 3.") activity_class = command.split(" ")[1] # when an activity is started outside sugar, diff --git a/src/sugar3/activity/widgets.py b/src/sugar3/activity/widgets.py index 21e71728..57223f4b 100644 --- a/src/sugar3/activity/widgets.py +++ b/src/sugar3/activity/widgets.py @@ -34,7 +34,8 @@ from sugar3.graphics.palettemenu import PaletteMenuBox from sugar3 import profile -def _(msg): return gettext.dgettext('sugar-toolkit-gtk3', msg) +def _(msg): + return gettext.dgettext('sugar-toolkit-gtk3', msg) def _create_activity_icon(metadata): @@ -337,7 +338,8 @@ class ActivityToolbar(Gtk.Toolbar): if activity.metadata: title_button = TitleEntry(activity) - title_button.connect('enter-key-press', lambda widget: self.emit('enter-key-press')) + title_button.connect('enter-key-press', + lambda widget: self.emit('enter-key-press')) title_button.show() self.insert(title_button, -1) self.title = title_button.entry diff --git a/src/sugar3/bundle/__init__.py b/src/sugar3/bundle/__init__.py index ea06fb45..39dc1667 100644 --- a/src/sugar3/bundle/__init__.py +++ b/src/sugar3/bundle/__init__.py @@ -29,10 +29,12 @@ an `[Activity]` header on the first line: 1.2.3, 1.2.3-country, or 1.2.3~developer, * `bundle_id` - the activity bundle identifier, using [Java package - naming conventions](http://en.wikipedia.org/wiki/Java_package#Package_naming_conventions), + naming conventions] + (http://en.wikipedia.org/wiki/Java_package#Package_naming_conventions), should conform to the [D-Bus specification for message protocol - names](http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names)(hyphens - are not allowed), usually an organisation or individual domain name + names] + (http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names) + (hyphens are not allowed), usually an organisation or individual domain name in reverse order, e.g. `org.sugarlabs.Name`, * `license` - an identifier for the software license of the bundle, @@ -58,7 +60,8 @@ Optional metadata keys are; files of these MIME types. Used to offer your activity when opening a downloaded file or a journal object. -* `url` - link to a home page or user documentation on https://help.sugarlabs.org/, +* `url` - link to a home page or user documentation on + https://help.sugarlabs.org/, * `repository` - link to repository for activity code, for use by git clone, @@ -84,7 +87,8 @@ Deprecated metadata keys are; * `update_url` - the updater no longer uses this. .. _SPDX License Identifier: http://spdx.org/licenses/ -.. _Fedora License Short Name: https://fedoraproject.org/wiki/Licensing:Main?rd=Licensing#Good_Licenses +.. _Fedora License Short Name: + https://fedoraproject.org/wiki/Licensing:Main?rd=Licensing#Good_Licenses AppStream Metadata ================== @@ -132,12 +136,27 @@ Example `activity.info` metadata_license = CC0-1.0 description: -

Surf the world! Here you can do research, watch educational videos, take online courses, find books, connect with friends and more. Browse is powered by the WebKit2 rendering engine with the Faster Than Light javascript interpreter - allowing you to view the full beauty of the web.

+

+ Surf the world! Here you can do research, watch educational videos, + take online courses, find books, connect with friends and more. + Browse is powered by the WebKit2 rendering engine with the Faster + Than Light javascript interpreter - allowing you to view the + full beauty of the web. +

To help in researching, Browse offers many features:

screenshots = https://people.sugarlabs.org/sam/activity-ss/browse-1-1.png https://people.sugarlabs.org/sam/activity-ss/browse-1-2.png ''' diff --git a/src/sugar3/bundle/bundleversion.py b/src/sugar3/bundle/bundleversion.py index 7ad9e3e0..577ed682 100644 --- a/src/sugar3/bundle/bundleversion.py +++ b/src/sugar3/bundle/bundleversion.py @@ -43,7 +43,8 @@ Based on the implementation of :pep:`386`, but adapted to our numeration schema. Attributes: - VERSION_RE (RegexObject): regular expression for versions, deprecated, as it is insufficient by itself. + VERSION_RE (RegexObject): regular expression for versions,\ + deprecated, as it is insufficient by itself. """ import re diff --git a/src/sugar3/dispatch/saferef.py b/src/sugar3/dispatch/saferef.py index 581703c2..405c06d5 100644 --- a/src/sugar3/dispatch/saferef.py +++ b/src/sugar3/dispatch/saferef.py @@ -167,7 +167,8 @@ class BoundMethodWeakref(object): def __cmp__(self, other): """Compare with another reference""" if not isinstance(other, self.__class__): - return ((self.__class__ > type(other)) - (self.__class__ < type(other))) + return ((self.__class__ > type(other)) - + (self.__class__ < type(other))) return ((self.key > other.key) - (self.key < other.key)) def __call__(self): diff --git a/src/sugar3/graphics/alert.py b/src/sugar3/graphics/alert.py index 66cefd9d..f05f00fc 100644 --- a/src/sugar3/graphics/alert.py +++ b/src/sugar3/graphics/alert.py @@ -61,7 +61,8 @@ from sugar3.graphics import style from sugar3.graphics.icon import Icon -def _(msg): return gettext.dgettext('sugar-toolkit-gtk3', msg) +def _(msg): + return gettext.dgettext('sugar-toolkit-gtk3', msg) if not hasattr(GObject.ParamFlags, 'READWRITE'): diff --git a/src/sugar3/graphics/colorbutton.py b/src/sugar3/graphics/colorbutton.py index 10c188ef..ff209fa5 100644 --- a/src/sugar3/graphics/colorbutton.py +++ b/src/sugar3/graphics/colorbutton.py @@ -29,7 +29,8 @@ from sugar3.graphics.icon import Icon from sugar3.graphics.palette import Palette, ToolInvoker, WidgetInvoker -def _(msg): return gettext.dgettext('sugar-toolkit-gtk3', msg) +def _(msg): + return gettext.dgettext('sugar-toolkit-gtk3', msg) if not hasattr(GObject.ParamFlags, 'READWRITE'): @@ -123,7 +124,8 @@ class _ColorButton(Gtk.Button): context = self.get_style_context() fg_color = context.get_color(Gtk.StateType.NORMAL) # the color components are stored as float values between 0.0 and 1.0 - return '#%.2X%.2X%.2X' % (int(fg_color.red * 255), int(fg_color.green * 255), + return '#%.2X%.2X%.2X' % (int(fg_color.red * 255), + int(fg_color.green * 255), int(fg_color.blue * 255)) def set_color(self, color): diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py index 2343aee3..342e802a 100644 --- a/src/sugar3/graphics/icon.py +++ b/src/sugar3/graphics/icon.py @@ -209,7 +209,7 @@ class _IconBuffer(object): # try read from the .icon file icon_filename = info.get_filename().replace('.svg', '.icon') if icon_filename != info.get_filename() and \ - os.path.exists(icon_filename): + os.path.exists(icon_filename): try: with open(icon_filename) as config_file: @@ -1309,8 +1309,7 @@ class CellRendererIcon(Gtk.CellRenderer): # widget is the treeview x, y = widget.get_pointer() x, y = widget.convert_widget_to_bin_window_coords(x, y) - return ((cell_area.x <= x <= cell_area.x + cell_area.width) - and + return ((cell_area.x <= x <= cell_area.x + cell_area.width) and (cell_area.y <= y <= cell_area.y + cell_area.height)) pointer_inside = is_pointer_inside() @@ -1379,10 +1378,10 @@ def get_icon_state(base_name, perc, step=5): ''' Get the closest icon name for a given state in percent. - First, you need a set of icons. They must be prefixed with `base_name`, for - example "network-wireless". They must be suffixed with 3 digit percentage - numbers, for example "-000", "-200", etc. Eventually, you get a collection - of icon names like: + First, you need a set of icons. They must be prefixed with `base_name`, + for example "network-wireless". They must be suffixed with 3 digit + percentage numbers, for example "-000", "-200", etc. Eventually, you get + a collection of icon names like: * network-wireless-000 * network-wireless-020 diff --git a/src/sugar3/graphics/notebook.py b/src/sugar3/graphics/notebook.py index 460a9b01..088733b3 100644 --- a/src/sugar3/graphics/notebook.py +++ b/src/sugar3/graphics/notebook.py @@ -37,7 +37,8 @@ if not hasattr(GObject.ParamFlags, 'READWRITE'): class Notebook(Gtk.Notebook): ''' Notebook class that creates a :class:`Gtk.Notebook`. It is possible to set - the `can-close-tabs` property from the constructor through Notebook(can_close_tabs=True) + the `can-close-tabs` property from the constructor + through Notebook(can_close_tabs=True) ''' __gtype_name__ = 'SugarNotebook' @@ -112,7 +113,8 @@ class Notebook(Gtk.Notebook): ''' Adds a page to the notebook and sets the newly added page as current. Returns True if the page is successfully added to the notebook. - If `can-close-tabs` is true, then a GtkEventBox is also created to close the tab. + If `can-close-tabs` is true, then a GtkEventBox is also created + to close the tab. Args: text_label (string): label of page to be added diff --git a/src/sugar3/graphics/objectchooser.py b/src/sugar3/graphics/objectchooser.py index 7cbe860f..38d962c0 100644 --- a/src/sugar3/graphics/objectchooser.py +++ b/src/sugar3/graphics/objectchooser.py @@ -51,8 +51,10 @@ def get_preview_pixbuf(preview_data, width=-1, height=-1): sugar3.datastore.datastore.DSObject.get_metadata() method. Keyword Args: - width (int): the pixbuf width, if is not set, the default width will be used - height (int): the pixbuf width, if is not set, the default height will be used + width (int): the pixbuf width, if is not set, + the default width will be used + height (int): the pixbuf width, if is not set, + the default height will be used Returns: Pixbuf, the generated Pixbuf @@ -117,8 +119,9 @@ class ObjectChooser(object): """ UI interface for object choosers. - Object choosers can be used by acivities to allow the user to select objects - from the file system or from some other similar source. + Object choosers can be used by acivities to allow the + user to select objects from the file system or from + some other similar source. Keyword Args: parent (:class:`Gtk.Widget`): the widget calling ObjectChooser @@ -194,8 +197,8 @@ class ObjectChooser(object): Runs the object chooser and displays it. Returns: - Gtk.ResponseType constant, the response received from displaying the - object chooser. + Gtk.ResponseType constant, the response received + from displaying the object chooser. """ self._object_id = None diff --git a/src/sugar3/graphics/palettewindow.py b/src/sugar3/graphics/palettewindow.py index 1cadbb67..dbaf7174 100644 --- a/src/sugar3/graphics/palettewindow.py +++ b/src/sugar3/graphics/palettewindow.py @@ -1319,7 +1319,7 @@ class CursorInvoker(Invoker): self._leave_hid = self._item.connect('leave-notify-event', self.__leave_notify_event_cb) self._release_hid = self._item.connect('button-release-event', - self.__button_release_event_cb) + self.__button_release_event_cb) self._long_pressed_hid = self._long_pressed_controller.connect( 'pressed', self.__long_pressed_event_cb, self._item) diff --git a/src/sugar3/graphics/scrollingdetector.py b/src/sugar3/graphics/scrollingdetector.py index a533aae0..fc5bd7de 100644 --- a/src/sugar3/graphics/scrollingdetector.py +++ b/src/sugar3/graphics/scrollingdetector.py @@ -33,16 +33,16 @@ from gi.repository import GLib class ScrollingDetector(GObject.GObject): ''' The scrolling detector sends signals when a scrolled window is scrolled and - when a scrolled window stops scrolling. Only one `scroll-start` signal will be - emitted until scrolling stops. + when a scrolled window stops scrolling. Only one `scroll-start` + signal will be emitted until scrolling stops. The `scroll-start` signal is emitted when scrolling begins and The `scroll-end` signal is emitted when scrolling ends Neither of these two signals have any arguments Args: - scrolled_window (Gtk.ScrolledWindow): A GTK scrolled window object for which - scrolling is to be detected + scrolled_window (Gtk.ScrolledWindow): A GTK scrolled window + object for which scrolling is to be detected timeout (int): time in milliseconds to establish the interval for which scrolling is detected diff --git a/src/sugar3/graphics/toolbox.py b/src/sugar3/graphics/toolbox.py index 23843b11..daf65166 100644 --- a/src/sugar3/graphics/toolbox.py +++ b/src/sugar3/graphics/toolbox.py @@ -78,7 +78,8 @@ class Toolbox(Gtk.VBox): Args: name (string): name of toolbar to be added - toolbar (.. :class:`Gtk.Toolbar`): Gtk.Toolbar to be appended to this toolbox + toolbar (.. :class:`Gtk.Toolbar`): + Gtk.Toolbar to be appended to this toolbox ''' label = Gtk.Label(label=name) req = label.size_request() diff --git a/src/sugar3/graphics/xocolor.py b/src/sugar3/graphics/xocolor.py index e5d7e4e8..78525c5d 100644 --- a/src/sugar3/graphics/xocolor.py +++ b/src/sugar3/graphics/xocolor.py @@ -210,7 +210,8 @@ colors = [['#B20008', '#FF2B34'], def _parse_string(color_string): ''' - Returns array of length 2 of two colors in standard html form of [stroke color, fill color] + Returns array of length 2 of two colors in standard html + form of [stroke color, fill color] Args: color_string (string): two html format strings separated by a comma diff --git a/src/sugar3/mime.py b/src/sugar3/mime.py index a2797d0d..9667c336 100644 --- a/src/sugar3/mime.py +++ b/src/sugar3/mime.py @@ -33,7 +33,8 @@ from gi.repository import GdkPixbuf from gi.repository import Gio -def _(msg): return gettext.dgettext('sugar-toolkit-gtk3', msg) +def _(msg): + return gettext.dgettext('sugar-toolkit-gtk3', msg) GENERIC_TYPE_TEXT = 'Text' diff --git a/src/sugar3/profile.py b/src/sugar3/profile.py index e46943fd..d5757c34 100644 --- a/src/sugar3/profile.py +++ b/src/sugar3/profile.py @@ -88,11 +88,11 @@ class Profile(object): return None magic = 'ssh-dss ' - for l in lines: - l = l.strip() - if not l.startswith(magic): + for line in lines: + line = line.strip() + if not line.startswith(magic): continue - return l[len(magic):] + return line[len(magic):] else: logging.error('Error parsing public key.') return None @@ -114,17 +114,17 @@ class Profile(object): key = "" begin_found = False end_found = False - for l in lines: - l = l.strip() - if l.startswith(('-----BEGIN DSA PRIVATE KEY-----', - '-----BEGIN OPENSSH PRIVATE KEY-----')): + for line in lines: + line = line.strip() + if line.startswith(('-----BEGIN DSA PRIVATE KEY-----', + '-----BEGIN OPENSSH PRIVATE KEY-----')): begin_found = True continue - if l.startswith(('-----END DSA PRIVATE KEY-----', - '-----END OPENSSH PRIVATE KEY-----')): + if line.startswith(('-----END DSA PRIVATE KEY-----', + '-----END OPENSSH PRIVATE KEY-----')): end_found = True continue - key += l + key += line if not (len(key) and begin_found and end_found): logging.error('Error parsing public key.') return None diff --git a/src/sugar3/util.py b/src/sugar3/util.py index 45cbd368..8ea5adba 100644 --- a/src/sugar3/util.py +++ b/src/sugar3/util.py @@ -32,7 +32,8 @@ import logging import atexit -def _(msg): return gettext.dgettext('sugar-toolkit-gtk3', msg) +def _(msg): + return gettext.dgettext('sugar-toolkit-gtk3', msg) def printable_hash(in_hash):