Ejemplo n.º 1
0
 def render_file(self, target, template, context=None, *, executable=False, override=False, force_python=False):
     with self.file(target, executable=executable, override=override) as f:
         content = format_file_content(self.render(template, context))
         if force_python or target.endswith(".py"):
             content, modified = yapf_api.FormatCode(content, filename=target)
         f.write(content)
         self._log_file(target, override, content)
Ejemplo n.º 2
0
 def render_file(self, target, template, context=None, *, executable=False, override=False, force_python=False):
     with self.file(target, executable=executable, override=override) as f:
         content = format_file_content(self.render(template, context))
         if force_python or target.endswith('.py'):
             content, modified = yapf_api.FormatCode(content, filename=target)
         f.write(content)
         self._log_file(target, override, content)
Ejemplo n.º 3
0
 def render_file_inline(self, target, template_string, context=None, override=False, force_python=False):
     with self.file(target, override=override) as f:
         content = format_file_content(Template(template_string).render(**(context or {})))
         if force_python or target.endswith('.py'):
             content, modified = yapf_api.FormatCode(
                 content, filename=target, style_config=settings.YAPF_STYLE_CONFIG
             )
         f.write(content)
         self._log_file(target, override, content)
Ejemplo n.º 4
0
 def render_file_inline(self, target, template_string, context=None, override=False, force_python=False):
     with self.file(target, override=override) as f:
         content = format_file_content(Template(template_string).render(**(context or {})))
         if force_python or target.endswith(".py"):
             content, modified = yapf_api.FormatCode(
                 content, filename=target, style_config=settings.YAPF_STYLE_CONFIG
             )
         f.write(content)
         self._log_file(target, override, content)
Ejemplo n.º 5
0
def read_configuration(dispatcher, filename, variables, features, files):
    config = ConfigurationRegistry()

    # monkey patch placeholders
    import medikit
    _listen, _pipeline, _require = medikit.listen, medikit.pipeline, medikit.require
    medikit.listen, medikit.pipeline, medikit.require = dispatcher.listen, config.pipeline, config.require

    # todo, move this in a configurable place
    with medikit.pipeline('release') as release:
        release.add(steps.Install())
        release.add(steps.BumpVersion())
        release.add(steps.Make('update-requirements'))
        release.add(steps.Make('clean install'))  # test docs
        release.add(steps.System('git add -p .'))
        release.add(steps.Commit('Release: {version}', tag=True))

    # read configuration
    with open(filename) as f:
        # TODO use runpy?
        code = compile(f.read(), filename, 'exec')
    ctx = {'listen': dispatcher.listen}
    exec(code, ctx)

    # restore old values
    medikit.listen, medikit.pipeline, medikit.require = _listen, _pipeline, _require

    for k in variables.keys():
        if k in ctx:
            variables[k] = ctx[k]

    for feature in DEFAULT_FEATURES:
        config.require(feature)

    # old, deprecated way ...
    for feature in set(ctx.pop('enable_features',
                               ())) - set(ctx.pop('disable_features', ())):
        config.require(feature)

    # current way ...
    features = features | set(config.keys())

    for k in files.keys():
        if k in ctx:
            files[k] = format_file_content(ctx[k])

    return variables, features, files, config
Ejemplo n.º 6
0
def read_configuration(dispatcher, filename, variables, features, files):
    config = ConfigurationRegistry()
    setup_default_pipelines(config)
    default_context = {'listen': dispatcher.listen}

    # monkey patch placeholders
    _listen, _pipeline, _require = medikit.listen, medikit.pipeline, medikit.require
    try:
        medikit.listen, medikit.pipeline, medikit.require = dispatcher.listen, config.pipeline, config.require
        context = runpy.run_path(filename, init_globals=default_context)
    finally:
        # restore old values
        medikit.listen, medikit.pipeline, medikit.require = _listen, _pipeline, _require

    for k in variables.keys():
        if k in context:
            variables[k] = context[k]

    for feature in DEFAULT_FEATURES:
        config.require(feature)

    # Deprecated: enabled and disabled features.
    enable_features, disable_features = context.pop('enable_features',
                                                    ()), context.pop(
                                                        'disable_features', ())
    if len(enable_features) or len(disable_features):
        with deprecated_feature(
                '0.5.0', '0.6.0',
                'Using "enable_features" and "disable_features"', 'require()'):
            for feature in set(enable_features) - set(disable_features):
                config.require(feature)

    # Better: required features.
    features = features | set(config.keys())

    for k in files.keys():
        if k in context:
            files[k] = format_file_content(context[k])

    return variables, features, files, config
Ejemplo n.º 7
0
def read_configuration(dispatcher, filename, variables, features, files):
    config = ConfigurationRegistry(dispatcher)
    setup_default_pipelines(config)
    default_context = {"listen": dispatcher.listen}

    # monkey patch placeholders
    _listen, _pipeline, _require = medikit.listen, medikit.pipeline, medikit.require
    try:
        medikit.listen, medikit.pipeline, medikit.require = dispatcher.listen, config.pipeline, config.require
        context = runpy.run_path(filename, init_globals=default_context)
    finally:
        # restore old values
        medikit.listen, medikit.pipeline, medikit.require = _listen, _pipeline, _require

    # Deprecated, but can be used for non-python projects (PACKAGE=...)
    variables = {k: context.get(k, v) for k, v in variables.items()}
    config.set_vars(**variables)

    for feature in DEFAULT_FEATURES:
        config.require(feature)

    # Deprecated: enabled and disabled features.
    enable_features, disable_features = context.pop("enable_features", ()), context.pop("disable_features", ())
    if len(enable_features) or len(disable_features):
        with deprecated_feature("0.5.0", "0.6.0", 'Using "enable_features" and "disable_features"', "require()"):
            for feature in set(enable_features) - set(disable_features):
                config.require(feature)

    # Better: required features.
    features = features | set(config.keys())

    for k in files.keys():
        if k in context:
            files[k] = format_file_content(context[k])

    return variables, features, files, config
Ejemplo n.º 8
0
def read_configuration(dispatcher, filename, variables, features, files):
    config = ConfigurationRegistry()
    setup_default_pipelines(config)
    default_context = {"listen": dispatcher.listen}

    # monkey patch placeholders
    _listen, _pipeline, _require = medikit.listen, medikit.pipeline, medikit.require
    try:
        medikit.listen, medikit.pipeline, medikit.require = dispatcher.listen, config.pipeline, config.require
        context = runpy.run_path(filename, init_globals=default_context)
    finally:
        # restore old values
        medikit.listen, medikit.pipeline, medikit.require = _listen, _pipeline, _require

    # Deprecated, but can be used for non-python projects (PACKAGE=...)
    variables = {k: context.get(k, v) for k, v in variables.items()}
    config.set_vars(**variables)

    for feature in DEFAULT_FEATURES:
        config.require(feature)

    # Deprecated: enabled and disabled features.
    enable_features, disable_features = context.pop("enable_features", ()), context.pop("disable_features", ())
    if len(enable_features) or len(disable_features):
        with deprecated_feature("0.5.0", "0.6.0", 'Using "enable_features" and "disable_features"', "require()"):
            for feature in set(enable_features) - set(disable_features):
                config.require(feature)

    # Better: required features.
    features = features | set(config.keys())

    for k in files.keys():
        if k in context:
            files[k] = format_file_content(context[k])

    return variables, features, files, config