How to use the cookiecutter.exceptions.RepositoryNotFound 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 / repository / test_determine_repo_dir_clones_repo.py View on Github external
def test_repository_url_with_no_context_file(
        mocker, template_url, user_config_data):
    mocker.patch(
        'cookiecutter.repository.clone',
        return_value='tests/fake-repo-bad',
        autospec=True
    )

    with pytest.raises(exceptions.RepositoryNotFound) as err:
        repository.determine_repo_dir(
            template_url,
            abbreviations={},
            clone_to_dir=None,
            checkout=None,
            no_input=True
        )

    assert str(err.value) == (
        'A valid repository for "{}" could not be found in the following '
        'locations:\n{}'.format(
            template_url,
            'tests/fake-repo-bad',
        )
github awslabs / aws-sam-cli / tests / unit / local / init / test_arbitrary_project.py View on Github external
def test_must_fail_when_repo_not_found(self):
        location = str(Path("my", "folder"))

        with patch.object(repository, "unzip") as unzip_mock:
            unzip_mock.side_effect = RepositoryNotFound("repo")

            with self.assertRaises(ArbitraryProjectDownloadFailed):
                generate_non_cookiecutter_project(location, self.output_dir)
github cookiecutter / cookiecutter / tests / vcs / test_clone.py View on Github external
"""In `clone()`, repository not found errors should raise an
    appropriate exception.
    """
    # side_effect is set to an iterable here (and below),
    # because of a Python 3.4 unittest.mock regression
    # http://bugs.python.org/issue23661
    mocker.patch(
        'cookiecutter.vcs.subprocess.check_output',
        autospec=True,
        side_effect=[subprocess.CalledProcessError(
            -1, 'cmd', output=error_message
        )]
    )

    repository_url = 'https://github.com/hackebro/cookiedozer'
    with pytest.raises(exceptions.RepositoryNotFound) as err:
        vcs.clone(
            repository_url,
            clone_to_dir=clone_dir,
            no_input=True
        )

    assert str(err.value) == (
        'The repository {} could not be found, have you made a typo?'
    ).format(repository_url)
github cookiecutter / cookiecutter / tests / repository / test_determine_repository_should_use_local_repo.py View on Github external
def test_local_repo_typo(tmpdir):
    """An unknown local repository should raise a `RepositoryNotFound`
    exception.
    """
    template_path = os.path.join('tests', 'unknown-repo')
    with pytest.raises(exceptions.RepositoryNotFound) as err:
        repository.determine_repo_dir(
            template_path,
            abbreviations={},
            clone_to_dir=str(tmpdir),
            checkout=None,
            no_input=True
        )

    assert str(err.value) == (
        'A valid repository for "{}" could not be found in the following '
        'locations:\n{}'.format(
            template_path,
            '\n'.join([
                template_path,
                str(tmpdir / 'tests/unknown-repo')
            ]),
github awslabs / aws-sam-cli / samcli / lib / init / arbitrary_project.py View on Github external
LOG.debug("%s location is a zip file", location)
        download_fn = functools.partial(
            repository.unzip, zip_uri=location, is_url=repository.is_repo_url(location), no_input=no_input
        )

    # Else, treat it as a git/hg/ssh URL and try to clone
    elif repository.is_repo_url(location):
        LOG.debug("%s location is a source control repository", location)
        download_fn = functools.partial(repository.clone, repo_url=location, no_input=no_input)

    else:
        raise ArbitraryProjectDownloadFailed(msg=BAD_LOCATION_ERROR_MSG)

    try:
        return _download_and_copy(download_fn, output_dir)
    except exceptions.RepositoryNotFound:
        # Download failed because the zip or the repository was not found
        raise ArbitraryProjectDownloadFailed(msg=BAD_LOCATION_ERROR_MSG)
github awslabs / aws-sam-cli / samcli / local / init / arbitrary_project.py View on Github external
LOG.debug("%s location is a zip file", location)
        download_fn = functools.partial(
            repository.unzip, zip_uri=location, is_url=repository.is_repo_url(location), no_input=no_input
        )

    # Else, treat it as a git/hg/ssh URL and try to clone
    elif repository.is_repo_url(location):
        LOG.debug("%s location is a source control repository", location)
        download_fn = functools.partial(repository.clone, repo_url=location, no_input=no_input)

    else:
        raise ArbitraryProjectDownloadFailed(msg=BAD_LOCATION_ERROR_MSG)

    try:
        return _download_and_copy(download_fn, output_dir)
    except exceptions.RepositoryNotFound:
        # Download failed because the zip or the repository was not found
        raise ArbitraryProjectDownloadFailed(msg=BAD_LOCATION_ERROR_MSG)
github cookiecutter / cookiecutter / cookiecutter / repository.py View on Github external
no_input=no_input,
        )
        repository_candidates = [cloned_repo]
        cleanup = False
    else:
        repository_candidates = [
            template,
            os.path.join(clone_to_dir, template)
        ]
        cleanup = False

    for repo_candidate in repository_candidates:
        if repository_has_cookiecutter_json(repo_candidate):
            return repo_candidate, cleanup

    raise RepositoryNotFound(
        'A valid repository for "{}" could not be found in the following '
        'locations:\n{}'.format(
            template,
            '\n'.join(repository_candidates)
        )
github beeware / briefcase / src / briefcase / commands / create.py View on Github external
# Create the platform directory (if it doesn't already exist)
            output_path = self.bundle_path(app).parent
            output_path.mkdir(parents=True, exist_ok=True)
            # Unroll the template
            self.cookiecutter(
                str(cached_template),
                no_input=True,
                output_dir=str(output_path),
                checkout=self.python_version_tag,
                extra_context=extra_context
            )
        except subprocess.CalledProcessError:
            # Computer is offline
            # status code == 128 - certificate validation error.
            raise NetworkFailure("clone template repository")
        except cookiecutter_exceptions.RepositoryNotFound:
            # Either the template path is invalid,
            # or it isn't a cookiecutter template (i.e., no cookiecutter.json)
            raise InvalidTemplateRepository(app.template)
        except cookiecutter_exceptions.RepositoryCloneFailed:
            # Branch does not exist for python version
            raise TemplateUnsupportedVersion(self.python_version_tag)
github beeware / briefcase / src / briefcase / commands / new.py View on Github external
)

        try:
            # Unroll the new app template
            self.cookiecutter(
                str(cached_template),
                no_input=True,
                output_dir=str(self.base_path),
                checkout="v0.3",
                extra_context=context
            )
        except subprocess.CalledProcessError:
            # Computer is offline
            # status code == 128 - certificate validation error.
            raise NetworkFailure("clone template repository")
        except cookiecutter_exceptions.RepositoryNotFound:
            # Either the template path is invalid,
            # or it isn't a cookiecutter template (i.e., no cookiecutter.json)
            raise InvalidTemplateRepository(template)

        print("""
Application '{formal_name}' has been generated. To run your application, type:

    cd {app_name}
    briefcase dev
""".format(**context))
github cookiecutter / cookiecutter / cookiecutter / vcs.py View on Github external
try:
            subprocess.check_output(
                [repo_type, 'clone', repo_url],
                cwd=clone_to_dir,
                stderr=subprocess.STDOUT,
            )
            if checkout is not None:
                subprocess.check_output(
                    [repo_type, 'checkout', checkout],
                    cwd=repo_dir,
                    stderr=subprocess.STDOUT,
                )
        except subprocess.CalledProcessError as clone_error:
            output = clone_error.output.decode('utf-8')
            if 'not found' in output.lower():
                raise RepositoryNotFound(
                    'The repository {} could not be found, '
                    'have you made a typo?'.format(repo_url)
                )
            if any(error in output for error in BRANCH_ERRORS):
                raise RepositoryCloneFailed(
                    'The {} branch of repository {} could not found, '
                    'have you made a typo?'.format(checkout, repo_url)
                )
            raise

    return repo_dir