PyBites-Open-Source / eatlocal

This package helps users solve PyBites code challenges on their local machine.
MIT License
20 stars 9 forks source link

#27 new feature: add init mode #28

Closed pmayd closed 2 years ago

pmayd commented 2 years ago

I tried to add a new init command that makes the env vars obsolete, but please test this first on UNIX and MAC, as I am developing under Windows.

The idea is to replace the environment vars needed by eatlocal with a local .env file. As the tool can be installed via pip we cannot rely on a local .env in the repository. Instead, I choose to create a new file under .eatlocal/.env in the user home directory. pathlib's Path().home() makes sure that we have the correct user directory under all supported OS,

Now what is happening is the following: eatlocal init will ask the user for their username, password and local pybites repo. Once confirmed, it will store these values under .eatlocal/.env. Next time you run eatlocal, it will load these variables with dotenv_variables, not with dotenv_load so they are directly loaded as a dictionary and not stored as env vars in the system (which is only temporarily for the current session but still, we don't need this). So whenever the username or the local repository changes, the user can just run eatlocal init again.

When you try to run a command without init first, you will see the following two messages:

⚠ Could not find or read .eatlocal/.env in your home directory.
Please run eatlocal init first.
pmayd commented 2 years ago

@rhelmstedter if we want to do this, I have to update the REadme, too. BEcause we no longer need any env vars, so we can delete all the sections about setting env vars for different OS