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

[question] How to add runtime-only environment variables #9529

Closed
daravi opened this issue Sep 4, 2021 · 10 comments
Closed

[question] How to add runtime-only environment variables #9529

daravi opened this issue Sep 4, 2021 · 10 comments

Comments

@daravi
Copy link
Contributor

daravi commented Sep 4, 2021

Hi is it possible to append only to the run environment? Adding to env_info results in the environment variable being added to the virtual environment. But I only need the variable at run time so I need it in the virtual run environment.

In my environment.sh.env file I see some variables that are required only for runtime and not in compile time. But I don't see a way for the Conan recipe authors to append to environment_run.sh.env instead of environment.sh.env. My understanding is that former is for runtime and latter is for build time.

@memsharded
Copy link
Member

The new environment management implements this:

  • Add self.runenv_info.append("MYVAR", "MYVALUE") to your package_info()
  • Use the VirtualRunEnv generator, or better, auto-activate it with the auto_use [conf]
  • Use self.run(..., env=["conanrunenv"]) to run only with the defined run environment. The file is conanrunenv.sh.

It is pending to properly document this, it is experimental, and we wanted to test it internally first.

@daravi
Copy link
Contributor Author

daravi commented Sep 4, 2021

@memsharded Awesome thanks! Is VirtualRunEnv different from virtualrunenv? Also what do you mean by auto_use?

@memsharded
Copy link
Member

Yes, it is the new one, very different approach.

$ conan config list
Supported Conan *experimental* conan.conf properties:
core:required_conan_version: Will raise if the current Conan version does not match the defined version range.
...
tools.env.virtualenv:auto_use: Automatically activate virtualenvs when changing into a directory

The description is not very good, it will be improved, but it means that it will generate VirtualBuildEnv and VirtualRunEnv if there are enviroment items by default. At the moment it is opt-in to make sure it is not breaking, but it will be enabled by default in Conan 2.0.

@daravi
Copy link
Contributor Author

daravi commented Sep 5, 2021

Got it. Thanks @memsharded !

@daravi daravi closed this as completed Sep 5, 2021
@daravi daravi reopened this Sep 5, 2021
@daravi daravi closed this as completed Sep 5, 2021
@daravi
Copy link
Contributor Author

daravi commented Sep 5, 2021

@memsharded Some follow up questions and feedback:

  1. Putting the config in conan.conf I don't see any effects. The global.conf documentation says it should be in home directory but I think this should be in the Conan directory (~/.conan) correct? Also, putting this global.conf in my ~/.conan directory:
[conf]
tools.env.virtualenv:auto_use = True # Automatically activate virtualenvs

I am getting this error when running conan commands:

Error in Conan initialization: Error while parsing conf value '[conf]'

Am I missing something or is this a bug?


  1. It seems redundant (and confusing) to have to add VirtualRunEnv generator if I have self.run(..., env=["conanrunenv"]) in my recipe. (since I didn't have to include any generator if I used self.run(..., run_environment=True))

  1. An indicator in the prompt could be useful to show that the environment has been activated

  1. I guess I could open a separate ticket for this but using prepend_path I see the environment variable in the middle, even though it should have been at the very end of the list:
/opt/conan/gst-plugins-base/1.19.1/3rdparty/stable/package/f5fe3fc092cad9350eaa1b83e67bf9034b7a5d7b/lib/gstreamer-1.0:/opt/conan/gst-plugins-good/1.19.1/3rdparty/stable/package/10574dabbd4926f359886a1e3bdaf3e723fbe1fc/lib/gstreamer-1.0:/opt/conan/gst-libav/1.19.1/3rdparty/stable/package/72c7f31a45487786fb0fc49d7271eb5e5bf2ceac/lib/gstreamer-1.0:$GST_PLUGIN_PATH:/opt/conan/gstreamer/1.19.1/3rdparty/stable/package/343c7cb897991a054238a1804728747e201f5802/lib/gstreamer-1.0

In my case I am using prepend_path in all 4 recipes above.

@daravi daravi reopened this Sep 5, 2021
@tapia
Copy link
Contributor

tapia commented Sep 20, 2021

Hi, @daravi

Question 1: That [conf] section works fine for me. Could you please paste the full conan.conf file? Looks like you have some kind of syntax error.

Question 2: The default environment is VirtualBuildEnv. If you want to use VirtualRunEnv, you have to do it explicitly. Anyhow, the recommendation is setting the auto_use configuration instead of explicitly use the VirtualRunEnv generator

Question 3: What do you mean? Usually virtualenvs do show that prompt

Question 4: Yep, that should be another ticket :-)

@chausner-audeering
Copy link

Question 1: That [conf] section works fine for me. Could you please paste the full conan.conf file? Looks like you have some kind of syntax error.

@daravi Did you solve this issue? I am experiencing the same error with a different setting. I created a global.conf file in ~/.conan with the following content:

[conf]
core:default_profile=linux-gcc10

Running any Conan command only prints:

Error in Conan initialization: Error while parsing conf value '[conf]'

@chausner-audeering
Copy link

@daravi I think we have both misinterpreted the docs at https://docs.conan.io/en/latest/reference/config_files/global_conf.html#tools-configurations. The example that is given there refers to profiles but not global.conf, I think.

@memsharded
Copy link
Member

@chausner-audeering

Yes, the example there refers to Profile values ..., not to the actual global.conf file. Most likely the docs can be improved, they are a bit rough now.

The global.conf doesn't contain the [conf] header, the contents can be the same items that are under the [conf] section in a profile (except the core items cannot be defined in the profile so far).

@tapia
Copy link
Contributor

tapia commented Oct 14, 2021

Closing the issue as the main question has been answered. @daravi feel free to reopen it if necessary.

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

No branches or pull requests

4 participants