OpenMDAO / build_pyoptsparse

python script to build/install pyoptsparse with IPOPT (and optionally SNOPT)
Apache License 2.0
9 stars 15 forks source link

Failing to build METIS from source code (type error from TempDirectory) #59

Closed ss4adam closed 11 months ago

ss4adam commented 11 months ago

I'm new to build_pyoptsparse and encountered an error that may be a bug or improper use by the user. When running build_pyoptsparse I get a Python TypeError where a "str" expected, not "TemporaryDirectory". It looks like os.environ['METIS_DIR'] = git_clone('metis') is attempting to set an environment variable (METIS_DIR) to a TemporaryDirectory object instead of a string path.

Ubuntu 20.04 Python 3.10.13 (using venv) git version 2.25.1

$ build_pyoptsparse

VIRTUAL_ENV: /home/adam/repos/MyApp-Thingy/venv
------- Testing build environment functionality. Can be skipped with -k. ------
Using $VIRTUAL_ENV for install prefix
Changed directory to /tmp/tmpw9ixdv63
Testing gcc... OK
Testing g++... OK
Testing gfortran... OK
Changed directory back to /home/adam/repos/MyApp-Thingy
Changed directory to /tmp/tmp559wt2kc
Checking for library: lapack... OK
Changed directory back to /home/adam/repos/MyApp-Thingy
Changed directory to /tmp/tmp5vubhxrx
Checking for library: blas... OK
Changed directory back to /home/adam/repos/MyApp-Thingy
Changed directory to /tmp/tmpt3zycmmt
Checking for library: openblas... OK
Changed directory back to /home/adam/repos/MyApp-Thingy
---------------------------- Beginning installation ---------------------------
----------------------- Building METIS from source code -----------------------
Cloning https://github.com/coin-or-tools/ThirdParty-Metis.git... OK
Changed directory to /tmp/tmp99k25te9
Checking out branch releases/2.0.0... Traceback (most recent call last):
  File "/home/adam/repos/MyApp-Thingy/venv/bin/build_pyoptsparse", line 8, in <module>
    sys.exit(perform_install())
  File "/home/adam/repos/MyApp-Thingy/venv/lib/python3.10/site-packages/build_pyoptsparse.py", line 1333, in perform_install
    install_with_mumps()
  File "/home/adam/repos/MyApp-Thingy/venv/lib/python3.10/site-packages/build_pyoptsparse.py", line 787, in install_with_mumps
    install_metis()
  File "/home/adam/repos/MyApp-Thingy/venv/lib/python3.10/site-packages/build_pyoptsparse.py", line 662, in install_metis
    install_metis_from_src()
  File "/home/adam/repos/MyApp-Thingy/venv/lib/python3.10/site-packages/build_pyoptsparse.py", line 643, in install_metis_from_src
    os.environ['METIS_DIR'] = git_clone('metis')
  File "/root/.pyenv/versions/3.10.13/lib/python3.10/os.py", line 685, in __setitem__
    value = self.encodevalue(value)
  File "/root/.pyenv/versions/3.10.13/lib/python3.10/os.py", line 757, in encode
    raise TypeError("str expected, not %s" % type(value).__name__)
TypeError: str expected, not TemporaryDirectory
swryan commented 11 months ago

You are correct, this is a bug.. I had discovered this recently and made the following change to that line in my local environment:

-    os.environ['METIS_DIR'] = git_clone('metis')
+    metis_dir = git_clone('metis')
+    os.environ['METIS_DIR'] = metis_dir if isinstance(metis_dir, str) else metis_dir.name

I will get this fix into the repository shortly.