Skip to content

Commit 01ff700

Browse files
rose edit: license and lint (#2998)
* update license headers * remove invalid shebang * remove Python 2 object inheritance * lint: fix B009 * lint: fix C403 * lint: fix C416 * lint: fix SIM102 * lint: fix C414 * lint: fix SIM105 * lint: fix C419 * lint: fix C405 * lint: fix B010
1 parent 3904d46 commit 01ff700

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+200
-402
lines changed

metomi/rose/apps/rose_ana.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def buffer_to_db(self, reporter=None):
167167
self.statement_buffer = []
168168

169169

170-
class AnalysisTask(object, metaclass=abc.ABCMeta):
170+
class AnalysisTask(metaclass=abc.ABCMeta):
171171
"""Base class for an analysis task.
172172
173173
All custom user tasks should inherit from this class and override

metomi/rose/config_editor/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
# -----------------------------------------------------------------------------
3-
# Copyright (C) 2012-2020 British Crown (Met Office) & Contributors.
4-
#
1+
# Copyright (C) British Crown (Met Office) & Contributors.
52
# This file is part of Rose, a framework for meteorological suites.
63
#
74
# Rose is free software: you can redistribute it and/or modify

metomi/rose/config_editor/data.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
# -----------------------------------------------------------------------------
3-
# Copyright (C) 2012-2020 British Crown (Met Office) & Contributors.
4-
#
1+
# Copyright (C) British Crown (Met Office) & Contributors.
52
# This file is part of Rose, a framework for meteorological suites.
63
#
74
# Rose is free software: you can redistribute it and/or modify
@@ -51,7 +48,7 @@
5148
)
5249

5350

54-
class VarData(object):
51+
class VarData:
5552
"""Stores past, present, and missing variables."""
5653

5754
def __init__(self, v_map, latent_v_map, save_v_map, latent_save_v_map):
@@ -105,7 +102,7 @@ def get_var(self, section, option, save=False, skip_latent=False):
105102
return None
106103

107104

108-
class SectData(object):
105+
class SectData:
109106
"""Stores past, present, and missing sections."""
110107

111108
def __init__(
@@ -145,7 +142,7 @@ def get_sect(self, section, save=False, skip_latent=False):
145142
return None
146143

147144

148-
class ConfigData(object):
145+
class ConfigData:
149146
"""Stores information about a configuration."""
150147

151148
def __init__(
@@ -177,7 +174,7 @@ def __init__(
177174
self.is_preview = is_preview
178175

179176

180-
class ConfigDataManager(object):
177+
class ConfigDataManager:
181178
"""Loads the information from the various configurations."""
182179

183180
def __init__(
@@ -1196,10 +1193,9 @@ def load_ignored_data(self, config_name):
11961193
metomi.rose.config_editor
11971194
.WARNING_TYPE_USER_IGNORED
11981195
)
1199-
val = getattr(
1200-
metomi.rose.config_editor,
1201-
"WARNING_USER_NOT_TRIGGER_IGNORED",
1202-
)
1196+
val = (
1197+
metomi.rose.config_editor
1198+
).WARNING_USER_NOT_TRIGGER_IGNORED
12031199
node_inst.warning.update({key: val})
12041200
else:
12051201
# Doc table: I_u -> I_t -> optional

metomi/rose/config_editor/data_helper.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
# -----------------------------------------------------------------------------
3-
# Copyright (C) 2012-2020 British Crown (Met Office) & Contributors.
4-
#
1+
# Copyright (C) British Crown (Met Office) & Contributors.
52
# This file is part of Rose, a framework for meteorological suites.
63
#
74
# Rose is free software: you can redistribute it and/or modify
@@ -27,7 +24,7 @@
2724
REC_ELEMENT_SECTION = re.compile(r"^(.*)\((.+)\)$")
2825

2926

30-
class ConfigDataHelper(object):
27+
class ConfigDataHelper:
3128

3229
def __init__(self, data, util):
3330
self.data = data
@@ -42,10 +39,10 @@ def get_config_has_unsaved_changes(self, config_name):
4239
save_sections = config_data.sections.get_all(
4340
save=True, skip_latent=True
4441
)
45-
now_set = set([v.to_hashable() for v in variables])
46-
save_set = set([v.to_hashable() for v in save_vars])
47-
now_sect_set = set([s.to_hashable() for s in sections])
48-
save_sect_set = set([s.to_hashable() for s in save_sections])
42+
now_set = {v.to_hashable() for v in variables}
43+
save_set = {v.to_hashable() for v in save_vars}
44+
now_sect_set = {s.to_hashable() for s in sections}
45+
save_sect_set = {s.to_hashable() for s in save_sections}
4946
return (
5047
config_name not in self.data.saved_config_names
5148
or now_set ^ save_set
@@ -249,7 +246,7 @@ def get_sections_from_namespace(self, namespace):
249246
ns_metadata = self.data.namespace_meta_lookup.get(namespace, {})
250247
sections = ns_metadata.get("sections", [])
251248
if sections:
252-
return [s for s in sections]
249+
return list(sections)
253250
base, subsp = self.util.split_full_ns(self.data, namespace)
254251
ns_section = subsp.replace("/", ":")
255252
if ns_section in self.data.config[base].sections.now:

metomi/rose/config_editor/keywidget.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
# -----------------------------------------------------------------------------
3-
# Copyright (C) 2012-2020 British Crown (Met Office) & Contributors.
4-
#
1+
# Copyright (C) British Crown (Met Office) & Contributors.
52
# This file is part of Rose, a framework for meteorological suites.
63
#
74
# Rose is free software: you can redistribute it and/or modify
@@ -446,13 +443,12 @@ def _set_show_title(self, should_show_title):
446443
"""Set the display of a variable title instead of the name."""
447444
if not self.my_variable.name:
448445
return False
449-
if should_show_title:
450-
if metomi.rose.META_PROP_TITLE in self.meta:
451-
title_string = self._get_metadata_formatting(
452-
metomi.rose.META_PROP_TITLE
453-
)
454-
if title_string != self.entry.get_text():
455-
return self.entry.set_text(title_string)
446+
if should_show_title and metomi.rose.META_PROP_TITLE in self.meta:
447+
title_string = self._get_metadata_formatting(
448+
metomi.rose.META_PROP_TITLE
449+
)
450+
if title_string != self.entry.get_text():
451+
return self.entry.set_text(title_string)
456452
if self.entry.get_text() != self.my_variable.name:
457453
self.entry.set_text(self.my_variable.name)
458454

@@ -543,9 +539,8 @@ def _handle_enter(self, event_box):
543539
if (
544540
metomi.rose.META_PROP_HELP in self.meta
545541
or metomi.rose.META_PROP_URL in self.meta
546-
):
547-
if isinstance(self.entry, Gtk.Label):
548-
self._set_underline(self.entry, underline=True)
542+
) and isinstance(self.entry, Gtk.Label):
543+
self._set_underline(self.entry, underline=True)
549544
return False
550545

551546
def _set_underline(self, label, underline=False):

metomi/rose/config_editor/main.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
# -----------------------------------------------------------------------------
3-
# Copyright (C) 2012-2020 British Crown (Met Office) & Contributors.
4-
#
1+
# Copyright (C) British Crown (Met Office) & Contributors.
52
# This file is part of Rose, a framework for meteorological suites.
63
#
74
# Rose is free software: you can redistribute it and/or modify
@@ -76,9 +73,10 @@
7673
import metomi.rose.opt_parse
7774
import metomi.rose.resource
7875
import metomi.rose.macros
76+
import contextlib
7977

8078

81-
class MainController(object):
79+
class MainController:
8280
"""The main controller class.
8381
8482
Call with a configuration directory and/or a dict of
@@ -916,7 +914,7 @@ def make_page(self, namespace_name):
916914
)
917915
# Related pages
918916
see_also = ""
919-
sections = [s for s in ns_metadata.get("sections", [])]
917+
sections = list(ns_metadata.get("sections", []))
920918
for section_name in [s for s in sections if s.startswith("namelist")]:
921919
no_num_name = metomi.rose.macro.REC_ID_STRIP_DUPL.sub(
922920
"", section_name
@@ -1867,7 +1865,7 @@ def get_found_page_and_id(self, expression, start_page):
18671865
current_name = self.util.split_full_ns(self.data, current_ns)[0]
18681866
ns_cmp = lambda x, y: (y == current_ns) - (x == current_ns)
18691867
name_cmp = lambda x, y: (y == current_name) - (x == current_name)
1870-
config_keys = sorted(list(self.data.config.keys()))
1868+
config_keys = sorted(self.data.config.keys())
18711869
config_keys.sort(key=cmp_to_key(name_cmp))
18721870
for config_name in config_keys:
18731871
config_data = self.data.config[config_name]
@@ -1890,7 +1888,7 @@ def get_found_page_and_id(self, expression, start_page):
18901888
if reg_find(variable.name) or reg_find(variable.value):
18911889
found_ns_vars.setdefault(ns, [])
18921890
found_ns_vars[ns].append(variable)
1893-
ns_list = sorted(list(found_ns_vars.keys()))
1891+
ns_list = sorted(found_ns_vars.keys())
18941892
ns_list.sort(key=cmp_to_key(ns_cmp))
18951893
for ns in ns_list:
18961894
variables = found_ns_vars[ns]
@@ -1968,10 +1966,8 @@ def perform_undo(self, redo_mode_on=False):
19681966
action = stack_item.action
19691967
node = stack_item.node
19701968
node_id = None
1971-
try:
1969+
with contextlib.suppress(AttributeError, KeyError):
19721970
node_id = node.metadata["id"]
1973-
except (AttributeError, KeyError):
1974-
pass
19751971
# We need to handle namespace and metadata changes
19761972
if node_id is None:
19771973
# Not a variable or section
@@ -1998,7 +1994,7 @@ def perform_undo(self, redo_mode_on=False):
19981994
and not node_is_section
19991995
):
20001996
page = self.view_page(namespace, node_id)
2001-
redo_items = [x for x in self.redo_stack]
1997+
redo_items = list(self.redo_stack)
20021998
if stack_item.undo_args:
20031999
args = list(stack_item.undo_args)
20042000
for i, arg_item in enumerate(args):
@@ -2237,7 +2233,7 @@ def main():
22372233
if opts.conf_dir:
22382234
os.chdir(opts.conf_dir)
22392235
path = os.getcwd()
2240-
name_set = set([metomi.rose.SUB_CONFIG_NAME, metomi.rose.TOP_CONFIG_NAME])
2236+
name_set = {metomi.rose.SUB_CONFIG_NAME, metomi.rose.TOP_CONFIG_NAME}
22412237
while True:
22422238
if set(os.listdir(path)) & name_set:
22432239
break

