Repository: spack/spack

Issue:
Installation issue: kahip (python2 vs python3 issue in SConstruct scripts)
I am running into an issue when trying to build kahip using scons based on python3

### Steps to reproduce the issue
spack install kahip@2.00 
when using a scons built with python@3

gives error
=========
==> 20722: Installing kahip
==> Fetching http://algo2.iti.kit.edu/schulz/software_releases/KaHIP_2.00.tar.gz
==> Staging archive: /tmp/spackswinst/spack-stage/spack-stage-kahip-2.00-w6pzs3m7ke2ks526f36j6gbfi3kkuz5u/KaHIP_2.00.tar.gz
==> Created stage in /tmp/spackswinst/spack-stage/spack-stage-kahip-2.00-w6pzs3m7ke2ks526f36j6gbfi3kkuz5u
==> Ran patch() for kahip
==> 20722: kahip: Building kahip [SConsPackage]
==> 20722: kahip: Executing phase: 'build'
==> 20722: kahip: Executing phase: 'install'
==> Error: FileNotFoundError: [Errno 2] No such file or directory: 'deploy'

/software/spack/git.2020.05.14/var/spack/repos/builtin/packages/kahip/package.py:62, in install:
         59        mkdirp(prefix.include)
         60        mkdirp(prefix.lib)
         61
  >>     62        with working_dir('deploy'):
         63            for f in os.listdir('.'):
         64                if re.match(r'.*\.(a|so|dylib)$', f):
         65                    install(f, prefix.lib)
===============

which seems to be do to python2/3 mismatch as spack-build-out.txt contains
===============
==> 20722: kahip: Executing phase: 'build'
==> [2020-07-21-11:20:21.940770, 24067] './compile.sh'
scons: Reading SConscript files ...
  File "/tmp/spackswinst/spack-stage/spack-stage-kahip-2.00-w6pzs3m7ke2ks526f36j6gbfi3kkuz5u/spack-src/SConstruct", line 58

    print 'Illegal value for variant: %s' % env['variant']

                                        ^

SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Illegal value for variant: %s' % env['variant'])?

compile error in node_separator. exiting.
==> 20722: kahip: Executing phase: 'install'
===================

### Information on your system
My system:
spack debug report
* **Spack:** 0.14.2
* **Python:** 3.6.8
* **Platform:** linux-rhel8-x86_64

It appears that the SConstruct scripts provided as part of kahip package contain some python2-isms that do not work in python3.  From what I can see so far, it is basically some print statements that need to be converted to print function calls (i.e. wrap arguments in parentheses).  The python used seems to come through the scons dependency.

The last kahip issue I was able to find was  #13466 (@olesenm); as that ticket was inquiring about strategies to update kahip I thought they might be interested.  That ticket claims kahip>2.11 switched to CMake from SCons; I confess to not being very familiar with SCons, and I noticed that the SConscript/SConstruct files are missing in the root directory in master, but are present in some subdirectories, and have been made python3 friendly since 2.11, so I am confused by the claim that SCons is no longer used.


 
<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [ ] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [ ] I have run `spack maintainers <name-of-the-package>` and @mentioned any maintainers
- [ ] I have uploaded the build log and environment files
- [ ] I have searched the issues of this repo and believe this is not a duplicate



Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/kahip/package.py b/var/spack/repos/builtin/packages/kahip/package.py
--- a/var/spack/repos/builtin/packages/kahip/package.py
+++ b/var/spack/repos/builtin/packages/kahip/package.py
@@ -35,6 +35,15 @@ class Kahip(SConsPackage):
     conflicts('%apple-clang')
     conflicts('%clang')
 
+    # Fix SConstruct files to be python3 friendly (convert print from a
+    # statement to a function)
+    # Split into 2 patch files:
+    # *) first file patches Sconstruct files present in all versions (from
+    # 2.00 to 2.11)
+    # *) second is for files only present in 2.00
+    patch('fix-sconstruct-for-py3.patch', when='@2: ^python@3:')
+    patch('fix-sconstruct-for-py3-v2.00.patch', when='@2.00 ^python@3:')
+
     def patch(self):
         """Internal compile.sh scripts hardcode number of cores to build with.
         Filter these out so Spack can control it."""


Test patch: