def tidy_venv(st2_venv_path: Path) -> None:
    """Clean up and remove this script from the venv.

    Unfortunately, the way pants uses pex, this script ends up in the venv.
    """
    for path in (st2_venv_path / "lib").glob("python*"):
        script_path = path / "site-packages" / "packaging" / "build_st2_venv.py"
        if script_path.exists():
            script_path.unlink()

        script_path = path / "site-packages" / "__pex_executable__.py"
        if script_path.exists():
            script_path.unlink()

    # and remove the reference to this script
    main_path = st2_venv_path / "__main__.py"
    main_path.write_text(main_path.read_text().replace("__pex_executable__", ""))
Clean up and remove this script from the venv.

    Unfortunately, the way pants uses pex, this script ends up in the venv.
    
packaging/build_st2_venv.py