diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000..bb03d08a82 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +ignore=E123,E124,E126,E128,W503 diff --git a/setup-freeze.py b/setup-freeze.py index 7c0703ed36..3b5865e28d 100755 --- a/setup-freeze.py +++ b/setup-freeze.py @@ -65,8 +65,9 @@ def replace_path(match): if sys.platform == 'darwin': libs = [os.path.join('@executable_path', l) for l in libs] return 'shared-library="%s"' % ','.join(libs) -lib_re = re.compile(r'shared-library="([^\"]*)"') + +lib_re = re.compile(r'shared-library="([^\"]*)"') required_libs = set() temp = tempfile.mkdtemp() for ns in required_gi_namespaces: diff --git a/tryton/__init__.py b/tryton/__init__.py index d3b439655e..95be105734 100644 --- a/tryton/__init__.py +++ b/tryton/__init__.py @@ -14,7 +14,7 @@ except ValueError: try: # Import earlier otherwise there is a segmentation fault on MSYS2 - import goocalendar + import goocalendar # noqa: F401 except ImportError: pass diff --git a/tryton/action/__init__.py b/tryton/action/__init__.py index 0dad8d0854..3dc05cfd93 100644 --- a/tryton/action/__init__.py +++ b/tryton/action/__init__.py @@ -1,3 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from .main import * +from .main import Action + +__all__ = [Action] diff --git a/tryton/common/__init__.py b/tryton/common/__init__.py index 8f46d94989..c90fc4206c 100644 --- a/tryton/common/__init__.py +++ b/tryton/common/__init__.py @@ -1,8 +1,32 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from .common import * -from .domain_inversion import domain_inversion, eval_domain, localize_domain, \ - merge, inverse_leaf, filter_leaf, prepare_reference_domain, \ - extract_reference_models, concat, simplify, unique_value +from .common import ( + IconFactory, MODELACCESS, MODELHISTORY, VIEW_SEARCH, + get_toplevel_window, get_sensible_widget, selection, file_selection, + slugify, file_write, file_open, mailto, message, warning, userwarning, sur, + sur_3b, ask, concurrency, error, to_xml, process_exception, Login, Logout, + node_attributes, hex2rgb, highlight_rgb, generateColorscheme, RPCException, + RPCProgress, RPCExecute, RPCContextReload, Tooltips, COLOR_SCHEMES, + filter_domain, timezoned_date, untimezoned_date, humanize, get_hostname, + get_port, resize_pixbuf, data2pixbuf, apply_label_attributes, ellipsize, + get_align, date_format, idle_add) +from .domain_inversion import ( + domain_inversion, eval_domain, localize_domain, merge, inverse_leaf, + filter_leaf, prepare_reference_domain, extract_reference_models, concat, + simplify, unique_value) from .environment import EvalEnvironment from . import timedelta + +__all__ = [ + IconFactory, MODELACCESS, MODELHISTORY, VIEW_SEARCH, + get_toplevel_window, get_sensible_widget, selection, file_selection, + slugify, file_write, file_open, mailto, message, warning, userwarning, sur, + sur_3b, ask, concurrency, error, to_xml, process_exception, Login, Logout, + node_attributes, hex2rgb, highlight_rgb, generateColorscheme, RPCException, + RPCProgress, RPCExecute, RPCContextReload, Tooltips, COLOR_SCHEMES, + filter_domain, timezoned_date, untimezoned_date, humanize, get_hostname, + get_port, resize_pixbuf, data2pixbuf, apply_label_attributes, ellipsize, + get_align, date_format, idle_add, domain_inversion, eval_domain, + localize_domain, merge, inverse_leaf, filter_leaf, + prepare_reference_domain, extract_reference_models, concat, simplify, + unique_value, EvalEnvironment, timedelta] diff --git a/tryton/common/common.py b/tryton/common/common.py index b012fe392d..0da74c2077 100644 --- a/tryton/common/common.py +++ b/tryton/common/common.py @@ -274,20 +274,6 @@ class ViewSearch(object): VIEW_SEARCH = ViewSearch() -def find_in_path(name): - if os.name == "nt": - sep = ';' - else: - sep = ':' - path = [directory for directory in os.environ['PATH'].split(sep) - if os.path.isdir(directory)] - for directory in path: - val = os.path.join(directory, name) - if os.path.isfile(val) or os.path.islink(val): - return val - return name - - def get_toplevel_window(): from tryton.gui.main import Main return Main().get_active_window() diff --git a/tryton/common/datetime_.py b/tryton/common/datetime_.py index b6440d8b12..5f7c92c2d7 100644 --- a/tryton/common/datetime_.py +++ b/tryton/common/datetime_.py @@ -83,8 +83,8 @@ class Date(Gtk.Entry): self.__calendar = Gtk.Calendar() cal_options = ( - Gtk.CalendarDisplayOptions.SHOW_DAY_NAMES | - Gtk.CalendarDisplayOptions.SHOW_HEADING) + Gtk.CalendarDisplayOptions.SHOW_DAY_NAMES + | Gtk.CalendarDisplayOptions.SHOW_HEADING) self.__calendar.set_display_options(cal_options) self.__cal_popup.add(self.__calendar) self.__calendar.connect('day-selected', self.cal_popup_changed) diff --git a/tryton/common/domain_parser.py b/tryton/common/domain_parser.py index 401311fc3a..c81eecb483 100644 --- a/tryton/common/domain_parser.py +++ b/tryton/common/domain_parser.py @@ -542,7 +542,8 @@ class DomainParser(object): def stringable_(clause): if not clause: return True - if (((clause[0] in ('AND', 'OR')) + if (( + (clause[0] in ('AND', 'OR')) or isinstance(clause[0], (list, tuple))) and all(isinstance(c, (list, tuple)) for c in clause[1:])): return self.stringable(clause) @@ -626,8 +627,8 @@ class DomainParser(object): else: operator = '' formatted_value = format_value(field, value, target, self.context) - if (operator in OPERATORS and - field['type'] in ('char', 'text', 'selection') + if (operator in OPERATORS + and field['type'] in ('char', 'text', 'selection') and value == ''): formatted_value = '""' return '%s: %s%s' % (quote(field['string']), operator, diff --git a/tryton/common/htmltextbuffer.py b/tryton/common/htmltextbuffer.py index a47c9e2187..72bbd6ca08 100644 --- a/tryton/common/htmltextbuffer.py +++ b/tryton/common/htmltextbuffer.py @@ -413,7 +413,7 @@ if __name__ == '__main__':

