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

Conda needs to activate _build and _test environments - not monkey with PATH #910

Closed
jakirkham opened this issue May 2, 2016 · 18 comments
Closed
Assignees
Labels
locked [bot] locked due to inactivity
Milestone

Comments

@jakirkham
Copy link
Member

When using the following recipe.

package:
  name: blas_openblas
  version: 1.0.0

build:
  number: 0
  track_features:
    - blas_openblas

test:
  commands:
    - conda list blas_openblas

about:
  home: NA
  license: NA
  summary: Metapackage to enable the use of OpenBLAS in an environment.

extra:
  recipe-maintainers:
    - jakirkham

I run the build, but it appears not to activate the _test environment during the testing phase, but remains in the _build environment. Here is a snippet that I see in the log.

TEST START: blas_openblas-1.0.0-0
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata: ..............
.Solving package specifications: .........

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    blas_openblas-1.0.0        |                0          657 B  file:///zopt/conda2/conda-bld/osx-64/

The following NEW packages will be INSTALLED:

    blas_openblas: 1.0.0-0 file:///zopt/conda2/conda-bld/osx-64/

Fetching packages ...
blas_openblas- 100% |#############################################################################################################| Time: 0:00:00 947.94 kB/s
Extracting packages ...
[      COMPLETE      ]|################################################################################################################################| 100%
Linking packages ...
[      COMPLETE      ]|################################################################################################################################| 100%
+ conda list blas_openblas
Error: Error: environment does not exist: /zopt/conda2/envs/_build
#
# Use 'conda create' to create an environment before listing its packages.
TESTS FAILED: blas_openblas-1.0.0-0
@msarahan
Copy link
Contributor

This is very related to your compiler configuration PR on conda-forge. IMHO, we need conda-build actually activating environments. That will both clean up code in conda-build, and make it more predictable.

@msarahan msarahan self-assigned this May 10, 2016
@msarahan msarahan added this to the 2.0 milestone May 10, 2016
@msarahan msarahan changed the title _test environment not activated Conda needs to activate _build and _test environments - not monkey with PATH May 10, 2016
@jakirkham
Copy link
Member Author

