Conan: [question] Virtual environment with activate.sh under Windows

Created on 23 Jul 2019  路  5Comments  路  Source: conan-io/conan

To help us debug your issue please explain:

  • [x] I've read the CONTRIBUTING guide.
  • [x] I've specified the Conan version, operating system version and any tool that can be relevant.
  • [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.

Environment

OS: Windows 7 Enterprise
Conan version: 1.15.1 (installed via pip)
Python: 3.7.2

Problem

We encountered a problem when launching virtual environment with activate.sh under Windows.
We launch it from Git bash:
"source activate.sh"
But the PATH seems not to be appended correctly (the slashes are wrongly set)
(PATH="C:\Users\uid95125\.conan\data\Tool1\2.0.0\conti_gen_dev1\stable\package\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\bin"${PATH+:$PATH})
When we try to launch our bash script in the virtual environment it cannot be found (due to the wrongly created PATH)
After we manually change the path (slashes) in "activate.sh" and activate again the virtual env ("source activate.sh"), the tool (bash script) can be called.
(PATH="/C/Users/uid95125/.conan/data/Tool1/2.0.0/conti_gen_dev1/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/bin"${PATH+:$PATH})

Detailed use case

Here is the detailed use case (under Windows):

  • one of our teams has a tool with a bash script stored in Artifactory
  • we have a conanfile.txt for the consumer:
[requires]
Tool1/2.0.0@conti_gen_dev1/stable
[generators]
virtualenv
  • the consumer runs conan install .
  • the package is retrieved in local cache and the scripts for activating/deactivating the virtual env are generated (activate.sh/bat/ps1)
    =>activate.sh:
OLD_PS1="$PS1"
export OLD_PS1
PS1="(conanenv) $PS1"
export PS1
PATH="C:\Users\uid95125\.conan\data\Tool1\2.0.0\conti_gen_dev1\stable\package\5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9\bin"${PATH+:$PATH}
export PATH
  • the consumer runs from bash source activate.sh
  • consumer runs the tool:
    source first_sh.sh
    => tool can not be run as the path is wrongly built
  • we modified manually the activate.sh and changed the slashes in the PATH
    => activate.sh
OLD_PS1="$PS1"
export OLD_PS1
PS1="(conanenv) $PS1"
export PS1
PATH="/C/Users/uid95125/.conan/data/Tool1/2.0.0/conti_gen_dev1/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/bin"${PATH+:$PATH}
export PATH
  • after launching the changed activate.sh

    • the path is set correctly

    • the tool could be run properly source first.sh

I have attached also the output when the virtual environment sets the path wrong and when it is set correctly:
RunNOK.txt
RunOK.txt

Questions

Can you help us with this? Are we doing the things wrong?
If someone has a tool which is a bash script how shall this be found?
Is this the expected behavior of activate.sh under Windows (or is a bug)?
Do you propose a workaround for our use case?

medium medium queue bug

All 5 comments

Hi @CristinaBa

I am checking this issue, and you are right, this is problematic behavior.

I guess you have something in the package like:

                def package_info(self):
                    self.env_info.PATH=[self.package_folder]

Which adds itself to the path, so the script is later found there.
The main problem is that such self.package_folder is managed by the system (python interpreter) and it is OS dependent, paths in Windows are using backslash, so that is why that path gets all the way to the activate.sh script. The reason it hasn't been noticed yet might be that most people in Windows uses the .bat, not the .sh scripts.

A possible workaround is to force the slashes just once in the package, so it is not necessary to do it downstream every time:

                def package_info(self):
                    self.env_info.PATH=[self.package_folder.replace("\\\\", "/")]

I am trying to think about other possibilities, but the truth is that the virtualenv generator is agnostic of variables, it doesn't know that such thing is a path, so it seems a bit tricky to change the path in the virtualenv generator.

Please let me know if the above makes the trick. Thanks!

Hello @memsharded

thanks for the reply.
Unfortunately the workaround you suggested is not the best option for us.
We were thinking as an option to develop a custom generator to solve our problem.
If you have any other ideas or workarounds please let us know.

Thanks!

I am exploring possibilities here: https://github.com/conan-io/conan/pull/5534 Note that this is not intended to be merged, only reviewed to check possible approaches.

The main problem here is that paths are given by the system. By default in Windows it uses backslash. That path is assigned to an env-var.

When the virtualenv files are generated, it is not possible to know what represents a path and what not. The PR just hardcode some possible env-var names, but that is a bit hacky.

Are you generating the activate scripts also in the git console? Maybe the generator could detect the "subsystem" and generate the paths with the correct slashes. I don't like it a lot... but we might consider it.

I've used activate.sh on both Linux & Windows since a very long time, but just recently noticed this same issue (cleared the cache, updated conan and did a clean build, so probably it changed a while back)...
Anything particular that has changed? AFAIK my packages (or at least the one causing issues) have not changed.

Was this page helpful?
0 / 5 - 0 ratings