saulpw / aipl

Array-Inspired Pipeline Language
MIT License
119 stars 7 forks source link

AIPL reads env vars at time of import, not instantiation #59

Open dovinmu opened 1 year ago

dovinmu commented 1 year ago

I have a simple flask server that serves results from running AIPL scripts over HTTP. I have to load_dotenv() so it has access to API keys like OpenAI's. But if I do this (at server start) it doesn't have access:

from aipl import AIPL
load_dotenv()
aipl = AIPL()

instead I have to do this:

load_dotenv()
from aipl import AIPL
aipl = AIPL()
saulpw commented 1 year ago

Hm, I don't know why that would be! Nothing is calling os.getenv or pulling vars from os.environ at the toplevel, it all happens at the operator level. So it seems like it should work either way. Unless somehow importing os itself seals the environment even if it's not used.