Skip to content
Closed
Changes from 13 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
55 changes: 53 additions & 2 deletions easybuild/easyblocks/generic/cmakemake.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
from easybuild.framework.easyconfig import BUILD, CUSTOM
from easybuild.tools.build_log import EasyBuildError, print_warning
from easybuild.tools.config import build_option
from easybuild.tools.filetools import change_dir, create_unused_dir, mkdir, which
from easybuild.tools.filetools import change_dir, create_unused_dir, mkdir, read_file, which
from easybuild.tools.environment import setvar
from easybuild.tools.modules import get_software_root, get_software_version
from easybuild.tools.run import run_cmd
from easybuild.tools.systemtools import get_shared_lib_ext
from easybuild.tools.utilities import nub

import easybuild.tools.toolchain as toolchain

DEFAULT_CONFIGURE_CMD = 'cmake'

Expand Down Expand Up @@ -317,9 +317,60 @@ def configure_step(self, srcdir=None, builddir=None):
self.cfg['configopts']])

(out, _) = run_cmd(command, log_all=True, simple=False)
self.check_python_paths()

return out

def check_python_paths(self):
"""Check that there are no detected Python paths outside the EB installed PythonF"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Check that there are no detected Python paths outside the EB installed PythonF"""
"""Check that there are no detected Python paths outside the Python dependency provided by EasyBuild"""

if not os.path.exists('CMakeCache.txt'):
self.log.warning("CMakeCache.txt not found. Python paths checks skipped.")
return
cmake_cache = read_file('CMakeCache.txt')
if not cmake_cache:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't see how this can happen, since at this point you know that the file exists?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it could be empty for some reason

self.log.warning("CMake Cache could not be read. Python paths checks skipped.")
return

self.log.info("Checking Python paths")

python_paths = {
"executable": [],
"include_dir": [],
"library": [],
}
PYTHON_RE = re.compile(r"_?(?:Python|PYTHON)\d_(EXECUTABLE|INCLUDE_DIR|LIBRARY)[^=]*=(.*)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use "constants" inline:

Suggested change
PYTHON_RE = re.compile(r"_?(?:Python|PYTHON)\d_(EXECUTABLE|INCLUDE_DIR|LIBRARY)[^=]*=(.*)")
python_regex = re.compile(r"_?(?:Python|PYTHON)\d_(EXECUTABLE|INCLUDE_DIR|LIBRARY)[^=]*=(.*)")

for line in cmake_cache.splitlines():
match = PYTHON_RE.match(line)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
match = PYTHON_RE.match(line)
match = python_regex.match(line)

if match:
path_type = match[1].lower()
path = match[2].strip()
self.log.info(f"Python {path_type} path: {path}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a PR to develop, we need to be careful with f-strings, since EasyBuild 4.x is still supposed to support Python 2.7:

Suggested change
self.log.info(f"Python {path_type} path: {path}")
self.log.info("Python %s path: %s" % (path_type, path))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to format before logging:

Suggested change
self.log.info(f"Python {path_type} path: {path}")
self.log.info("Python %s path: %s", path_type, path)

python_paths[path_type].append(path)

ebrootpython_path = get_software_root("Python")
if not ebrootpython_path:
if any(python_paths.values()) and not self.toolchain.comp_family() == toolchain.SYSTEM:
self.log.warning("Found Python paths in CMake cache but Python is not a dependency")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't make this a warning, just info message?

Suggested change
self.log.warning("Found Python paths in CMake cache but Python is not a dependency")
self.log.info("Found Python paths in CMake cache but Python is not a dependency")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not, it is likely an error. #3233 (comment) requested to "complain" ;-)

# Can't do the check
return
ebrootpython_path = os.path.realpath(ebrootpython_path)

errors = []
for path_type, paths in python_paths.items():
for path in paths:
if path.endswith('-NOTFOUND'):
continue
if not os.path.exists(path):
errors.append(f"Python {path_type} does not exist: {path}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a PR to develop, we need to be careful with f-strings, since EasyBuild 4.x is still supposed to support Python 2.7:

Suggested change
errors.append(f"Python {path_type} does not exist: {path}")
errors.append("Python %s does not exist: %s" % (path_type, path))

elif not os.path.realpath(path).startswith(ebrootpython_path):
errors.append(f"Python {path_type} path '{path}' is outside EBROOTPYTHON ({ebrootpython_path})")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a PR to develop, we need to be careful with f-strings, since EasyBuild 4.x is still supposed to support Python 2.7:

Suggested change
errors.append(f"Python {path_type} path '{path}' is outside EBROOTPYTHON ({ebrootpython_path})")
errors.append("Python %s path '%s' is outside EBROOTPYTHON (%s)" % (path_type, path, ebrootpython_path))


if errors:
# Combine all errors into a single message
error_message = "\n".join(errors)
raise EasyBuildError(f"Python path errors:\n{error_message}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a PR to develop, we need to be careful with f-strings, since EasyBuild 4.x is still supposed to support Python 2.7:

Suggested change
raise EasyBuildError(f"Python path errors:\n{error_message}")
raise EasyBuildError("Python path errors:\n" + error_message)

self.log.info("Python check successful")

def test_step(self):
"""CMake specific test setup"""
# When using ctest for tests (default) then show verbose output if a test fails
Expand Down