Skip to content

chore: ♻️ load from .env.example if no other env found - #238

Open
lwjohnst86 wants to merge 2 commits into
mainfrom
chore/load-from-env-example
Open

lwjohnst86 wants to merge 2 commits into
mainfrom
chore/load-from-env-example

Conversation

@lwjohnst86

Copy link
Copy Markdown
Member

Description

To prevent an error about not finding the .env file (myself and Kris experienced).

Needs a quick review.

Checklist

  • Ran just run-all
  • (When relevant) Ran just build-package

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is this the error that Kris posted in a screenshot? If so, that appears to be from Quarto. Here is an older issue about it: quarto-dev/quarto-cli#9262 . Could we not solve it on the Quarto side? First check Quarto versions, then see if there are more recent mentions of the error, etc.

In any case, I don't think .env.example is ever meant to be loaded into the application even as a fallback. It's for documentation only. The idea is that everyone should copy/rename it and fill it out (if the env vars are not coming from the shared file). Also, here it overrides the real env vars coming from the real env files.

@lwjohnst86 lwjohnst86 Sep 22, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

She "fixed" it by renaming to .env. I can't remember how I fixed my issue, but I also had an issue because it was not able to load/use the env variables within the code, even if I didn't need the env for what I was doing. Do you have another solution to keep that for documentation but also will fix those errors?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what Kris did (renaming to .env) is how .env.example is supposed to be used.

That said, based on the Quarto issue I don't think this is intended behaviour from Quarto, so it would be nice to find where that is going wrong. Do you get it by running just run-all without a .env file? I haven't been able to recreate it with the latest Quarto version and with a fresh repo clone.

If your issue was different, I'm not sure about that without knowing the details.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used "fixed" in quotes because having to create an .env isn't a solution. It might be that her Quarto version is older. My issue came when trying to run pytask builds without an .env file present.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I honestly don't even remember what I did to fix it, so 🤷 I'll try to recreate the issue with a fresh clone.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, well, I think for the Quarto issue we should see if it can be recreated with the latest Quarto (I couldn't do it).

For the build.py issue, isn't that expected? It is hitting the API, so it tries to load the env vars.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if I'm running the code locally, I don't want the API key outside of GDK, nor do I want to pull any data. So some pytask build tasks (e.g. processing the metadata) should work without needing to be in GDK ☺️

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it to now fail because API key is wrong, not because it doesn't exist, which is what I was aiming for. We could probably do something clever and have an env var for remote vs local to bypass those API calls.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make some pytask tasks conditional on whether the API keys are there, but first I think it would be helpful to describe how exactly we want the pipeline to work on GenomeDK vs locally. For example, we decided not to commit the downloaded metadata, so that will not be available locally and so the processing task won't be able to run even if the download task is skipped.

If we eventually refactor the metadata processing and form splitting tasks to depend on raw-to-resource-map.csv, then we get around this metadata downloading problem. We will still have the same situation with downloading data, but that can't be processed locally anyway.

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Data development Sep 22, 2026
@lwjohnst86 lwjohnst86 changed the title chore: ♻️ load from .env.example chore: ♻️ load from .env.example if no other env found Sep 22, 2026
@lwjohnst86 lwjohnst86 moved this from In Progress to In Review in Data development Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make some pytask tasks conditional on whether the API keys are there, but first I think it would be helpful to describe how exactly we want the pipeline to work on GenomeDK vs locally. For example, we decided not to commit the downloaded metadata, so that will not be available locally and so the processing task won't be able to run even if the download task is skipped.

If we eventually refactor the metadata processing and form splitting tasks to depend on raw-to-resource-map.csv, then we get around this metadata downloading problem. We will still have the same situation with downloading data, but that can't be processed locally anyway.

First, env vars are loaded from the shared project folder on GenomeDK.
Then, they are overwritten by values from the local .env file (if this exists).
"""
load_dotenv(".env.example")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but I still don't see which problem is solved by this. I still think Kris' Quarto problem should be solved by looking at Quarto and it's not clear to me how this would solve it (does this code run before the Quarto command?).

As for the build pipeline, this makes the API keys exist, but they are still not correct, so as you said in the other comment, the download tasks still won't run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants