-
-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature add support for env variables #286
Merged
sansyrox
merged 10 commits into
sparckles:main
from
Shending-Help:Feature-Add-support-for-Env-variables
Oct 6, 2022
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
32f99c5
define root ar definitions.py
Shending-Help 27a0159
file detector, parser and setting vars
Shending-Help 81581f6
Delete hello_robyn.py
Shending-Help 8d177a2
Delete configuration.conf
Shending-Help aea9a24
name, functions are now testable, var overrides?
Shending-Help dbf9297
testing files
Shending-Help c8d4005
pathlib instead of os, moving consts, logging
Shending-Help 270cc39
calling the load_vars() automatically, checking for robyn.env first
Shending-Help 7dc9975
fixing the load_vars() call
Shending-Help 1ec134f
calling the load_vars() function in the constructor
Shending-Help File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -14,3 +14,6 @@ dist/ | |
|
||
# python venv | ||
venv | ||
robyn.code-workspace | ||
hello_robyn.py | ||
robyn.env |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os | ||
import logging | ||
from pathlib import Path | ||
|
||
|
||
|
||
# Path to the root of the project | ||
ROOT_DIR = Path(__file__).parent.parent | ||
|
||
# Path to the environment variables | ||
CONFIG_PATH = ROOT_DIR / 'robyn.env' | ||
|
||
#set the logger that will log the environment variables imported from robyn.env and the ones already set | ||
logger = logging.getLogger(__name__) | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
# parse the configuration file returning a list of tuples (key, value) containing the environment variables | ||
def parser(config_path=CONFIG_PATH): | ||
"""Parse the configuration file""" | ||
if config_path.exists(): | ||
with open(config_path, 'r') as f: | ||
for line in f: | ||
if line.startswith('#'): | ||
continue | ||
yield line.strip().split('=') | ||
|
||
|
||
# check for the environment variables set in cli and if not set them | ||
def load_vars(variables = None): | ||
"""Main function""" | ||
|
||
variables = parser() | ||
|
||
if variables is None: | ||
return | ||
|
||
for var in variables: | ||
if var[0] in os.environ: | ||
logger.info(f" Variable {var[0]} already set") | ||
continue | ||
else: | ||
os.environ[var[0]]=var[1] | ||
logger.info(f" Variable {var[0]} set to {var[1]}") | ||
|
||
|
||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing before we can proceed with the tests,
self.load_var
isNone
. So, we can just call theload_vars()
function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay I changed that