Skip to content

pypi ¤

PyPI integration.

Functions:

reserve_pypi ¤

reserve_pypi(
    username: str, name: str, description: str
) -> None

Reserve a name on PyPI.

Parameters:

  • username (str) –

    Username on PyPI.

  • name (str) –

    Name to reserve.

  • description (str) –

    Description of the project on PyPI.

Source code in src/insiders/pypi.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
def reserve_pypi(
    username: An[str, Doc("Username on PyPI.")],
    name: An[str, Doc("Name to reserve.")],
    description: An[str, Doc("Description of the project on PyPI.")],
) -> None:
    """Reserve a name on PyPI."""
    with TemporaryDirectory(prefix="insiders-") as tmpdir:
        repo = Path(tmpdir, name)
        repo.mkdir()
        dist = repo / "dist"

        logger.info(f"Preparing package {name}, {description}")
        repo.joinpath("pyproject.toml").write_text(
            dedent(
                f"""
                [project]
                name = "{name}"
                version = "0.0.0"
                description = "{description} Available to sponsors only."
                authors = [{{name = "{_git_user_name()}", email = "{_git_user_email()}"}}]
                readme = "README.md"
                requires-python = ">=3.8"
                classifiers = ["Development Status :: 1 - Planning"]
                """,
            ).lstrip(),
        )

        repo.joinpath("README.md").write_text(
            dedent(
                f"""
                # {name}

                {description}

                This project is currently available to [sponsors](https://github.com/sponsors/{username}) only.
                See https://{username}.github.io/{name}/insiders.
                """,
            ).lstrip(),
        )

        logger.info("Building distributions")
        for distribution in ("sdist", "wheel"):
            with DefaultIsolatedEnv() as env:
                builder = ProjectBuilder.from_isolated_env(env, repo)
                env.install(builder.build_system_requires)
                with Capture.BOTH.here() as captured:
                    env.install(builder.get_requires_for_build(distribution))
                    builder.build(distribution, str(dist))
                log_captured(str(captured), level="debug", pkg="build")

        logger.info("Uploading distributions")
        with redirect_output_to_logging(stdout_level="debug"):
            upload(
                Settings(
                    non_interactive=True,
                    skip_existing=True,
                    username="__token__",
                    disable_progress_bar=True,
                    verbose=True,
                ),
                [str(file) for file in dist.iterdir()],
            )