def main()

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


def main(package_name: str, version_suffix: str, output_dir: str, package_versions: dict):
    if package_name == "autorest.python":
        versionVariableName = "generatorVersion"
        tarball_prefix = "autorest-python"
    elif package_name == "typespec-python":
        versionVariableName = "emitterVersion"
        tarball_prefix = "azure-tools-typespec-python"
    else:
        print(f"Invalid package name: {package_name}")
        exit(1)

    package_dir = root_dir / Path("packages") / package_name

    currentVersion = call(
        "node -pe \"require('./package.json').version\"", capture_output=True, cwd=package_dir
    ).strip()

    if version_suffix:
        newVersion = f"{currentVersion}{version_suffix}"

        # Update version
        call(f'npm version "{newVersion}" --no-workspaces-update', cwd=package_dir)
        call("git add package.json", cwd=package_dir)
    else:
        newVersion = currentVersion

    print(f"Building version {newVersion}")

    package_versions[package_name] = newVersion

    if pipeline_build:
        # Update version variable
        print(f"##vso[task.setvariable variable={versionVariableName};isOutput=true]{newVersion}")

    # Build project
    call("pnpm run build")

    # Check version mismatch
    call("pnpm check-version-mismatch")

    call(f'pnpm pack --pack-destination "{output_dir}"', cwd=package_dir)

    tarball_path = output_dir / f"{tarball_prefix}-{newVersion}.tgz"

    call(f'pnpm install "{ tarball_path }" -w --verbose')

    call(f"git restore .")