How to use the briefcase.exceptions.NetworkFailure function in briefcase

To help you get started, we’ve selected a few briefcase 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 beeware / briefcase / tests / commands / create / test_install_app_support_package.py View on Github external
def test_offline_install(create_command, myapp, support_path):
    "If the computer is offline, an error is raised"
    # Hardcode the support package URL for test purposes
    create_command._support_package_url = 'https://example.com/path/to/support.zip'

    create_command.download_url = mock.MagicMock(
        side_effect=requests_exceptions.ConnectionError
    )

    # Installing while offline raises an error
    with pytest.raises(NetworkFailure):
        create_command.install_app_support_package(myapp)
github beeware / briefcase / tests / commands / create / test_generate_app_template.py View on Github external
def test_offline_repo_template(create_command, myapp):
    "If the user is offline the first time a repo template is requested, an error is raised"
    # There won't be a cookiecutter cache, so there won't be
    # a repo path (yet).
    create_command.git.Repo.side_effect = git_exceptions.NoSuchPathError

    # Calling cookiecutter on a repository while offline causes a CalledProcessError
    create_command.cookiecutter.side_effect = subprocess.CalledProcessError(
        cmd=['git', 'clone', 'https://github.com/beeware/briefcase-tester-dummy-template.git'],
        returncode=128
    )

    # Generating the template under these conditions raises an error
    with pytest.raises(NetworkFailure):
        create_command.generate_app_template(myapp)

    # App's template has been set
    assert myapp.template == 'https://github.com/beeware/briefcase-tester-dummy-template.git'

    # Cookiecutter was invoked with the expected template name and context.
    create_command.cookiecutter.assert_called_once_with(
        'https://github.com/beeware/briefcase-tester-dummy-template.git',
        no_input=True,
        checkout=create_command.python_version_tag,
        output_dir=str(create_command.platform_path),
        extra_context=full_context({
            'template': 'https://github.com/beeware/briefcase-tester-dummy-template.git',
        })
github beeware / briefcase / src / briefcase / commands / create.py View on Github external
try:
            # 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 / create.py View on Github external
support_package_url = self.support_package_url
                print("Using support package {support_package_url}".format(
                    support_package_url=support_package_url
                ))

            if support_package_url.startswith('https://') or support_package_url.startswith('http://'):
                # Download the support file, caching the result
                # in the user's briefcase support cache directory.
                support_filename = self.download_url(
                    url=support_package_url,
                    download_path=Path.home() / '.briefcase' / 'support'
                )
            else:
                support_filename = support_package_url
        except requests_exceptions.ConnectionError:
            raise NetworkFailure('downloading support package')

        try:
            print("Unpacking support package...")
            support_path = self.support_path(app)
            support_path.mkdir(parents=True, exist_ok=True)
            self.shutil.unpack_archive(
                str(support_filename),
                extract_dir=str(support_path)
            )
        except shutil.ReadError:
            raise InvalidSupportPackage(support_filename.name)
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))