How to use the twine.cli function in twine

To help you get started, we’ve selected a few twine 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 pypa / twine / tests / test_cli.py View on Github external
def test_catches_enoent():
    with pytest.raises(SystemExit):
        cli.dispatch(["non-existent-command"])
github pypa / twine / tests / test_register.py View on Github external
def test_values_from_env(monkeypatch):
    """Test calling main via cli"""

    def none_register(*args, **settings_kwargs):
        pass

    replaced_register = pretend.call_recorder(none_register)
    monkeypatch.setattr(register, "register", replaced_register)
    testenv = {
        "TWINE_USERNAME": "pypiuser",
        "TWINE_PASSWORD": "pypipassword",
        "TWINE_CERT": "/foo/bar.crt",
    }
    with helpers.set_env(**testenv):
        cli.dispatch(["register", helpers.WHEEL_FIXTURE])
    register_settings = replaced_register.calls[0].args[0]
    assert "pypipassword" == register_settings.password
    assert "pypiuser" == register_settings.username
    assert "/foo/bar.crt" == register_settings.cacert
github pypa / twine / tests / test_integration.py View on Github external
def test_pypi_upload(sampleproject_dist):
    command = [
        "upload",
        "--repository-url",
        "https://test.pypi.org/legacy/",
        "--username",
        "__token__",
        "--password",
        twine_sampleproject_token,
        str(sampleproject_dist),
    ]
    cli.dispatch(command)
github pypa / twine / twine / __main__.py View on Github external
def _format_error(message: str) -> str:
    pre_style, post_style = "", ""
    if not cli.args.no_color:
        colorama.init()
        pre_style, post_style = colorama.Fore.RED, colorama.Style.RESET_ALL

    return f"{pre_style}{message}{post_style}"
github pypa / twine / twine / __main__.py View on Github external
def main() -> Any:
    try:
        result = cli.dispatch(sys.argv[1:])
    except requests.HTTPError as exc:
        status_code = exc.response.status_code
        status_phrase = http.HTTPStatus(status_code).phrase
        result = (
            f"{exc.__class__.__name__}: {status_code} {status_phrase} "
            f"from {exc.response.url}\n"
            f"{exc.response.reason}"
        )
    except exceptions.TwineException as exc:
        result = f"{exc.__class__.__name__}: {exc.args[0]}"

    return _format_error(result) if isinstance(result, str) else result
github pypa / twine / twine / __main__.py View on Github external
def main():
    try:
        return cli.dispatch(sys.argv[1:])
    except (exceptions.TwineException, requests.HTTPError) as exc:
        return "{}: {}".format(exc.__class__.__name__, exc.args[0])
github wbond / ocspbuilder / dev / release.py View on Github external
print(tag_error.decode('utf-8').rstrip(), file=sys.stderr)
        print('Error looking for current git tag', file=sys.stderr)
        return False

    if len(tag) == 0:
        print('No git tag found on HEAD', file=sys.stderr)
        return False

    tag = tag.decode('ascii').strip()

    setuptools.sandbox.run_setup(
        setup_file,
        ['sdist', 'bdist_wheel', '--universal']
    )

    twine.cli.dispatch(['upload', 'dist/%s-%s*' % (package_name, tag)])

    setuptools.sandbox.run_setup(
        setup_file,
        ['clean']
    )
github pypa / twine / twine / repository.py View on Github external
def _make_user_agent_string() -> str:
        from twine import cli

        dependencies = cli.list_dependencies_and_versions()
        user_agent_string = (
            user_agent.UserAgentBuilder("twine", twine.__version__)
            .include_extras(dependencies)
            .include_implementation()
            .build()
        )

        return cast(str, user_agent_string)