()
Gets the project ID from the Cloud SDK.

    Returns:
        Optional[str]: The project ID.
Gets the project ID from the Cloud SDK.
Gets the project ID from the Cloud SDK .
def get_project_id():
    """Gets the project ID from the Cloud SDK.

    Returns:
        Optional[str]: The project ID.
    """
    if os.name == "nt":
        command = _CLOUD_SDK_WINDOWS_COMMAND
    else:
        command = _CLOUD_SDK_POSIX_COMMAND

    try:
        # Ignore the stderr coming from gcloud, so it won't be mixed into the output.
        # https://github.com/googleapis/google-auth-library-python/issues/673
        output = _run_subprocess_ignore_stderr((command,) + _CLOUD_SDK_CONFIG_COMMAND)
    except (subprocess.CalledProcessError, OSError, IOError):
        return None

    try:
        configuration = json.loads(output.decode("utf-8"))
    except ValueError:
        return None

    try:
        return configuration["configuration"]["properties"]["core"]["project"]
    except KeyError:
        return None
def get_project_id ( ) : if os . name == "nt" : command = _CLOUD_SDK_WINDOWS_COMMAND else : command = _CLOUD_SDK_POSIX_COMMAND try : # Ignore the stderr coming from gcloud, so it won't be mixed into the output. # https://github.com/googleapis/google-auth-library-python/issues/673 output = _run_subprocess_ignore_stderr ( ( command , ) + _CLOUD_SDK_CONFIG_COMMAND ) except ( subprocess . CalledProcessError , OSError , IOError ) : return None try : configuration = json . loads ( output . decode ( "utf-8" ) ) except ValueError : return None try : return configuration [ "configuration" ] [ "properties" ] [ "core" ] [ "project" ] except KeyError : return None