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
7673import metomi .rose .opt_parse
7774import metomi .rose .resource
7875import 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
0 commit comments