#1240 Feature/local extensions

Open mwesterhof

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -4,8 +4,11 @@
Loading
4 4
The code in this module is also a good example of how to use Cookiecutter as a
5 5
library rather than a script.
6 6
"""
7 +
from __future__ import unicode_literals
8 +
from copy import copy
7 9
import logging
8 10
import os
11 +
import sys
9 12
10 13
from cookiecutter.config import get_user_config
11 14
from cookiecutter.exceptions import InvalidModeException
@@ -72,15 +75,17 @@
Loading
72 75
        password=password,
73 76
        directory=directory,
74 77
    )
78 +
    import_patch = _patch_import_path_for_repo(repo_dir)
75 79
76 80
    template_name = os.path.basename(os.path.abspath(repo_dir))
77 81
78 82
    if replay:
79 -
        if isinstance(replay, bool):
80 -
            context = load(config_dict['replay_dir'], template_name)
81 -
        else:
82 -
            path, template_name = os.path.split(os.path.splitext(replay)[0])
83 -
            context = load(path, template_name)
83 +
        with import_patch:
84 +
            if isinstance(replay, bool):
85 +
                context = load(config_dict['replay_dir'], template_name)
86 +
            else:
87 +
                path, template_name = os.path.split(os.path.splitext(replay)[0])
88 +
                context = load(path, template_name)
84 89
    else:
85 90
        context_file = os.path.join(repo_dir, 'cookiecutter.json')
86 91
        logger.debug('context_file is %s', context_file)
@@ -93,7 +98,8 @@
Loading
93 98
94 99
        # prompt the user to manually configure at the command line.
95 100
        # except when 'no-input' flag is set
96 -
        context['cookiecutter'] = prompt_for_config(context, no_input)
101 +
        with import_patch:
102 +
            context['cookiecutter'] = prompt_for_config(context, no_input)
97 103
98 104
        # include template dir or url in the context dict
99 105
        context['cookiecutter']['_template'] = template
@@ -104,17 +110,31 @@
Loading
104 110
        dump(config_dict['replay_dir'], template_name, context)
105 111
106 112
    # Create project from local context and project template.
107 -
    result = generate_files(
108 -
        repo_dir=repo_dir,
109 -
        context=context,
110 -
        overwrite_if_exists=overwrite_if_exists,
111 -
        skip_if_file_exists=skip_if_file_exists,
112 -
        output_dir=output_dir,
113 -
        accept_hooks=accept_hooks,
114 -
    )
113 +
    with import_patch:
114 +
        result = generate_files(
115 +
            repo_dir=repo_dir,
116 +
            context=context,
117 +
            overwrite_if_exists=overwrite_if_exists,
118 +
            skip_if_file_exists=skip_if_file_exists,
119 +
            output_dir=output_dir,
120 +
            accept_hooks=accept_hooks,
121 +
        )
115 122
116 123
    # Cleanup (if required)
117 124
    if cleanup:
118 125
        rmtree(repo_dir)
119 126
120 127
    return result
128 +
129 +
130 +
class _patch_import_path_for_repo:
131 +
    def __init__(self, repo_dir):
132 +
        self._repo_dir = repo_dir
133 +
        self._path = None
134 +
135 +
    def __enter__(self):
136 +
        self._path = copy(sys.path)
137 +
        sys.path.append(self._repo_dir)
138 +
139 +
    def __exit__(self, type, value, traceback):
140 +
        sys.path = self._path

@@ -8,6 +8,7 @@
Loading
8 8
import sys
9 9
10 10
from cookiecutter.prompt import read_user_yes_no
11 +
from jinja2.ext import Extension
11 12
12 13
logger = logging.getLogger(__name__)
13 14
@@ -105,3 +106,15 @@
Loading
105 106
            return False
106 107
107 108
        sys.exit()
109 +
110 +
111 +
def simple_filter(filter_function):
112 +
    """Decorate a function to wrap it in a simplified jinja2 extension."""
113 +
114 +
    class SimpleFilterExtension(Extension):
115 +
        def __init__(self, environment):
116 +
            super(SimpleFilterExtension, self).__init__(environment)
117 +
            environment.filters[filter_function.__name__] = filter_function
118 +
119 +
    SimpleFilterExtension.__name__ = filter_function.__name__
120 +
    return SimpleFilterExtension

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
cookiecutter 100.00%
__main__.py 100.00%
Project Totals (19 files) 100.00%
Loading