metomi/rose/config_editor/menu.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
# -----------------------------------------------------------------------------
3-
# Copyright (C) 2012-2020 British Crown (Met Office) & Contributors.
4-
#
1+
# Copyright (C) British Crown (Met Office) & Contributors.
52
# This file is part of Rose, a framework for meteorological suites.
63
#
74
# Rose is free software: you can redistribute it and/or modify
@@ -42,7 +39,7 @@
4239
from functools import cmp_to_key
4340

4441

45-
class MenuBar(object):
42+
class MenuBar:
4643
"""Generate the menu bar, using the GTK UIManager.
4744
4845
Parses the settings in 'ui_config_string'. Connection of buttons is done
@@ -491,7 +488,7 @@ def add_macro(
491488
config_item.get_submenu().prepend(all_item)
492489

493490

494-
class MainMenuHandler(object):
491+
class MainMenuHandler:
495492
"""Handles signals from the main menu and tool bar."""
496493

497494
def __init__(
@@ -651,7 +648,7 @@ def load_page_menu(self, menubar, add_menuitem, current_page):
651648
def load_macro_menu(self, menubar):
652649
"""Refresh the menu dealing with custom macro launches."""
653650
menubar.clear_macros()
654-
config_keys = sorted(list(self.data.config.keys()))
651+
config_keys = sorted(self.data.config.keys())
655652
for config_name in config_keys:
656653
image = self.data.helper.get_icon_path_for_config(config_name)
657654
macros = self.data.config[config_name].macros

metomi/rose/config_editor/menuwidget.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
# -----------------------------------------------------------------------------
3-
# Copyright (C) 2012-2020 British Crown (Met Office) & Contributors.
4-
#
1+
# Copyright (C) British Crown (Met Office) & Contributors.
52
# This file is part of Rose, a framework for meteorological suites.
63
#
74
# Rose is free software: you can redistribute it and/or modify
@@ -219,9 +216,8 @@ def _set_hover_over(self, variable):
219216
for err, err_info in list(variable.error.items()):
220217
hover_string += "(" + err + "): " + err_info + "\n"
221218
hover_string = hover_string.rstrip("\n")
222-
if self.is_ghost:
223-
if not variable.error:
224-
hover_string = metomi.rose.config_editor.VAR_MENU_TIP_LATENT
219+
if self.is_ghost and not variable.error:
220+
hover_string = metomi.rose.config_editor.VAR_MENU_TIP_LATENT
225221
self.hover_text = hover_string
226222
self.button.set_tooltip_text(self.hover_text)
227223
self.button.show()

metomi/rose/config_editor/nav_controller.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
# -----------------------------------------------------------------------------
3-
# Copyright (C) 2012-2020 British Crown (Met Office) & Contributors.
4-
#
1+
# Copyright (C) British Crown (Met Office) & Contributors.
52
# This file is part of Rose, a framework for meteorological suites.
63
#
74
# Rose is free software: you can redistribute it and/or modify
@@ -23,7 +20,7 @@
2320
import metomi.rose.config_editor
2421

2522

26-
class NavTreeManager(object):
23+
class NavTreeManager:
2724
"""This controls the navigation namespace tree structure."""
2825

2926
def __init__(self, data, util, reporter, tree_trigger_update):

metomi/rose/config_editor/nav_panel.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
# -----------------------------------------------------------------------------
3-
# Copyright (C) 2012-2020 British Crown (Met Office) & Contributors.
4-
#
1+
# Copyright (C) British Crown (Met Office) & Contributors.
52
# This file is part of Rose, a framework for meteorological suites.
63
#
74
# Rose is free software: you can redistribute it and/or modify
@@ -279,13 +276,12 @@ def _set_title_markup(self, column, cell, model, r_iter, index):
279276
title = metomi.rose.config_editor.TITLE_PAGE_PREVIEW_MARKUP.format(
280277
title
281278
)
282-
if latent_status:
283-
if self._get_is_latent_sub_tree(model, r_iter):
284-
title = (
285-
metomi.rose.config_editor.TITLE_PAGE_LATENT_MARKUP.format(
286-
title
287-
)
279+
if latent_status and self._get_is_latent_sub_tree(model, r_iter):
280+
title = (
281+
metomi.rose.config_editor.TITLE_PAGE_LATENT_MARKUP.format(
282+
title
288283
)
284+
)
289285
if ignored_status:
290286
title = metomi.rose.config_editor.TITLE_PAGE_IGNORED_MARKUP.format(
291287
ignored_status, title

0 commit comments

Comments
 (0)