Source code for pyscaffold.extensions.pre_commit

# -*- coding: utf-8 -*-
Extension that generates configuration files for Yelp `pre-commit`_.

.. _pre-commit:
from __future__ import absolute_import

from ..templates import pre_commit_config
from ..api import Extension
from ..api import helpers

[docs]class PreCommit(Extension): """Generate pre-commit configuration file"""
[docs] def activate(self, actions): """Activate extension Args: actions (list): list of actions to perform Returns: list: updated list of actions """ return self.register( actions, self.add_files, after='define_structure')
[docs] def add_files(self, struct, opts): """Add .pre-commit-config.yaml file to structure Args: struct (dict): project representation as (possibly) nested :obj:`dict`. opts (dict): given options, see :obj:`create_project` for an extensive list. Returns: struct, opts: updated project representation and options """ files = { '.pre-commit-config.yaml': ( pre_commit_config(opts), helpers.NO_OVERWRITE ), } return helpers.merge(struct, {opts['project']: files}), opts