| 397 | |
| 398 | |
| 399 | def prepare_py_release( |
| 400 | context: Context, package: PackageInfo |
| 401 | ) -> Callable[[bool], None]: |
| 402 | twine_username = os.getenv("PYPI_USERNAME") |
| 403 | twine_password = os.getenv("PYPI_PASSWORD") |
| 404 | |
| 405 | if not (twine_password and twine_username): |
| 406 | msg = "PYPI_USERNAME and PYPI_PASSWORD environment variables must be set" |
| 407 | raise Exit(msg) |
| 408 | |
| 409 | for build_dir_name in ["build", "dist"]: |
| 410 | build_dir_path = Path.cwd() / build_dir_name |
| 411 | if build_dir_path.exists(): |
| 412 | rmtree(str(build_dir_path)) |
| 413 | |
| 414 | with context.cd(package.path): |
| 415 | context.run("hatch build") |
| 416 | |
| 417 | def publish(dry_run: bool): |
| 418 | with context.cd(package.path): |
| 419 | context.run("twine check dist/*") |
| 420 | |
| 421 | if dry_run: |
| 422 | return |
| 423 | |
| 424 | context.run( |
| 425 | "twine upload dist/*", |
| 426 | env={ |
| 427 | "TWINE_USERNAME": twine_username, |
| 428 | "TWINE_PASSWORD": twine_password, |
| 429 | }, |
| 430 | ) |
| 431 | |
| 432 | return publish |
| 433 | |
| 434 | |
| 435 | def install_hatch_project(context: Context, path: Path) -> None: |