Skip to content
Snippets Groups Projects
Commit 9194baa9 authored by David Fairbrother's avatar David Fairbrother
Browse files

Re #19493 Warn if config_file was not set.

parent 4d5c7ee6
No related branches found
No related tags found
No related merge requests found
......@@ -7,11 +7,9 @@ from isis_powder.routines import common, instrument_settings, yaml_parser
class Gem(AbstractInst):
def __init__(self, **kwargs):
basic_config_dict = yaml_parser.open_yaml_file_as_dictionary(kwargs.get("config_file", None))
self._inst_settings = instrument_settings.InstrumentSettings(
param_map=gem_param_mapping.attr_mapping, adv_conf_dict=gem_advanced_config.get_all_adv_variables(),
kwargs=kwargs, basic_conf_dict=basic_config_dict)
kwargs=kwargs)
super(Gem, self).__init__(user_name=self._inst_settings.user_name,
calibration_dir=self._inst_settings.calibration_dir,
......
......@@ -10,11 +10,9 @@ from isis_powder.pearl_routines import pearl_algs, pearl_output, pearl_advanced_
class Pearl(AbstractInst):
def __init__(self, **kwargs):
basic_config_dict = yaml_parser.open_yaml_file_as_dictionary(kwargs.get("config_file", None))
self._inst_settings = instrument_settings.InstrumentSettings(
param_map=pearl_param_mapping.attr_mapping, adv_conf_dict=pearl_advanced_config.get_all_adv_variables(),
basic_conf_dict=basic_config_dict, kwargs=kwargs)
kwargs=kwargs)
super(Pearl, self).__init__(user_name=self._inst_settings.user_name,
calibration_dir=self._inst_settings.calibration_dir,
......
......@@ -9,10 +9,9 @@ from isis_powder.polaris_routines import polaris_advanced_config, polaris_algs,
class Polaris(AbstractInst):
def __init__(self, **kwargs):
basic_config_dict = yaml_parser.open_yaml_file_as_dictionary(kwargs.get("config_file", None))
self._inst_settings = instrument_settings.InstrumentSettings(
param_map=polaris_param_mapping.attr_mapping, adv_conf_dict=polaris_advanced_config.variables,
basic_conf_dict=basic_config_dict, kwargs=kwargs)
kwargs=kwargs)
super(Polaris, self).__init__(user_name=self._inst_settings.user_name,
calibration_dir=self._inst_settings.calibration_dir,
......
from __future__ import (absolute_import, division, print_function)
from six import iteritems
from isis_powder.routines import yaml_parser
import warnings
# Have to patch warnings at runtime to not print the source code. This is even advertised as a 'feature' of
# the warnings library in the documentation: https://docs.python.org/3/library/warnings.html#warnings.showwarning
def warning_no_source(msg, *_):
def _warning_no_source(msg, *_):
return str(msg) + '\n'
warnings.formatwarning = warning_no_source
warnings.formatwarning = _warning_no_source
warnings.simplefilter('always', UserWarning)
class InstrumentSettings(object):
# Holds instance variables updated at runtime
def __init__(self, param_map, adv_conf_dict=None, basic_conf_dict=None, kwargs=None):
def __init__(self, param_map, adv_conf_dict=None, kwargs=None):
self._param_map = param_map
self._adv_config_dict = adv_conf_dict
self._basic_conf_dict = basic_conf_dict
self._kwargs = kwargs
config_file_path = kwargs.get("config_file", None)
if not config_file_path:
warnings.warn("No config file was specified. If one was meant to be used the path to a YAML config file"
" is set with the 'config_file' parameter.")
# Always do this so we have a known state of the internal variable
self._basic_conf_dict = yaml_parser.open_yaml_file_as_dictionary(config_file_path)
# We parse in the order advanced config, basic config (if specified), kwargs.
# This means that users can use the advanced config as a safe set of defaults, with their own preferences as
# the next layer which can override defaults and finally script arguments as their final override.
self._parse_attributes(dict_to_parse=adv_conf_dict)
self._parse_attributes(dict_to_parse=basic_conf_dict)
self._parse_attributes(dict_to_parse=self._basic_conf_dict)
self._parse_attributes(dict_to_parse=kwargs)
# __getattr__ is only called if the attribute was not set so we already know
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment