PythonPackage: check purelib for libs/headers (#42602)

* PythonPackage: check purelib for libs/headers

* Update error messages too

* Fix functools.reduce argument order
This commit is contained in:
Adam J. Stewart 2024-02-22 22:17:21 +01:00 committed by GitHub
parent 2066eda3cd
commit b61d964eb8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,7 +2,10 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import functools
import inspect import inspect
import operator
import os import os
import re import re
import shutil import shutil
@ -368,16 +371,20 @@ def headers(self) -> HeaderList:
# Remove py- prefix in package name # Remove py- prefix in package name
name = self.spec.name[3:] name = self.spec.name[3:]
# Headers may be in either location # Headers should only be in include or platlib, but no harm in checking purelib too
include = self.prefix.join(self.spec["python"].package.include).join(name) include = self.prefix.join(self.spec["python"].package.include).join(name)
platlib = self.prefix.join(self.spec["python"].package.platlib).join(name) platlib = self.prefix.join(self.spec["python"].package.platlib).join(name)
headers = fs.find_all_headers(include) + fs.find_all_headers(platlib) purelib = self.prefix.join(self.spec["python"].package.purelib).join(name)
find_all_headers = functools.partial(fs.find_all_headers, recursive=True)
headers_list = map(find_all_headers, [include, platlib, purelib])
headers = functools.reduce(operator.add, headers_list)
if headers: if headers:
return headers return headers
msg = "Unable to locate {} headers in {} or {}" msg = "Unable to locate {} headers in {}, {}, or {}"
raise NoHeadersError(msg.format(self.spec.name, include, platlib)) raise NoHeadersError(msg.format(self.spec.name, include, platlib, purelib))
@property @property
def libs(self) -> LibraryList: def libs(self) -> LibraryList:
@ -386,15 +393,19 @@ def libs(self) -> LibraryList:
# Remove py- prefix in package name # Remove py- prefix in package name
name = self.spec.name[3:] name = self.spec.name[3:]
root = self.prefix.join(self.spec["python"].package.platlib).join(name) # Libraries should only be in platlib, but no harm in checking purelib too
platlib = self.prefix.join(self.spec["python"].package.platlib).join(name)
purelib = self.prefix.join(self.spec["python"].package.purelib).join(name)
libs = fs.find_all_libraries(root, recursive=True) find_all_libraries = functools.partial(fs.find_all_libraries, recursive=True)
libs_list = map(find_all_libraries, [platlib, purelib])
libs = functools.reduce(operator.add, libs_list)
if libs: if libs:
return libs return libs
msg = "Unable to recursively locate {} libraries in {}" msg = "Unable to recursively locate {} libraries in {} or {}"
raise NoLibrariesError(msg.format(self.spec.name, root)) raise NoLibrariesError(msg.format(self.spec.name, platlib, purelib))
@spack.builder.builder("python_pip") @spack.builder.builder("python_pip")