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

ignore user python packages by using -s option when running Python code via python -c #3440

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion easybuild/easyblocks/c/clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ def sanity_check_step(self):

if self.cfg['python_bindings']:
custom_paths['files'].extend([os.path.join("lib", "python", "clang", "cindex.py")])
custom_commands.extend(["python -c 'import clang'"])
custom_commands.extend(["python -s -c 'import clang'"])

super(EB_Clang, self).sanity_check_step(custom_paths=custom_paths, custom_commands=custom_commands)

Expand Down
4 changes: 2 additions & 2 deletions easybuild/easyblocks/c/cplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def sanity_check_step(self):
custom_commands = []

if self.with_python:
custom_commands.append("python -c 'import cplex'")
custom_commands.append("python -c 'import docplex'")
custom_commands.append("python -s -c 'import cplex'")
custom_commands.append("python -s -c 'import docplex'")

super(EB_CPLEX, self).sanity_check_step(custom_paths=custom_paths, custom_commands=custom_commands)
2 changes: 1 addition & 1 deletion easybuild/easyblocks/c/cryptography.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ def sanity_check_step(self, *args, **kwargs):
if success:
# Check module added in v0.7 leading to issue #9446 (see above)
if LooseVersion(self.version) >= LooseVersion("0.7"):
run_cmd("python -c 'from cryptography.hazmat.bindings.openssl import binding'")
run_cmd("python -s -c 'from cryptography.hazmat.bindings.openssl import binding'")
return success, fail_msg
2 changes: 1 addition & 1 deletion easybuild/easyblocks/e/esmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,6 @@ def sanity_check_step(self):

custom_commands = []
if get_software_root('Python'):
custom_commands += ["python -c 'import ESMF'"]
custom_commands += ["python -s -c 'import ESMF'"]

super(EB_ESMF, self).sanity_check_step(custom_commands=custom_commands, custom_paths=custom_paths)
2 changes: 1 addition & 1 deletion easybuild/easyblocks/g/gurobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def sanity_check_step(self):
]

if get_software_root('Python'):
custom_commands.append("python -c 'import gurobipy'")
custom_commands.append("python -s -c 'import gurobipy'")

super(EB_Gurobi, self).sanity_check_step(custom_commands=custom_commands, custom_paths=custom_paths)

Expand Down
8 changes: 4 additions & 4 deletions easybuild/easyblocks/l/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,15 @@ def configure_step(self, **kwargs):
python_dir = get_software_root('Python')
if python_dir:
# Find the Python .so lib
cmd = 'python -c "import sysconfig; print(sysconfig.get_config_var(\'LDLIBRARY\'))"'
cmd = 'python -s -c "import sysconfig; print(sysconfig.get_config_var(\'LDLIBRARY\'))"'
(python_lib, _) = run_cmd(cmd, log_all=True, simple=False, trace=False)
if not python_lib:
raise EasyBuildError("Failed to determine Python .so library: %s", python_lib)
python_lib_path = glob.glob(os.path.join(python_dir, 'lib*', python_lib.strip()))[0]
if not python_lib_path:
raise EasyBuildError("Could not find path to Python .so library: %s", python_lib)
# and the path to the Python include folder
cmd = 'python -c "import sysconfig; print(sysconfig.get_config_var(\'INCLUDEPY\'))"'
cmd = 'python -s -c "import sysconfig; print(sysconfig.get_config_var(\'INCLUDEPY\'))"'
(python_include_dir, _) = run_cmd(cmd, log_all=True, simple=False, trace=False)
if not python_include_dir:
raise EasyBuildError("Failed to determine Python include dir: %s", python_include_dir)
Expand Down Expand Up @@ -516,7 +516,7 @@ def sanity_check_step(self, *args, **kwargs):
if LooseVersion(self.cur_version) >= LooseVersion(translate_lammps_version('29Sep2021')):
custom_commands = [cmd + '; l.finalize()' for cmd in custom_commands]

custom_commands = ["""python -c '%s'""" % cmd for cmd in custom_commands]
custom_commands = ["""python -s -c '%s'""" % cmd for cmd in custom_commands]

# Execute sanity check commands within an initialized MPI in MPI enabled toolchains
if self.toolchain.options.get('usempi', None):
Expand Down Expand Up @@ -666,7 +666,7 @@ def get_cpu_arch():

