Esempio n. 1
0
def get_repository_from_config(
        config_file: str,
        repository: str,
        repository_url: Optional[str] = None) -> RepositoryConfig:
    # Get our config from, if provided, command-line values for the
    # repository name and URL, or the .pypirc file

    if repository_url:
        _validate_repository_url(repository_url)
        # prefer CLI `repository_url` over `repository` or .pypirc
        return {
            "repository": repository_url,
            "username": None,
            "password": None,
        }
    try:
        return get_config(config_file)[repository]
    except KeyError:
        msg = ("Missing '{repo}' section from the configuration file\n"
               "or not a complete URL in --repository-url.\n"
               "Maybe you have an out-dated '{cfg}' format?\n"
               "more info: "
               "https://packaging.python.org/specifications/pypirc/\n").format(
                   repo=repository, cfg=config_file)
        raise exceptions.InvalidConfiguration(msg)
Esempio n. 2
0
def get_repository_from_config(
        config_file: str,
        repository: str,
        repository_url: Optional[str] = None) -> RepositoryConfig:
    # Get our config from, if provided, command-line values for the
    # repository name and URL, or the .pypirc file
    if repository_url and "://" in repository_url:
        # prefer CLI `repository_url` over `repository` or .pypirc
        return {
            "repository": repository_url,
            "username": None,
            "password": None,
        }
    if repository_url and "://" not in repository_url:
        raise exceptions.UnreachableRepositoryURLDetected(
            "Repository URL {} has no protocol. Please add "
            "'https://'. \n".format(repository_url))
    try:
        return get_config(config_file)[repository]
    except KeyError:
        msg = ("Missing '{repo}' section from the configuration file\n"
               "or not a complete URL in --repository-url.\n"
               "Maybe you have a out-dated '{cfg}' format?\n"
               "more info: "
               "https://docs.python.org/distutils/packageindex.html#pypirc\n"
               ).format(repo=repository, cfg=config_file)
        raise exceptions.InvalidConfiguration(msg)
Esempio n. 3
0
def get_repository_from_config(
    config_file: str,
    repository: str,
    repository_url: Optional[str] = None,
) -> RepositoryConfig:
    """Get repository config command-line values or the .pypirc file."""
    # Prefer CLI `repository_url` over `repository` or .pypirc
    if repository_url:
        _validate_repository_url(repository_url)
        return {
            "repository": repository_url,
            "username": None,
            "password": None,
        }

    try:
        return get_config(config_file)[repository]
    except OSError as exc:
        raise exceptions.InvalidConfiguration(str(exc))
    except KeyError:
        raise exceptions.InvalidConfiguration(
            f"Missing '{repository}' section from {config_file}.\n"
            f"More info: https://packaging.python.org/specifications/pypirc/ ")
Esempio n. 4
0
def test_exception_handling(monkeypatch):
    replaced_dispatch = pretend.raiser(exceptions.InvalidConfiguration("foo"))
    monkeypatch.setattr(cli, "dispatch", replaced_dispatch)
    assert dunder_main.main() == "InvalidConfiguration: foo"
Esempio n. 5
0
def test_exception_handling(monkeypatch):
    replaced_dispatch = pretend.raiser(exceptions.InvalidConfiguration('foo'))
    monkeypatch.setattr(dunder_main, 'dispatch', replaced_dispatch)
    assert dunder_main.main() == 'InvalidConfiguration: foo'