def __init__(self, defaults=None, **kw): self.include_path = [] if defaults: if isinstance(defaults, CompilationOptions): defaults = defaults.__dict__ else: defaults = default_options options = dict(defaults) options.update(kw) # let's assume 'default_options' contains a value for most known compiler options # and validate against them unknown_options = set(options) - set(default_options) # ignore valid options that are not in the defaults unknown_options.difference_update(['include_path']) if unknown_options: message = "got unknown compilation option%s, please remove: %s" % ( 's' if len(unknown_options) > 1 else '', ', '.join(unknown_options)) raise ValueError(message) directive_defaults = get_directive_defaults() directives = dict(options['compiler_directives']) # copy mutable field # check for invalid directives unknown_directives = set(directives) - set(directive_defaults) if unknown_directives: message = "got unknown compiler directive%s: %s" % ( 's' if len(unknown_directives) > 1 else '', ', '.join(unknown_directives)) raise ValueError(message) options['compiler_directives'] = directives if directives.get('np_pythran', False) and not options['cplus']: import warnings warnings.warn("C++ mode forced when in Pythran mode!") options['cplus'] = True if 'language_level' in directives and 'language_level' not in kw: options['language_level'] = directives['language_level'] elif not options.get('language_level'): options['language_level'] = directive_defaults.get( 'language_level') if 'formal_grammar' in directives and 'formal_grammar' not in kw: options['formal_grammar'] = directives['formal_grammar'] if options['cache'] is True: options['cache'] = os.path.join(Utils.get_cython_cache_dir(), 'compiler') self.__dict__.update(options)
def __init__(self, defaults=None, **kw): self.include_path = [] if defaults: if isinstance(defaults, CompilationOptions): defaults = defaults.__dict__ else: defaults = default_options options = dict(defaults) options.update(kw) # let's assume 'default_options' contains a value for most known compiler options # and validate against them unknown_options = set(options) - set(default_options) # ignore valid options that are not in the defaults unknown_options.difference_update(['include_path']) if unknown_options: message = "got unknown compilation option%s, please remove: %s" % ( 's' if len(unknown_options) > 1 else '', ', '.join(unknown_options)) raise ValueError(message) directive_defaults = get_directive_defaults() directives = dict(options['compiler_directives']) # copy mutable field # check for invalid directives unknown_directives = set(directives) - set(directive_defaults) if unknown_directives: message = "got unknown compiler directive%s: %s" % ( 's' if len(unknown_directives) > 1 else '', ', '.join(unknown_directives)) raise ValueError(message) options['compiler_directives'] = directives if directives.get('np_pythran', False) and not options['cplus']: import warnings warnings.warn("C++ mode forced when in Pythran mode!") options['cplus'] = True if 'language_level' in directives and 'language_level' not in kw: options['language_level'] = directives['language_level'] elif not options.get('language_level'): options['language_level'] = directive_defaults.get('language_level') if 'formal_grammar' in directives and 'formal_grammar' not in kw: options['formal_grammar'] = directives['formal_grammar'] if options['cache'] is True: options['cache'] = os.path.join(Utils.get_cython_cache_dir(), 'compiler') self.__dict__.update(options)