Skip to content

[Issue] Make it easy to find azd env path #4067

@pamelafox

Description

@pamelafox

I want to easily get the azd env path, so that I can load that into my Python program's environments without doing an export. This is what I'm doing now:

def load_azd_env():
    """Get path to current azd env file and load file using python-dotenv"""
    result = subprocess.run("azd env list -o json", shell=True, capture_output=True, text=True)
    if result.returncode != 0:
        raise Exception("Error loading azd env")
    env_json = json.loads(result.stdout)
    env_file_path = None
    for entry in env_json:
        if entry["IsDefault"]:
            env_file_path = entry["DotEnvPath"]
    if not env_file_path:
        raise Exception("No default azd env file found")
    logger.info(f"Loading azd env from {env_file_path}")
    load_dotenv(env_file_path, override=True)

@vhvb1989 suggested that perhaps azd could make an environment variable for the current path.

Metadata

Metadata

Assignees

Labels

area/core-cliCLI commands, cmd/, internal/cmd/enhancementNew feature or improvement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions