-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
Add support for embedded variables #430
Open
henrikek
wants to merge
5
commits into
joke2k:main
Choose a base branch
from
ESSolutions:Add-support-for-embedded-variables
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add support for embedded variables #430
henrikek
wants to merge
5
commits into
joke2k:main
from
ESSolutions:Add-support-for-embedded-variables
Conversation
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
Hello and thank you for your feedback.
The interpolate=True flag does not solve the problem.
I suspect you tried setting environment variables directly in the OS? Then the OS will automatically translate variables, which is not the case when using an environment file.
The problem I have solved in my proposal for PR is the following:
# more test_env
BAR=FOO
PROXY=$BAR
VAR_1=prod
VAR_2=my_app_name
APP_LIB_DIR=/opt/${VAR_1}/extra_${VAR_2}_extra/lib
LIB_PATH=/home/username/.lib
GDAL_LIBRARY_PATH=$LIB_PATH/osgeo/gdal304.dll
# python
Python 3.10.8 (main, Nov 10 2022, 16:17:40) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>> import environ
>> env = environ.Env(interpolate=True)
>> env.read_env('test_env')
>> print(env.str('BAR'))
FOO
>> print(env.str('PROXY'))
FOO
>> print(env.str('VAR_1'))
prod
>> print(env.str('VAR_2'))
my_app_name
>> print(env.str('APP_LIB_DIR'))
/opt/${VAR_1}/extra_${VAR_2}_extra/lib
>> print(env.str('LIB_PATH'))
/home/username/.lib
>> print(env.str('GDAL_LIBRARY_PATH'))
Traceback (most recent call last):
File "/ESSArch/pd/python/lib/python3.10/site-packages/environ/environ.py", line 387, in get_value
value = self.ENVIRON[var_name]
File "/ESSArch/pd/python/lib/python3.10/os.py", line 680, in __getitem__
raise KeyError(key) from None
KeyError: 'LIB_PATH/osgeo/gdal304.dll'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/ESSArch/pd/python/lib/python3.10/site-packages/environ/environ.py", line 212, in str
value = self.get_value(var, cast=str, default=default)
File "/ESSArch/pd/python/lib/python3.10/site-packages/environ/environ.py", line 400, in get_value
value = self.get_value(value, cast=cast, default=default)
File "/ESSArch/pd/python/lib/python3.10/site-packages/environ/environ.py", line 391, in get_value
raise ImproperlyConfigured(error_msg) from exc
django.core.exceptions.ImproperlyConfigured: Set the LIB_PATH/osgeo/gdal304.dll environment variable
If you try this with my PR you will get correct output for this:
>> print(env.str('APP_LIB_DIR'))
/opt/prod/extra_my_app_name_extra/lib
Your example with GDAL_LIBRARY_PATH=$LIB_PATH/osgeo/gdal304.dll is not a correct configuration as you missed the curly bracket around your variable which is required to have it embedded in a string or path.
Best regards,
/Henrik
…----- Original Message -----
From: "Serghei Iakovlev" ***@***.***>
To: "joke2k/django-environ" ***@***.***>
Cc: "Henrik Ek" ***@***.***>, "Author" ***@***.***>
Sent: Friday, March 3, 2023 12:36:32 AM
Subject: Re: [joke2k/django-environ] Add support for embedded variables (PR #430)
Can you please explain why the current behavior doesn't suit you and what kind of problem you're trying to solve?
Values that being with a $ may be interpolated. Pass interpolate=True to environ.Env() to enable this feature:
import environ env = environ . Env ( interpolate = True ) # BAR=FOO # PROXY=$BAR # # LIB_PATH=/home/username/.lib # GDAL_LIBRARY_PATH=$LIB_PATH/osgeo/gdal304.dll >> > print env . str ( 'PROXY' ) FOO >> > print ( env . str ( 'LIB_PATH' )) / home / username / . lib >> > print ( env . str ( 'GDAL_LIBRARY_PATH' )) / home / username / . lib / osgeo / gdal304 . dll >> > from environ import __version__ >> > print ( __version__ ) 0.10 . 0
—
Reply to this email directly, view it on GitHub , or unsubscribe .
You are receiving this because you authored the thread. Message ID: <joke2k/django-environ/pull/430/c1452726189 @ github . com>
|
Is it possible to get this PR merged so it can be included in the next release? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Many users is using embedded variables and this PR are fixing this and solves issue #421