def get_engine(project_id: str | None = None) -> Engine:
    """Get an Engine instance assuming some sensible defaults.

    This uses the environment variable GOOGLE_CLOUD_PROJECT for the Engine
    project_id, unless set explicitly. By using an environment variable,
    you can avoid hard-coding the project_id in shared code.

    If the environment variables are set, but incorrect, an authentication
    failure will occur when attempting to run jobs on the engine.

    Args:
        project_id: If set overrides the project id obtained from the
            google.auth.default().

    Returns:
        The Engine instance.

    Raises:
        OSError: If the environment variable GOOGLE_CLOUD_PROJECT is not set. This is actually
            an `EnvironmentError`, which by definition is an `OsError`.
    """
    service_args = {}
    if not project_id:
        credentials, project_id = google.auth.default()
        service_args['credentials'] = credentials
    if not project_id:
        raise EnvironmentError(
            'Unable to determine project id. Please set environment variable GOOGLE_CLOUD_PROJECT '
            'or configure default project with `gcloud set project <project_id>`.'
        )

    return Engine(project_id=project_id, service_args=service_args)
Get an Engine instance assuming some sensible defaults.

    This uses the environment variable GOOGLE_CLOUD_PROJECT for the Engine
    project_id, unless set explicitly. By using an environment variable,
    you can avoid hard-coding the project_id in shared code.

    If the environment variables are set, but incorrect, an authentication
    failure will occur when attempting to run jobs on the engine.

    Args:
        project_id: If set overrides the project id obtained from the
            google.auth.default().

    Returns:
        The Engine instance.

    Raises:
        OSError: If the environment variable GOOGLE_CLOUD_PROJECT is not set. This is actually
            an `EnvironmentError`, which by definition is an `OsError`.
    
cirq-google/cirq_google/engine/engine.py