:return: returns detected cpu architecture
"""
out, ec = run_cmd("python -c 'from archspec.cpu import host; print(host())'", simple=False)
out, ec = run_cmd("python -s -c 'from archspec.cpu import host; print(host())'", simple=False)
if ec:
raise EasyBuildError("Failed to determine CPU architecture: %s", out)
return out.strip()
2 changes: 1 addition & 1 deletion easybuild/easyblocks/m/mrtrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ def sanity_check_step(self):

custom_commands = []
if LooseVersion(self.version) >= LooseVersion('3.0'):
custom_commands.append("python -c 'import mrtrix3'")
custom_commands.append("python -s -c 'import mrtrix3'")

super(EB_MRtrix, self).sanity_check_step(custom_paths=custom_paths, custom_commands=custom_commands)
2 changes: 1 addition & 1 deletion easybuild/easyblocks/n/neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def sanity_check_step(self):
self.log.info("Skipping MPI testing of NEURON since MPI testing is disabled")

if self.with_python:
cmd = "python -c 'import neuron; neuron.test()'"
cmd = "python -s -c 'import neuron; neuron.test()'"
(out, ec) = run_cmd(cmd, simple=False, log_all=True, log_output=True)

# cleanup
Expand Down
4 changes: 2 additions & 2 deletions easybuild/easyblocks/n/numexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ def sanity_check_step(self):

# if Intel MKL is available, make sure VML is used
if self.imkl_root:
custom_commands.append("python -c 'import numexpr; assert(numexpr.use_vml)'")
custom_commands.append("python -s -c 'import numexpr; assert(numexpr.use_vml)'")

# for sufficiently recent versions of numexpr, also do a more extensive check for VML support
if LooseVersion(self.version) >= LooseVersion('2.7.3'):
custom_commands.append("""python -c "import numexpr; numexpr.set_vml_accuracy_mode('low')" """)
custom_commands.append("""python -s -c "import numexpr; numexpr.set_vml_accuracy_mode('low')" """)

return super(EB_numexpr, self).sanity_check_step(custom_commands=custom_commands)
8 changes: 4 additions & 4 deletions easybuild/easyblocks/n/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def sanity_check_step(self, *args, **kwargs):
"blas_found = numpy_build_deps['blas']['found']",
"assert blas_found",
])
custom_commands.append('python -c "%s"' % blas_check_pytxt)
custom_commands.append('python -s -c "%s"' % blas_check_pytxt)

# if FlexiBLAS is used, make sure we are linking to it
# (rather than directly to a backend library like OpenBLAS or Intel MKL)
Expand All @@ -372,7 +372,7 @@ def sanity_check_step(self, *args, **kwargs):
"blas_name = numpy_build_deps['blas']['name']",
"assert blas_name == 'flexiblas', 'BLAS library should be flexiblas, found %s' % blas_name",
])
custom_commands.append('python -c "%s"' % blas_check_pytxt)
custom_commands.append('python -s -c "%s"' % blas_check_pytxt)

elif LooseVersion(self.version) >= LooseVersion('1.10'):
# generic check to see whether numpy v1.10.x and up was built against a CBLAS-enabled library
Expand All @@ -383,10 +383,10 @@ def sanity_check_step(self, *args, **kwargs):
"blas_ok = 'HAVE_CBLAS' in dict(numpy.__config__.blas_opt_info['define_macros'])",
"sys.exit((1, 0)[blas_ok])",
])
custom_commands.append('python -c "%s"' % blas_check_pytxt)
custom_commands.append('python -s -c "%s"' % blas_check_pytxt)
else:
# _dotblas is required for decent performance of numpy.dot(), but only there in numpy 1.9.x and older
custom_commands.append("python -c 'import numpy.core._dotblas'")
custom_commands.append("python -s -c 'import numpy.core._dotblas'")

return super(EB_numpy, self).sanity_check_step(custom_paths=custom_paths, custom_commands=custom_commands)

Expand Down
2 changes: 1 addition & 1 deletion easybuild/easyblocks/o/opencv.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def sanity_check_step(self):

custom_commands = []
if get_software_root('Python'):
custom_commands.append("python -c 'import cv2'")
custom_commands.append("python -s -c 'import cv2'")

super(EB_OpenCV, self).sanity_check_step(custom_paths=custom_paths, custom_commands=custom_commands)

Expand Down
4 changes: 2 additions & 2 deletions easybuild/easyblocks/p/petsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ def configure_step(self):
if self.with_python:

# enable numpy support, but only if numpy is available
(_, ec) = run_cmd("python -c 'import numpy'", log_all=True, simple=False)
(_, ec) = run_cmd("python -s -c 'import numpy'", log_all=True, simple=False)
if ec == 0:
self.cfg.update('configopts', '--with-numpy=1')

# enable mpi4py support, but only if mpi4py is available
(_, ec) = run_cmd("python -c 'import mpi4py'", log_all=True, simple=False)
(_, ec) = run_cmd("python -s -c 'import mpi4py'", log_all=True, simple=False)
if ec == 0:
with_mpi4py_opt = '--with-mpi4py'
if self.cfg['shared_libs'] and with_mpi4py_opt not in self.cfg['configopts']:
Expand Down
20 changes: 10 additions & 10 deletions easybuild/easyblocks/p/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import easybuild.tools.toolchain as toolchain


EXTS_FILTER_PYTHON_PACKAGES = ('python -c "import %(ext_name)s"', "")
EXTS_FILTER_PYTHON_PACKAGES = ('python -s -c "import %(ext_name)s"', "")

# magic value for unlimited stack size
UNLIMITED = 'unlimited'
Expand Down Expand Up @@ -528,7 +528,7 @@ def _sanity_check_ebpythonprefixes(self):
site_packages_path = os.path.join('lib', 'python' + self.pyshortver, 'site-packages')
temp_site_packages_path = os.path.join(temp_prefix, site_packages_path)
mkdir(temp_site_packages_path, parents=True) # Must exist
(out, _) = run_cmd("%s=%s python -c 'import sys; print(sys.path)'" % (EBPYTHONPREFIXES, temp_prefix))
(out, _) = run_cmd("%s=%s python -s -c 'import sys; print(sys.path)'" % (EBPYTHONPREFIXES, temp_prefix))
out = out.strip()
# Output should be a list which we can evaluate directly
if not out.startswith('[') or not out.endswith(']'):
Expand Down Expand Up @@ -561,7 +561,7 @@ def sanity_check_step(self):
abiflags = ''
if LooseVersion(self.version) >= LooseVersion("3"):
run_cmd("command -v python", log_all=True, simple=False, trace=False)
cmd = 'python -c "import sysconfig; print(sysconfig.get_config_var(\'abiflags\'));"'
cmd = 'python -s -c "import sysconfig; print(sysconfig.get_config_var(\'abiflags\'));"'
(abiflags, _) = run_cmd(cmd, log_all=True, simple=False, trace=False)
if not abiflags:
raise EasyBuildError("Failed to determine abiflags: %s", abiflags)
Expand All @@ -571,7 +571,7 @@ def sanity_check_step(self):
# make sure hashlib is installed correctly, there should be no errors/output when 'import hashlib' is run
# (python will exit with 0 regardless of whether or not errors are printed...)
# cfr. https://github.com/easybuilders/easybuild-easyconfigs/issues/6484
cmd = "python -c 'import hashlib'"
cmd = "python -s -c 'import hashlib'"
(out, _) = run_cmd(cmd)
regex = re.compile('error', re.I)
if regex.search(out):
Expand Down Expand Up @@ -600,9 +600,9 @@ def sanity_check_step(self):
custom_commands = [
"python --version",
"python-config --help", # make sure that symlink was created correctly
"python -c 'import _ctypes'", # make sure that foreign function interface (libffi) works
"python -c 'import _ssl'", # make sure SSL support is enabled one way or another
"python -c 'import readline'", # make sure readline support was built correctly
"python -s -c 'import _ctypes'", # make sure that foreign function interface (libffi) works
"python -s -c 'import _ssl'", # make sure SSL support is enabled one way or another
"python -s -c 'import readline'", # make sure readline support was built correctly
]

if self.install_pip:
Expand All @@ -612,8 +612,8 @@ def sanity_check_step(self):
os.path.join('bin', pip) for pip in ('pip', 'pip' + py_maj_version, 'pip' + self.pyshortver)
])
custom_commands.extend([
"python -c 'import pip'",
"python -c 'import setuptools'",
"python -s -c 'import pip'",
"python -s -c 'import setuptools'",
])

if get_software_root('Tk'):
Expand All @@ -622,7 +622,7 @@ def sanity_check_step(self):
tkinter = 'tkinter'
else:
tkinter = 'Tkinter'
custom_commands.append("python -c 'import %s'" % tkinter)
custom_commands.append("python -s -c 'import %s'" % tkinter)

# check whether _tkinter*.so is found, exact filename doesn't matter
tkinter_so = os.path.join(self.installdir, 'lib', pyver, 'lib-dynload', '_tkinter*.' + shlib_ext)
Expand Down
2 changes: 1 addition & 1 deletion easybuild/easyblocks/q/qscintilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def sanity_check_step(self):
os.path.join('qsci', 'api', 'python'),
os.path.join('share', 'sip', self.pyqt_pkg_name),
])
custom_commands.append("python -c 'import %s.Qsci'" % self.pyqt_pkg_name)
custom_commands.append("python -s -c 'import %s.Qsci'" % self.pyqt_pkg_name)

super(EB_QScintilla, self).sanity_check_step(custom_paths=custom_paths, custom_commands=custom_commands)

Expand Down
2 changes: 1 addition & 1 deletion easybuild/easyblocks/r/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def sanity_check_step(self):

custom_commands = []
if get_software_root('Python'):
custom_commands.append("python -c 'import ROOT'")
custom_commands.append("python -s -c 'import ROOT'")

super(EB_ROOT, self).sanity_check_step(custom_commands=custom_commands, custom_paths=custom_paths)

Expand Down
2 changes: 1 addition & 1 deletion easybuild/easyblocks/t/tbb.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def sanity_check_step(self):

if self.cfg['with_python']:
custom_paths['dirs'].append(os.path.join(self.tbb_subdir, 'python'))
custom_commands.extend(['python -c "import tbb"'])
custom_commands.extend(['python -s -c "import tbb"'])

super(EB_tbb, self).sanity_check_step(custom_paths=custom_paths, custom_commands=custom_commands)

Expand Down
2 changes: 1 addition & 1 deletion easybuild/easyblocks/t/tkinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def sanity_check_step(self):
tkinter = 'tkinter'
else:
tkinter = 'Tkinter'
custom_commands = ["python -c 'import %s'" % tkinter]
custom_commands = ["python -s -c 'import %s'" % tkinter]

if not self.tkinter_so_basename:
self.tkinter_so_basename = self.get_tkinter_so_basename(True)
Expand Down
4 changes: 2 additions & 2 deletions easybuild/easyblocks/t/torchvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def sanity_check_step(self):
" scores = torch.randn(1).to('cuda')",
" print(torchvision.ops.nms(boxes, scores, 0.5))",
])
custom_commands.append('python -c "%s"' % python_code)
custom_commands.append('python -s -c "%s"' % python_code)

if get_software_root('libjpeg-turbo'):
# check if torchvision was built with libjpeg support
Expand All @@ -121,6 +121,6 @@ def sanity_check_step(self):
"image_tensor = torch.zeros(1, 1, 1, dtype=torch.uint8)",
"print(torchvision.io.image.encode_jpeg(image_tensor))",
])
custom_commands.append('python -c "%s"' % python_code)
custom_commands.append('python -s -c "%s"' % python_code)

return super(EB_torchvision, self).sanity_check_step(custom_commands=custom_commands, custom_paths=custom_paths)
4 changes: 2 additions & 2 deletions easybuild/easyblocks/v/vmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def configure_step(self):
# Python locations
pyver = get_software_version('Python')
pymajver = pyver.split('.')[0]
out, ec = run_cmd("python -c 'import sysconfig; print(sysconfig.get_path(\"include\"))'", simple=False)
out, ec = run_cmd("python -s -c 'import sysconfig; print(sysconfig.get_path(\"include\"))'", simple=False)
if ec:
raise EasyBuildError("Failed to determine Python include path: %s", out)
else:
Expand All @@ -114,7 +114,7 @@ def configure_step(self):
env.setvar('PYTHON_LIBRARIES', out.strip())

# numpy include location, easiest way to determine it is via numpy.get_include()
out, ec = run_cmd("python -c 'import numpy; print(numpy.get_include())'", simple=False)
out, ec = run_cmd("python -s -c 'import numpy; print(numpy.get_include())'", simple=False)
if ec:
raise EasyBuildError("Failed to determine numpy include directory: %s", out)
else:
Expand Down
Loading