Also, this issue ( #355 ) seems to be related.

@jakirkham
Copy link
Member Author

Also, maybe this issue ( #353 ) too.

@jakirkham
Copy link
Member Author

jakirkham commented May 18, 2016

Here is a use case for configuring compiler tools ( conda-forge/thrift-cpp-feedstock#4 ). Note that the toolchain simply sets environment variables as part of its activate.sh script to avoid having users do this manually.

@jakirkham
Copy link
Member Author

Just so I know (as there is a 2.0.0beta out), is this still planned for 2.0.0?

@msarahan
Copy link
Contributor

msarahan commented Jun 6, 2016

I forgot about it, but it fits. This is what prerelease is for!

@jakirkham
Copy link
Member Author

Awesome, that is very exciting. What do we need to do to make this work?

@msarahan
Copy link
Contributor

msarahan commented Jun 6, 2016

Here's what I have so far:

def _set_environ_from_subprocess_values(vars):
    """
    Vars is an unprocessed string of envrionment variable output, such as from ```set```
    on Windows, or ```env``` elsewhere
    """
    vars = vars.split("\n")
    vars = {var.split("=")[0].strip(): var.split("=")[1].strip() for var in vars}
    for key, value in vars.items:
        os.environ[key] = value


def activate_env(env_name_or_path):
    if sys.platform == "win32":
        vars = subprocess.check_output(["activate", env_name_or_path,
                                        "&&", "set"]).replace("\r\n", "\n")
    else:
        vars = subprocess.check_output(["source", "activate",
                                        env_name_or_path, "&&", "env"])
    return _set_environ_from_subprocess_values(vars)

def deactivate_env():
    if sys.platform == "win32":
        vars = subprocess.check_output(["deactivate", "&&", "set"]).replace("\r\n", "\n")
    else:
        vars = subprocess.check_output(["source", "deactivate", "&&", "env"])
    return _set_environ_from_subprocess_values(vars)

Still need test cases that prove functionality. Have not run tests to see if this breaks anything.

@jankatins
Copy link

This branch has such a functions which I got from xonsh: https://github.com/janschulz/jupyter_environment_kernels/commits/conda_windows -> last two commits

[I've currently no clue why the real repo, where that branch was PR to, has gone missing :-(]

@msarahan msarahan mentioned this issue Jun 6, 2016
@astrojuanlu
Copy link

I would be glad to see this merged to 2.0 too 😄

@msarahan
Copy link
Contributor

@Juanlu001 this is in 1.21.0. It's a bit buggy. If you're comfortable installing from source, I'd appreciate your review and comments on #1044, which should hopefully clear up a lot of the errors.

@astrojuanlu
Copy link

Great, I will try to provide some feedback this weekend.

@msarahan
Copy link
Contributor

msarahan commented Jun 22, 2016

I'm calling this implemented between #1002 and #1044. Please try 1.21.1 and let me know how it works for you.

@ijstokes
Copy link

@msarahan I'm not about to reopen this, but I'm using latest conda-build 1.21.6 and I think there is some vestige of this problem manifesting itself: many Conda-Forge feedstock build.sh scripts have a source activate line in them with a comment before that line to this issue to say that the source activate is being done to overcome problems with conda-build. Seeing that this issue was closed I removed those lines but then I have the surprising experience I just described to @mingwandroid in a private chat:

I'm trying to build libhdfs3 from https://github.com/conda-forge/libhdfs3-feedstock, I was surprised to see this line (the first one) in the conda build output:

-- Found PROTOBUF: /home/ijstokes/.conda/envs/protobuf/lib/libprotobuf.so  
-- Found KERBEROS: /home/ijstokes/.conda/envs/_build/lib/libkrb5.so  
-- Found GSASL: /home/ijstokes/.conda/envs/_build/lib/libgsasl.so  
-- Found LIBUUID: /home/ijstokes/.conda/envs/_build/lib/libuuid.so

My build.sh script has in it:

export PROTOBUF_LIBRARY=$CONDA_PREFIX/lib
export PROTOBUF_INCLUDE_DIR=$CONDA_PREFIX/include

And I assumed that would have $CONDA_PREFIX point to /home/ijstokes/.conda/envs/_build. The fact that it does not surprises me, and feels like it might be tied to #910 which is the piece mentioned at the top of several Conda-Forge build.sh scripts when they explicitly do a source activate ....

@mingwandroid has checked and believes that conda-build does not activate the _build environment. That is the piece that surprises me. Is there a reason for that? What should I be putting instead of CONDA_PREFIX for those two export lines?

@ijstokes
Copy link

The plot thickens! I have no idea how conda-build works, but investigating a little bit more I noticed that the very end of my (failed) build attempt had this output:

/home/ijstokes/.conda/envs/_build/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.5/../../../libkrb5.so: undefined reference to `k5_get_error@krb5support_0_MIT'
/home/ijstokes/.conda/envs/_build/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.5/../../../libkrb5.so: undefined reference to `k5_json_string_create_len@krb5support_0_MIT'
collect2: error: ld returned 1 exit status
make[3]: *** [test/unit/unit] Error 1
make[3]: Leaving directory `/home/ijstokes/conda-bld/work/pivotalrd-libhdfs3-2.2.31/build'
make[2]: *** [test/unit/CMakeFiles/unit.dir/all] Error 2
make[2]: Leaving directory `/home/ijstokes/conda-bld/work/pivotalrd-libhdfs3-2.2.31/build'
make[1]: *** [test/CMakeFiles/unittest.dir/rule] Error 2
make[1]: Leaving directory `/home/ijstokes/conda-bld/work/pivotalrd-libhdfs3-2.2.31/build'
make: *** [unittest] Error 2
Command failed: /bin/bash -x -e /home/ijstokes/conda-bld/work/pivotalrd-libhdfs3-2.2.31/conda_build.sh

So I thought I'd dig around and what does conda_build.sh contain?

$ cat /home/ijstokes/conda-bld/work/pivotalrd-libhdfs3-2.2.31/conda_build.sh
source activate /home/ijstokes/.conda/envs/_build
#!/usr/bin/env bash

export PROTOBUF_LIBRARY=$CONDA_PREFIX/lib
export PROTOBUF_INCLUDE_DIR=$CONDA_PREFIX/include

mkdir build
cd build
export LIBHDFS3_HOME=`pwd`
../bootstrap --prefix=$PREFIX
make
make unittest
make install

So it appears that whatever it is that creates conda_build.sh did add source activate to the top of my build.sh script. More of a mystery as to how protobuf got into the build environment!

@mingwandroid
Copy link
Contributor

I looked a bit more carefully and I can see where it is done now, apologies for the misinformation:

activate _test:
https://github.com/conda/conda-build/blob/master/conda_build/build.py#L749

activate _build (Windows):
https://github.com/conda/conda-build/blob/master/conda_build/windows.py#L209

activate _build (Unix):
https://github.com/conda/conda-build/blob/master/conda_build/build.py#L582

@msarahan
Copy link
Contributor

I believe you should depend primarily on $PREFIX for things like this, which will always be the build environment prefix. $CONDA_PREFIX is brand new, and depends on a very up-to-date conda. Aside from that, it is much less tested.

@github-actions
Copy link

Hi there, thank you for your contribution!

This issue has been automatically locked because it has not had recent activity after being closed.

Please open a new issue if needed.

Thanks!

@github-actions github-actions bot added the locked [bot] locked due to inactivity label Apr 21, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked [bot] locked due to inactivity
Projects
None yet
Development

No branches or pull requests

6 participants