Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Allow PETSc to build with Python 3.#69

Merged
pramodk merged 1 commit intodevelopfrom
enh/petsc
Aug 27, 2018
Merged

Allow PETSc to build with Python 3.#69
pramodk merged 1 commit intodevelopfrom
enh/petsc

Conversation

@pramodk
Copy link
Copy Markdown

@pramodk pramodk commented Aug 26, 2018

Currently PETSc can be built with only Python2. This means, if package like STEPs need to be built with Python3 then we get :

→ spack spec steps+petsc ^python@3
Input spec
--------------------------------
steps+petsc
    ^python@3

Concretized
--------------------------------
==> Error: An unsatisfiable version constraint has been detected for spec:

    python@3

while trying to concretize the partial spec:

    petsc
        ^blas
        ^lapack
petsc requires python version 2.6:2.8, but spec asked for 3

This is because PETSc package has:

    # Build dependencies
    depends_on('[email protected]:2.8', type='build')

At the moment Spack doesn't allow to have two python version in the dependency tree i.e. python2 for PETSc and python3 for STEPs. See this PR for more details. This is current limitation of Spack concretiser algorithm. This limitation will be addressed in the next release (in coming month/months).

PETSc >=3.9 version allow to launch configure with python3 (see comment). In this case PETSc will internally check for python2 executable and if found, will continue build with python2. In this case we assume that python2 exist.

  • Why to unset PYTHONPATH?

When user does spack install petsc^python@3 then Spack will set PYTHONPATH & PYTHONHOME to python3 install prefix. But PETSc is internally going to launch python2 executable. This will result in import error. And hence we unset those env variables.

To overcome the limitation of current concretiser in spack.
See spack#7926
@pramodk pramodk requested review from ohm314 and tristan0x August 26, 2018 17:36
@pramodk pramodk mentioned this pull request Aug 26, 2018
Copy link
Copy Markdown

@ohm314 ohm314 left a comment

Choose a reason for hiding this comment

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

sorry, neither the PR description nor the comments were clear enough for me on what this PR does. I'm happy to approve it, but I'd be glad if you could explain why the environment variables have to be unset and what you mean by your PR comment.

@pramodk
Copy link
Copy Markdown
Author

pramodk commented Aug 26, 2018

@ohm314 : sorry, my mistake. I was trying to avoid long explanation. please have a look.

run_env.set('PETSC_DIR', self.prefix)
run_env.unset('PETSC_ARCH')

# Petsc build will use python2 internaly
Copy link
Copy Markdown
Member

@tristan0x tristan0x Aug 27, 2018

Choose a reason for hiding this comment

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

Could you please detail a little bit this comment? It is not very clear to me.
If I understand correctly, this patch allows this package to depends on Python 3 but in reality, Python 2 is always used, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If you look at this, this is what happens :

-import sys
+import sys, os
 if not type(sys.version_info) is tuple and sys.version_info.major > 2:
-  print('Configure does not support Python 3 yet, please run as')
+  if os.path.basename(sys.executable) == 'python2':
+    # Exit to prevent an infinite loop in case the environment is corrupted such
+    # that "python2" in PATH is actually a Python 3 interpreter.
+    print('Executable not a valid Python 2 interpreter: ' + sys.executable)
+    sys.exit(1)
+  print('Configure does not support Python 3 yet, attempting to run as')
   print('  python2 ' + ' '.join(["'" + a + "'" for a in sys.argv]))
-  sys.exit(1)
+  os.execlp('python2', 'python2', *sys.argv)

This is hack but currently there is no other way to have Python3 in the dependency tree when PETSc is involved as one of the dependency .

Copy link
Copy Markdown

@ohm314 ohm314 left a comment

Choose a reason for hiding this comment

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

Thanks @pramodk for the clarification. Makes much more sense now.

Copy link
Copy Markdown
Member

@tristan0x tristan0x left a comment

Choose a reason for hiding this comment

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

LGTM

@pramodk pramodk merged commit 1417a80 into develop Aug 27, 2018
@pramodk pramodk deleted the enh/petsc branch August 27, 2018 09:59
pramodk added a commit that referenced this pull request Sep 29, 2018
pramodk added a commit that referenced this pull request Nov 10, 2018
pramodk added a commit that referenced this pull request Nov 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants