-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import subprocess | ||
import os | ||
|
||
# Define the shell command as a multi-line string | ||
shell_command = """ | ||
cat << EOF > .env | ||
TEST_VAR=123 | ||
EOF | ||
""" | ||
|
||
# Execute the shell command | ||
|
||
|
||
import fire | ||
class Exp: | ||
def run(self): | ||
subprocess.run(shell_command, shell=True, check=True) | ||
|
||
def test_env(self): | ||
# NOTE: | ||
# If you only source the variables | ||
# - It will fail; | ||
# | ||
# You have to use following methods to make it works | ||
# 1) source the env | ||
# if [ -f .env ]; then | ||
# # Export each variable in the .env file | ||
# export $(grep -v '^#' .env | xargs) | ||
# fi | ||
# 2) use dotenv | ||
# dotenv run -- python app.py | ||
print(os.environ["TEST_VAR"]) | ||
|
||
if __name__ == "__main__": | ||
fire.Fire(Exp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters