Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
pamelafox opened this issue Jul 3, 2024 · 3 comments
Open
1 task done

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

pamelafox opened this issue Jul 3, 2024 · 3 comments
Assignees
Milestone

Comments

@pamelafox
Copy link
Member

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.

@jongio jongio self-assigned this Jul 5, 2024
@jongio
Copy link
Member

jongio commented Jul 5, 2024

Options:

  1. Use azd env list like above
  2. Use .azure/config.json:
    • The default environment is listed in .azure/config.json in the defaultEnvironment property. You could build the path based on that. Read in that file, read the defaultEnvironment property, and build .azure/{defaultEnvironment}/.env.
  3. New azd command to add env vars to current shell: azd env set-context. You'd call it before your python call. azd env set-context && python app.py
  4. Add --query with JMESPath support.
  5. Publish azd libraries for each language that has utility functions like this.

@jongio
Copy link
Member

jongio commented Jul 8, 2024

Related: #1697

@pamelafox
Copy link
Member Author

Hm the jmespath would be the easiest add, I imagine, and is similar to Azure CLI SDK command args. I'm a little unsure about whether I'm going to run into the same issues as exporting if I were to do an azd set-context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants