How to use the cookiecutter.repository.is_repo_url 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_is_repo_url.py View on Github external
def test_is_repo_url_for_remote_urls(remote_repo_url):
    """Verify is_repo_url works."""
    assert is_repo_url(remote_repo_url) is True
github cookiecutter / cookiecutter / tests / repository / test_is_repo_url.py View on Github external
def test_is_repo_url_for_local_urls(local_repo_url):
    """Verify is_repo_url works."""
    assert is_repo_url(local_repo_url) is False
github cookiecutter / cookiecutter / tests / repository / test_is_repo_url.py View on Github external
def test_expand_abbreviations():
    template = 'gh:audreyr/cookiecutter-pypackage'

    # This is not a valid repo url just yet!
    # First `repository.expand_abbreviations` needs to translate it
    assert is_repo_url(template) is False

    expanded_template = expand_abbreviations(template, BUILTIN_ABBREVIATIONS)
    assert is_repo_url(expanded_template) is True
github awslabs / aws-sam-cli / samcli / lib / init / arbitrary_project.py View on Github external
cookiecutter.exception.CookiecutterException if download failed for some reason
    """

    LOG.debug("Downloading project from %s to %s", location, output_dir)

    # Don't prompt ever
    no_input = True

    # Expand abbreviations in URL such as gh:awslabs/aws-sam-cli
    location = repository.expand_abbreviations(location, config.BUILTIN_ABBREVIATIONS)

    # If this is a zip file, download and unzip into output directory
    if repository.is_zip_file(location):
        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
cookiecutter.exception.CookiecutterException if download failed for some reason
    """

    LOG.debug("Downloading project from %s to %s", location, output_dir)

    # Don't prompt ever
    no_input = True

    # Expand abbreviations in URL such as gh:awslabs/aws-sam-cli
    location = repository.expand_abbreviations(location, config.BUILTIN_ABBREVIATIONS)

    # If this is a zip file, download and unzip into output directory
    if repository.is_zip_file(location):
        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 / lib / init / arbitrary_project.py View on Github external
# Don't prompt ever
    no_input = True

    # Expand abbreviations in URL such as gh:awslabs/aws-sam-cli
    location = repository.expand_abbreviations(location, config.BUILTIN_ABBREVIATIONS)

    # If this is a zip file, download and unzip into output directory
    if repository.is_zip_file(location):
        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
# Don't prompt ever
    no_input = True

    # Expand abbreviations in URL such as gh:awslabs/aws-sam-cli
    location = repository.expand_abbreviations(location, config.BUILTIN_ABBREVIATIONS)

    # If this is a zip file, download and unzip into output directory
    if repository.is_zip_file(location):
        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 associatedpress / datakit-project / datakit_project / utils.py View on Github external
def template_type(template):
    status = 'local directory'
    if re.match(r'(gh|hg):', template):
        status = 'remote alias'
    if is_repo_url(template):
        status = 'url'
    return status
github beeware / briefcase / src / briefcase / commands / base.py View on Github external
def update_cookiecutter_cache(self, template: str, branch='master'):
        """
        Ensure that we have a current checkout of a template path.

        If the path is a local path, use the path as is.

        If the path is a URL, look for a local cache; if one exists, update it,
        including checking out the required branch.

        :param template: The template URL or path.
        :param branch: The template branch to use. Default: ``master``
        :return: The path to the cached template. This may be the originally
            provided path if the template was a file path.
        """
        if is_repo_url(template):
            # The app template is a repository URL.
            #
            # When in `no_input=True` mode, cookiecutter deletes and reclones
            # a template directory, rather than updating the existing repo.
            #
            # Look for a cookiecutter cache of the template; if one exists,
            # try to update it using git. If no cache exists, or if the cache
            # directory isn't a git directory, or git fails for some reason,
            # fall back to using the specified template directly.
            try:
                cached_template = cookiecutter_cache_path(template)
                repo = self.git.Repo(cached_template)
                try:
                    # Attempt to update the repository
                    remote = repo.remote(name='origin')
                    remote.fetch()