Sunday, 30 December 2018

Register customizable environment variables with anaconda

By running conda env export > environment.yml I can make it easy for people to clone and replicate my environment.

But I also need them to set some environment variables. When using PHP (Laravel), I had a .env file (ignored by git) where the user could put account details, passwords, tokens etc. A file .env.example was provided allowing the user to see the required values. So I implemented that with a python class but it was frowned upon in r/learnpython ("...to give your user rope to hang themselves with").

After further reading I did a file activate in my project root

export \
    GITHUB_ACCESS_TOKEN="your value goes here", 
    BENNO="test",

So the user now just runs source activate to register the variables. But I see several problems

  • activate is committed, how to protect the user from accidently publishing this?
  • After exiting my conda environment, the variable GITHUB_ACCESS_TOKEN was still active. I expected the conda environment to keep a separate set of environment variables?
  • The user have to run the activate script every time they relaunch the terminal
  • The activation script does not support windows usage
  • The principle still is the same as the .env.example in PHP which is bad??

To summarize I would like a clean simple way to store both the dependencies AND customizable environment vars, allowing for simple installation for conda users, but also if possible a wider set of python users. What are some good practices here? Can I somehow list the vars in environment.yml?



from Register customizable environment variables with anaconda

No comments:

Post a Comment