How to use the cookiecutter.utils.work_in function in cookiecutter

To help you get started, we’ve selected a few cookiecutter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cookiecutter / cookiecutter / tests / test_more_cookiecutters.py View on Github external
def fin_remove_additional_dirs():
        with utils.work_in(config.DEFAULT_CONFIG['cookiecutters_dir']):
            if os.path.isdir('cookiecutter-pypackage'):
                utils.rmtree('cookiecutter-pypackage')
        if os.path.isdir('boilerplate'):
            utils.rmtree('boilerplate')
    request.addfinalizer(fin_remove_additional_dirs)
github cookiecutter / cookiecutter / tests / test_utils.py View on Github external
def test_work_in():
        with utils.work_in(ch_to):
            test_dir = os.path.join(cwd, ch_to).replace("/", os.sep)
            assert test_dir == os.getcwd()
            raise TestException()
github cookiecutter / cookiecutter / tests / test_examples.py View on Github external
def tearDown(self):
        with utils.work_in(config.DEFAULT_CONFIG['cookiecutters_dir']):
            if os.path.isdir('cookiecutter-pypackage'):
                utils.rmtree('cookiecutter-pypackage')
        if os.path.isdir('boilerplate'):
            utils.rmtree('boilerplate')
        super(TestExamplesRepoArg, self).tearDown()
github cookiecutter / cookiecutter / tests / test_hooks.py View on Github external
def test_find_hooks(self):
        '''Getting the list of all defined hooks'''
        repo_path = 'tests/test-hooks/'
        with utils.work_in(repo_path):
            self.assertEqual({
                'pre_gen_project': os.path.abspath('hooks/pre_gen_project.py'),
                'post_gen_project': os.path.abspath('hooks/post_gen_project.sh'),
            }, hooks.find_hooks())
github cookiecutter / cookiecutter / tests / test_hooks.py View on Github external
def test_public_run_hook(self):
        '''Execute hook from specified template in specified output directory'''
        tests_dir = os.path.join(self.repo_path, 'input{{hooks}}')
        with utils.work_in(self.repo_path):
            hooks.run_hook('pre_gen_project', tests_dir)
            self.assertTrue(os.path.isfile(os.path.join(tests_dir, 'python_pre.txt')))

            hooks.run_hook('post_gen_project', tests_dir)
            self.assertTrue(os.path.isfile(os.path.join(tests_dir, 'shell_post.txt')))
github cookiecutter / cookiecutter / cookiecutter / generate.py View on Github external
project_dir = os.path.abspath(project_dir)
    logger.debug('Project directory is {}'.format(project_dir))

    # if we created the output directory, then it's ok to remove it
    # if rendering fails
    delete_project_on_failure = output_directory_created

    _run_hook_from_repo_dir(
        repo_dir,
        'pre_gen_project',
        project_dir,
        context,
        delete_project_on_failure
    )

    with work_in(template_dir):
        env.loader = FileSystemLoader('.')

        for root, dirs, files in os.walk('.'):
            # We must separate the two types of dirs into different lists.
            # The reason is that we don't want ``os.walk`` to go through the
            # unrendered directories, since they will just be copied.
            copy_dirs = []
            render_dirs = []

            for d in dirs:
                d_ = os.path.normpath(os.path.join(root, d))
                # We check the full path, because that's how it can be
                # specified in the ``_copy_without_render`` setting, but
                # we store just the dir name
                if is_copy_only_path(d_, context):
                    copy_dirs.append(d)