def main()

in eng/scripts/initialize.py [0:0]


def main(update_to_latest_typespec: bool, build_artifacts_path: Path) -> None:
    # Install global dependencies
    call("npm install -g pnpm@9.5.0")
    call("npm install -g autorest")
    call("npm install -g @typespec/compiler")

    if build_artifacts_path:
        # copy package.json and pnpm-lock.yaml from build artifacts
        lock_files_dir = Path(build_artifacts_path) / "lock-files"
        if lock_files_dir.exists():
            print(f"Copying package.json and pnpm-lock.yaml from {lock_files_dir}")
            copy(lock_files_dir / "package.json", root_dir)
            copy(lock_files_dir / "pnpm-lock.yaml", root_dir)
            copy(
                lock_files_dir / "emitter/package.json",
                root_dir / "packages/typespec-python",
            )

        # Pnpm install
        call("pnpm install --frozen-lockfile")
    else:
        if update_to_latest_typespec:
            # Update typespec packages to latest dev version
            call(
                "npx -y @azure-tools/typespec-bump-deps@0.4.0 --use-peer-ranges package.json packages/typespec-python/package.json"
            )

            # Pnpm install
            call("pnpm install --no-frozen-lockfile")
        else:
            # No updates to package.json or lock files, just use what's in the repository
            call("pnpm install --frozen-lockfile")

        artifact_staging_dir = os.environ.get("BUILD_ARTIFACTSTAGINGDIRECTORY")
        if artifact_staging_dir:
            lock_files_dir = Path(artifact_staging_dir)

            # copy package.json and pnpm-lock.yaml to build artifacts
            copy(root_dir / "package.json", lock_files_dir)
            copy(root_dir / "pnpm-lock.yaml", lock_files_dir)
            copy(
                root_dir / "packages/typespec-python/package.json",
                lock_files_dir / "emitter",
            )

    # Pnpm list
    call("pnpm list -r")