Center
Sans6red
-
Title
''' +
Title
''' # noqa: E501 win = Gtk.Window() win.set_title('HTMLTextBuffer') diff --git a/tryton/common/selection.py b/tryton/common/selection.py index ac7043586f..cfb48e2c33 100644 --- a/tryton/common/selection.py +++ b/tryton/common/selection.py @@ -156,8 +156,9 @@ class PopdownMixin(object): if lengths: pop = sorted(lengths, reverse=True) average = sum(pop) / len(pop) - deviation = int(math.sqrt(sum((x - average) ** 2 for x in pop) / - len(pop))) + deviation = int( + math.sqrt(sum((x - average) ** 2 for x in pop) + / len(pop))) width = max(next((x for x in pop if x < (deviation * 4)), 10), 10) else: width = 10 diff --git a/tryton/gui/__init__.py b/tryton/gui/__init__.py index 0dad8d0854..27d571f1e9 100644 --- a/tryton/gui/__init__.py +++ b/tryton/gui/__init__.py @@ -1,3 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from .main import * +from .main import Main + +__all__ = [Main] diff --git a/tryton/gui/window/__init__.py b/tryton/gui/window/__init__.py index ab6d3baa13..f10bd31f9c 100644 --- a/tryton/gui/window/__init__.py +++ b/tryton/gui/window/__init__.py @@ -1,3 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from .window import * +from .window import Window + +__all__ = [Window] diff --git a/tryton/gui/window/form.py b/tryton/gui/window/form.py index 9fc81d3af6..07d23646e3 100644 --- a/tryton/gui/window/form.py +++ b/tryton/gui/window/form.py @@ -247,7 +247,7 @@ class Form(SignalEvent, TabContent): if (self.screen.current_view.view_type == 'form' and revision and revision < revisions[-1][0]): - revision = revisions[-1][0] + revision = revisions[-1][0] if revision != self.screen.context.get('_datetime'): self.screen.clear() # Update root group context that will be propagated diff --git a/tryton/gui/window/view_board/__init__.py b/tryton/gui/window/view_board/__init__.py index e33419253d..f566de670d 100644 --- a/tryton/gui/window/view_board/__init__.py +++ b/tryton/gui/window/view_board/__init__.py @@ -1,3 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from .view_board import * +from .view_board import ViewBoard + +__all__ = [ViewBoard] diff --git a/tryton/gui/window/view_board/action.py b/tryton/gui/window/view_board/action.py index 9eb0eeddf8..aa2e3f0223 100644 --- a/tryton/gui/window/view_board/action.py +++ b/tryton/gui/window/view_board/action.py @@ -95,8 +95,8 @@ class Action(SignalEvent): if not self.screen.current_record: return - if (self.screen.current_view.view_type == 'tree' and - int(self.screen.current_view.attributes.get( + if (self.screen.current_view.view_type == 'tree' + and int(self.screen.current_view.attributes.get( 'keyword_open', 0))): GenericAction.exec_keyword('tree_open', { 'model': self.screen.model_name, diff --git a/tryton/gui/window/view_form/__init__.py b/tryton/gui/window/view_form/__init__.py index 016355b5a9..360cfd1aa9 100644 --- a/tryton/gui/window/view_form/__init__.py +++ b/tryton/gui/window/view_form/__init__.py @@ -1,3 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. from . import screen + +__all__ = [screen] diff --git a/tryton/gui/window/view_form/model/record.py b/tryton/gui/window/view_form/model/record.py index e5941bc209..8200b13b00 100644 --- a/tryton/gui/window/view_form/model/record.py +++ b/tryton/gui/window/view_form/model/record.py @@ -603,8 +603,9 @@ class Record(SignalEvent): autocomplete = self.group.fields[fieldname].attrs['autocomplete'] args = self._get_on_change_args(autocomplete) try: - res = RPCExecute('model', self.model_name, 'autocomplete_' + - fieldname, args, context=self.get_context()) + res = RPCExecute( + 'model', self.model_name, + 'autocomplete_' + fieldname, args, context=self.get_context()) except RPCException: # ensure res is a list res = [] diff --git a/tryton/gui/window/view_form/screen/__init__.py b/tryton/gui/window/view_form/screen/__init__.py index 70b9392183..e6a2ce4a14 100644 --- a/tryton/gui/window/view_form/screen/__init__.py +++ b/tryton/gui/window/view_form/screen/__init__.py @@ -1,3 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from .screen import * +from .screen import Screen + +__all__ = [Screen] diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index 38280dd3d5..440f62d936 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -470,8 +470,8 @@ class Screen(SignalEvent): self.group.destroy() def default_row_activate(self): - if (self.current_view.view_type == 'tree' and - int(self.current_view.attributes.get('keyword_open', 0))): + if (self.current_view.view_type == 'tree' + and int(self.current_view.attributes.get('keyword_open', 0))): return Action.exec_keyword('tree_open', { 'model': self.model_name, 'id': self.current_record.id if self.current_record else None, @@ -491,8 +491,8 @@ class Screen(SignalEvent): view_id = int(view_id) if self.current_view: self.current_view.set_value() - if (self.current_record and - self.current_record not in self.current_record.group): + if (self.current_record + and self.current_record not in self.current_record.group): self.current_record = None fields = self.current_view.get_fields() if (self.current_record and self.current_view.editable diff --git a/tryton/gui/window/view_form/view/calendar_.py b/tryton/gui/window/view_form/view/calendar_.py index ca537cf9e9..7b2e146c33 100644 --- a/tryton/gui/window/view_form/view/calendar_.py +++ b/tryton/gui/window/view_form/view/calendar_.py @@ -11,7 +11,7 @@ from . import View, XMLViewParser try: from .calendar_gtk.calendar_ import Calendar_ from .calendar_gtk.toolbar import Toolbar -except ImportError as e: +except ImportError: Calendar_ = None Toolbar = None diff --git a/tryton/gui/window/view_form/view/calendar_gtk/toolbar.py b/tryton/gui/window/view_form/view/calendar_gtk/toolbar.py index 11f0bd55a9..866402d91b 100644 --- a/tryton/gui/window/view_form/view/calendar_gtk/toolbar.py +++ b/tryton/gui/window/view_form/view/calendar_gtk/toolbar.py @@ -61,9 +61,9 @@ class Toolbar(Gtk.Toolbar): 'day-selected-double-click', self.on_gtkcal_day_selected_double_click) gtkcal.set_display_options( - Gtk.CalendarDisplayOptions.SHOW_HEADING | - Gtk.CalendarDisplayOptions.SHOW_WEEK_NUMBERS | - Gtk.CalendarDisplayOptions.SHOW_DAY_NAMES) + Gtk.CalendarDisplayOptions.SHOW_HEADING + | Gtk.CalendarDisplayOptions.SHOW_WEEK_NUMBERS + | Gtk.CalendarDisplayOptions.SHOW_DAY_NAMES) gtkcal.set_no_show_all(True) self.__cal_popup.add(gtkcal) gtkcal.show() diff --git a/tryton/gui/window/view_form/view/graph_gtk/__init__.py b/tryton/gui/window/view_form/view/graph_gtk/__init__.py index aef2a929cb..4effdfa4a2 100644 --- a/tryton/gui/window/view_form/view/graph_gtk/__init__.py +++ b/tryton/gui/window/view_form/view/graph_gtk/__init__.py @@ -1,3 +1,2 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from parser import * diff --git a/tryton/gui/window/view_form/view/graph_gtk/line.py b/tryton/gui/window/view_form/view/graph_gtk/line.py index ef75ac0a08..0f7310d9b4 100644 --- a/tryton/gui/window/view_form/view/graph_gtk/line.py +++ b/tryton/gui/window/view_form/view/graph_gtk/line.py @@ -173,10 +173,10 @@ class Line(Graph): x = point.x * self.area.w + self.area.x y = point.y * self.area.h + self.area.y - l = (event.x - x) ** 2 + (event.y - y) ** 2 + square = (event.x - x) ** 2 + (event.y - y) ** 2 - if not nearest or l < nearest[1]: - nearest = (point, l) + if not nearest or square < nearest[1]: + nearest = (point, square) dia = self.area.w ** 2 + self.area.h ** 2 diff --git a/tryton/gui/window/view_form/view/list.py b/tryton/gui/window/view_form/view/list.py index 61bcd42a27..782760902d 100644 --- a/tryton/gui/window/view_form/view/list.py +++ b/tryton/gui/window/view_form/view/list.py @@ -75,8 +75,8 @@ class AdaptModelGroup(GenericTreeModel): self.row_inserted(path, iter_) if record.children_group(self.children_field): self.row_has_child_toggled(path, iter_) - if (record.parent and - record.group is not self.group): + if (record.parent + and record.group is not self.group): path = record.parent.get_index_path(self.group) iter_ = self.get_iter(path) self.row_has_child_toggled(path, iter_) diff --git a/tryton/gui/window/view_form/view/list_gtk/editabletree.py b/tryton/gui/window/view_form/view/list_gtk/editabletree.py index d06a9789e0..8c2c6956f8 100644 --- a/tryton/gui/window/view_form/view/list_gtk/editabletree.py +++ b/tryton/gui/window/view_form/view/list_gtk/editabletree.py @@ -214,7 +214,8 @@ class EditableTreeView(TreeView): break GLib.idle_add(self.set_cursor, path, col, None, True) return - if ((self.view.screen.pre_validate + if (( + self.view.screen.pre_validate and not record.pre_validate()) or (not self.view.screen.parent and not record.save())): diff --git a/tryton/gui/window/win_import.py b/tryton/gui/window/win_import.py index e00514a0e6..409f84d0e6 100644 --- a/tryton/gui/window/win_import.py +++ b/tryton/gui/window/win_import.py @@ -98,8 +98,9 @@ class WinImport(WinCSV): if self.model1.get_value(child, 0) is None: prefix_field = self.model1.get_value(iter, 1) name, model = self.fields[prefix_field] - self.model_populate(self._get_fields(model), iter, prefix_field + - '/', name + '/') + self.model_populate( + self._get_fields(model), iter, + prefix_field + '/', name + '/') self.model1.remove(child) def sig_autodetect(self, widget=None): diff --git a/tryton/jsonrpc.py b/tryton/jsonrpc.py index 3ab0d70acd..ceca6e909d 100644 --- a/tryton/jsonrpc.py +++ b/tryton/jsonrpc.py @@ -218,8 +218,8 @@ class Transport(xmlrpc.client.SafeTransport): peercert = None def format_hash(value): - return reduce(lambda x, y: x + y[1].upper() + - ((y[0] % 2 and y[0] + 1 < len(value)) and ':' or ''), + return reduce(lambda x, y: x + y[1].upper() + + ((y[0] % 2 and y[0] + 1 < len(value)) and ':' or ''), enumerate(value), '') return format_hash(hashlib.sha1(peercert).hexdigest()) except (socket.error, ssl.SSLError, ssl.CertificateError): diff --git a/tryton/tests/test_common_domain_parser.py b/tryton/tests/test_common_domain_parser.py index 25bbd4a7f7..51287b3713 100644 --- a/tryton/tests/test_common_domain_parser.py +++ b/tryton/tests/test_common_domain_parser.py @@ -365,7 +365,8 @@ class DomainParserTestCase(TestCase): (untimezoned_date(dt.datetime(2002, 12, 4)), dt.date(2002, 12, 4).strftime('%x')), (untimezoned_date(dt.datetime(2002, 12, 4, 12, 30)), - dt.datetime(2002, 12, 4, 12, 30).strftime('"%x %H:%M:%S"')), + dt.datetime(2002, 12, 4, 12, 30).strftime( + '"%x %H:%M:%S"')), (False, ''), (None, ''), ): diff --git a/tryton/tests/test_common_selection.py b/tryton/tests/test_common_selection.py index 1d1947af27..11cb2ba4b9 100644 --- a/tryton/tests/test_common_selection.py +++ b/tryton/tests/test_common_selection.py @@ -15,4 +15,3 @@ class SelectionTestCase(TestCase): self.assertEqual(freeze_value('foo'), 'foo') self.assertEqual( freeze_value({'foo': {'bar': 42}}), (('foo', (('bar', 42),)),)) - diff --git a/tryton/translate.py b/tryton/translate.py index f26333fbb2..6c6a2fffdd 100644 --- a/tryton/translate.py +++ b/tryton/translate.py @@ -86,10 +86,8 @@ _LOCALE2WIN32 = { 'ga': 'Scottish Gaelic', 'gl_ES': 'Galician_Spain', 'gu': 'Gujarati_India', - 'he_IL': 'Hebrew', 'he_IL': 'Hebrew_Israel', 'hi_IN': 'Hindi', - 'hi_IN': 'Hindi', 'hr_HR': 'Croatian', 'hu_HU': 'Hungarian', 'hu': 'Hungarian_Hungary',