Skip to content

EnvironmentModifications does not work if the package depends on a specific python package #14491

@zzotta

Description

@zzotta

Using sys.executable in EnvironmentModifications does not work if the package depends on a specific python package, since in this case the PYTHONHOME environment variable is set in the build environment, and it is not the correct python home when using the sys.executable interpreter, which is the one used for the spack command itself.

This issue comes from #14252.

For instance consider the following package (we use the spack source url only to have a downloadable package):

import os
import tempfile

from spack import *
from spack.util.environment import EnvironmentModifications

class SourceBug(Package):
    homepage = "https://github.com/spack"
    url      = "https://github.com/spack/spack/releases/download/v0.13.3/spack-0.13.3.tar.gz"

    version('0.13.3', sha256='dc6f4d6b89d72f1713324e6fd7d4eba8534ba731c680c848d4169d94e76ef85e')
    version('0.13.2', sha256='30c1a3eb42429344107acdea132be34ed7529489a8dafac9640fbcc86bee0ce1')

    depends_on('python@3.6.8', when='@0.13.3')

    def install(self, spec, prefix):
        with tempfile.NamedTemporaryFile() as source_me:
            source_me.write("MYDIR=/my/dir\n")
            source_me.flush()
            EnvironmentModifications.from_sourcing_file(source_me.name).apply_modifications()
        touch(os.path.join(spec.prefix, 'readme'))

In this case installing source-bug@0.13.2 works, while installing source-bug@0.13.3 fails:

==> Error: ProcessError: Command exited with status 1:
    '/bin/bash' '-c' 'source /tmp/tmpOePPWf &> /dev/null && /usr/bin/python -c "import os, json; print(json.dumps(dict(os.environ)))"'
See build log for details:
  .../spack/var/spack/stage/spack-stage-source-bug-0.13.3-wux6dhmj5htnxqhxqyqsykzdc2lptjto/spack-build-out.txt

The error is:

==> [2020-01-07-09:47:11.939684] '/bin/bash' '-c' 'source /tmp/tmpOePPWf &> /dev/null && /usr/bin/python -c "import os, json; print(json.dumps(dict(os.environ)))"'
ImportError: No module named site

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions