Skip to content
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

Improve docs about environment variables overriding #112

Closed
majidaldo opened this issue Aug 11, 2020 · 6 comments
Closed

Improve docs about environment variables overriding #112

majidaldo opened this issue Aug 11, 2020 · 6 comments

Comments

@majidaldo
Copy link
Contributor

in the docs:
"
Environment variables defined as a single string (like DB_LOCATION above) will overwrite an existing variable with the same name.
"

in code:

   "Can't merge the key: '{key}' because it will override the previous value.",
                            "Only lists and dicts can be merged. The type obtained was: {type}",

"Can't merge the key: '{key}' because it will override the previous value.",

@prusse-martin
Copy link
Member

prusse-martin commented Aug 11, 2020

The error indicates that there are multiple definitions for that variable in different devenv files, not related to the exiting variables.
Maybe the error message and/or the docs should be improved.

Maybe we should add a flag to merge those as "use the first value (possible from the root devenv file)".
As a work around you could use jinga to omit that env var from the file when included (not the root devenv file) using the is_included var:

environment:
  {% if not is_included %}
  DB_LOCATION: https://localhost/dev
  {% endif %}

We did opt for the "merge error" to avoid variables defined in some devenv file to be silently ignored.

@edisongustavo
Copy link
Contributor

Maybe we should add a flag to merge those as "use the first value (possible from the root devenv file)".

I would be opposed to doing that. You can easily end up in a situation where you don't know why an environment variable has a given value. And that will be long hours debugging something.

@nicoddemus
Copy link
Member

Agreed, better to raise an error, we just need to update the docs I think.

@majidaldo
Copy link
Contributor Author

majidaldo commented Aug 11, 2020

The error indicates that there are multiple definitions for that variable in different devenv files, not related to the exiting variables.
Maybe the error message and/or the docs should be improved.

Maybe we should add a flag to merge those as "use the first value (possible from the root devenv file)".
As a work around you could use jinga to omit that env var from the file when included (not the root devenv file) using the is_included var:

environment:
  {% if not is_included %}
  DB_LOCATION: https://localhost/dev
  {% endif %}

We did opt for the "merge error" to avoid variables defined in some devenv file to be silently ignored.

Yup. That's what I did. For data sciency work, I claim the following template is everything that you need.

# copy/paste into your work dir
#                           add more work dirs if needed
{% set included_workdirs = ['project', ] %}

{% set dev_req =     not is_included %}
{% set run_req =     is_included %}
{% set wrapped_exe = not  is_included %}


dependencies: []
    #- sometestframework        # [dev_req]
    #- some analysis library     # [run_req]
   # - wrapped exe                  # [wrapped_exe]
environment:
  # probably want to append PATH and PYTHONPATH in your env
  PATH:
    - '{{ os.path.join(root, "wbin") }}' # exec wrappers.
    - '{{root}}'
  PYTHONPATH:
    - '{{root}}'
  # don't define the following in envs that include this
  WORK_DIR: '{{  os.path.basename(root) }}'                       # [not is_included]
  WORKDIR:  '{{  os.path.basename(root) }}'                       # [not is_included]
  WORK_DIR_PATH: '{{root}}'                                       # [not is_included]
  WORKDIR_PATH:  '{{root}}'                                       # [not is_included]
  PROJECTROOT:  '{{ os.path.abspath(os.path.join(root, '..')) }}' # [not is_included]
  PROJECT_ROOT: '{{ os.path.abspath(os.path.join(root, '..')) }}' # [not is_included]
includes:
{% for included in included_workdirs %}
  - '{{root}}/../{{included}}/environment.devenv.yml'
{% endfor %}
name: {{'mydatascienceproject-' + os.path.basename(root)}}

This + exec-wrappers + ESSS/deps + invoke gives me everything that I need for a rather sophisticated and general data science setup...without having to go conda build.

@nicoddemus
Copy link
Member

Awesome!

I've changed the title of the issue to better reflect the doc change. Would you like to contribute that?

@nicoddemus nicoddemus changed the title override allowed or not? Improve docs about environment variables overriding Aug 12, 2020
@majidaldo
Copy link
Contributor Author

Awesome!

I've changed the title of the issue to better reflect the doc change. Would you like to contribute that?

Sure. Unfortunately my response will be delayed. If the condadevenv developers can respond faster, don't let my delay delay the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants