diff --git a/loopy/__init__.py b/loopy/__init__.py index 73a02479d705b74936097a87746baa83e5495de9..b6c2d15c26b47b8b667ffd8dc74ec10945cc802f 100644 --- a/loopy/__init__.py +++ b/loopy/__init__.py @@ -276,6 +276,9 @@ def set_options(kernel, *args, **kwargs): new_opt = kernel.options.copy() if kwargs: + from loopy.options import _apply_legacy_map, Options + kwargs = _apply_legacy_map(Options._legacy_options_map, kwargs) + for key, val in six.iteritems(kwargs): if not hasattr(new_opt, key): raise ValueError("unknown option '%s'" % key) diff --git a/loopy/options.py b/loopy/options.py index ef225b98b58baa7a1d7ec8034f7538f39d29f05f..a19afdaca8a4d14bcdf21397d1ea2d7fdd5a1a82 100644 --- a/loopy/options.py +++ b/loopy/options.py @@ -23,6 +23,7 @@ THE SOFTWARE. """ +import six from pytools import Record import re @@ -32,6 +33,27 @@ class _ColoramaStub(object): return "" +def _apply_legacy_map(lmap, kwargs): + result = {} + + for name, val in six.iteritems(kwargs): + try: + new_name, translator = lmap[name] + except KeyError: + new_name = name + else: + if name in result: + raise TypeError("may not pass a value for both '%s' and '%s'" + % (name, new_name)) + + if translator is not None: + val = translator(val) + + result[new_name] = val + + return result + + class Options(Record): """ Unless otherwise specified, these options are Boolean-valued @@ -91,7 +113,7 @@ class Options(Record): Accepts a file name as a value. Writes to ``sys.stdout`` if none is given. - .. attribute:: highlight_wrapper + .. attribute:: disable_wrapper_highlight Use syntax highlighting in :attr:`write_wrapper`. @@ -125,6 +147,14 @@ class Options(Record): .. attribute:: disable_global_barriers """ + _legacy_options_map = { + "cl_build_options": ("build_options", None), + "write_cl": ("write_code", None), + "highlight_cl": ("disable_code_highlight", lambda val: not val), + "highlight_wrapper": ("disable_wrapper_highlight", lambda val: not val), + "edit_cl": ("edit_code", None), + } + def __init__( # All Boolean flags in here should default to False for the # string-based interface of make_options (below) to make sense. @@ -132,70 +162,38 @@ class Options(Record): # All defaults are further required to be False when cast to bool # for the update() functionality to work. - self, - - annotate_inames=False, - trace_assignments=False, - trace_assignment_values=False, - ignore_boostable_into=False, - - skip_arg_checks=False, no_numpy=False, return_dict=False, - write_wrapper=False, highlight_wrapper=False, - write_code=None, disable_code_highlight=None, - edit_code=None, build_options=None, - allow_terminal_colors=None, - disable_global_barriers=False, - - # legacy - write_cl=None, - highlight_cl=None, - cl_build_options=None, - edit_cl=None, - ): - - if build_options is None: - build_options = cl_build_options - if build_options is None: - build_options = [] - - if write_code is None: - write_code = write_cl - if write_code is None: - write_code = False - - if disable_code_highlight is None and highlight_cl is not None: - disable_code_highlight = not highlight_cl - if disable_code_highlight is None: - disable_code_highlight = False - - if edit_code is None: - edit_code = edit_cl - if edit_code is None: - edit_code = False - - if allow_terminal_colors is None: - try: - import colorama # noqa - except ImportError: - allow_terminal_colors = False - else: - allow_terminal_colors = True + self, **kwargs): + + kwargs = _apply_legacy_map(self._legacy_options_map, kwargs) + + try: + import colorama # noqa + except ImportError: + allow_terminal_colors_def = False + else: + allow_terminal_colors_def = True Record.__init__( self, - annotate_inames=annotate_inames, - trace_assignments=trace_assignments, - trace_assignment_values=trace_assignment_values, - ignore_boostable_into=ignore_boostable_into, - - skip_arg_checks=skip_arg_checks, no_numpy=no_numpy, - return_dict=return_dict, - write_wrapper=write_wrapper, highlight_wrapper=highlight_wrapper, - write_code=write_code, disable_code_highlight=disable_code_highlight, - edit_code=edit_code, build_options=build_options, - allow_terminal_colors=allow_terminal_colors, - disable_global_barriers=disable_global_barriers, + annotate_inames=kwargs.get("annotate_inames", False), + trace_assignments=kwargs.get("trace_assignments", False), + trace_assignment_values=kwargs.get("trace_assignment_values", False), + ignore_boostable_into=kwargs.get("ignore_boostable_into", False), + + skip_arg_checks=kwargs.get("skip_arg_checks", False), + no_numpy=kwargs.get("no_numpy", False), + return_dict=kwargs.get("return_dict", False), + write_wrapper=kwargs.get("write_wrapper", False), + highlight_wrapper=kwargs.get("highlight_wrapper", False), + write_code=kwargs.get("write_code", False), + disable_code_highlight=kwargs.get("disable_code_highlight", False), + edit_code=kwargs.get("edit_code", False), + build_options=kwargs.get("build_options", []), + allow_terminal_colors=kwargs.get("allow_terminal_colors", + allow_terminal_colors_def), + disable_global_barriers=kwargs.get("disable_global_barriers", + False), ) # {{{ legacy compatibility diff --git a/loopy/version.py b/loopy/version.py index aa3e7abee41a05595985df574da52c024b52dcb5..0b56284bbbf68b92bbab368de3c30a997724b29e 100644 --- a/loopy/version.py +++ b/loopy/version.py @@ -32,4 +32,4 @@ except ImportError: else: _islpy_version = islpy.version.VERSION_TEXT -DATA_MODEL_VERSION = "v44-islpy%s" % _islpy_version +DATA_MODEL_VERSION = "v48-islpy%s" % _islpy_version