Fix flake8 errors and warnings

We add the flake8 configuration used so we ensure everyone uses the same.
We remove the usage of __all__ for non public API.
When possible, we rationalize the class name according to its __name__ and module.

issue9082
review297061002
This commit is contained in:
Cédric Krier committed 2020-03-01 12:33:54 +01:00
1 parent f50fa74c14
commit 49a54593ce
30 files changed
+88 -61

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
[flake8]
ignore=E123,E124,E126,E128,W503
+2 -1
View File
@@ -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:
+1 -1
View File
@@ -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
+3 -1
View File
@@ -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]
+28 -4
View File
@@ -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]
-14
View File
@@ -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()
+2 -2
View File
@@ -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)
+4 -3
View File
@@ -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,
+1 -1
View File
@@ -413,7 +413,7 @@ if __name__ == '__main__':
<div><br/></div>
<div align="center">Center</div>
<div><font face="sans" size="6">Sans6<font color="#ff0000">red</font></font></div>
<div align="center"> <b> <i><u>Title</u></i> </b></div>'''
<div align="center"> <b> <i><u>Title</u></i> </b></div>''' # noqa: E501
win = Gtk.Window()
win.set_title('HTMLTextBuffer')
+3 -2
View File
@@ -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
+3 -1
View File
@@ -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]
+3 -1
View File
@@ -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]
+1 -1
View File
@@ -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
+3 -1
View File
@@ -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]
+2 -2
View File
@@ -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,
+2
View File
@@ -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]
+3 -2
View File
@@ -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 = []
@@ -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]
+4 -4
View File
@@ -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
@@ -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
@@ -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()
@@ -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 *
@@ -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
+2 -2
View File
@@ -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_)
@@ -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())):
+3 -2
View File
@@ -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):
+2 -2
View File
@@ -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):
+2 -1
View File
@@ -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, ''),
):
-1
View File
@@ -15,4 +15,3 @@ class SelectionTestCase(TestCase):
self.assertEqual(freeze_value('foo'), 'foo')
self.assertEqual(
freeze_value({'foo': {'bar': 42}}), (('foo', (('bar', 42),)),))
-2
View File
@@ -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',