[ 
https://issues.apache.org/jira/browse/PROTON-2217?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17283381#comment-17283381
 ] 

ASF GitHub Bot commented on PROTON-2217:
----------------------------------------

astitcher commented on a change in pull request #294:
URL: https://github.com/apache/qpid-proton/pull/294#discussion_r574826338



##########
File path: tools/cmake/Modules/FindPython.cmake
##########
@@ -0,0 +1,66 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# This is a wrapper hack purely so that we can use FindPython
+# with cmake 2.8.12 and its supplied older modules
+
+if (POLICY CMP0094)  # https://cmake.org/cmake/help/latest/policy/CMP0094.html
+    cmake_policy(SET CMP0094 NEW)  # FindPython should return the first 
matching Python on PATH
+endif ()
+
+if (DEFINED PYTHON_EXECUTABLE AND DEFINED Python_EXECUTABLE)
+    message(FATAL_ERROR "Both PYTHON_EXECUTABLE and Python_EXECUTABLE are 
defined. Define at most one of those.")
+endif ()
+
+# FindPython was added in CMake 3.12, but there it always returned
+#  newest Python on the entire PATH. We want to use the first one.
+if (CMAKE_VERSION VERSION_LESS "3.15.0")
+    if (DEFINED Python_EXECUTABLE)
+        set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
+    endif ()
+
+    find_package (PythonInterp REQUIRED)
+    # forward compatibility with FindPython
+    set(Python_VERSION_STRING "${PYTHON_VERSION_STRING}")
+    set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
+    # for completeness, these are not actually used now
+    set(Python_VERSION_MAJOR "${PYTHON_VERSION_MAJOR}")
+    set(Python_VERSION_MINOR "${PYTHON_VERSION_MINOR}")
+    set(Python_VERSION_PATCH "${PYTHON_VERSION_PATCH}")
+
+    find_package (PythonLibs ${PYTHON_VERSION_STRING} EXACT)
+    set(Python_Development_FOUND "${PYTHONLIBS_FOUND}")
+    set(Python_INCLUDE_DIRS "${PYTHON_INCLUDE_PATH}")
+    set(Python_LIBRARIES "${PYTHON_LIBRARIES}")
+else ()
+    if (DEFINED PYTHON_EXECUTABLE)
+        set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
+    endif ()
+
+    # needed on GitHub Actions CI: actions/setup-python does not touch 
registry/frameworks on Windows/macOS
+    # this mirrors PythonInterp behavior which did not consult 
registry/frameworks first

Review comment:
       II think this comment should just read:
   `# This mirrors PythonInterp behavior on windows, which did not consult 
registry/frameworks first.`
   IMO the specifics of github actions behaviour is not that important.

##########
File path: tools/cmake/Modules/FindPython.cmake
##########
@@ -0,0 +1,66 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# This is a wrapper hack purely so that we can use FindPython
+# with cmake 2.8.12 and its supplied older modules
+
+if (POLICY CMP0094)  # https://cmake.org/cmake/help/latest/policy/CMP0094.html
+    cmake_policy(SET CMP0094 NEW)  # FindPython should return the first 
matching Python on PATH
+endif ()
+
+if (DEFINED PYTHON_EXECUTABLE AND DEFINED Python_EXECUTABLE)
+    message(FATAL_ERROR "Both PYTHON_EXECUTABLE and Python_EXECUTABLE are 
defined. Define at most one of those.")
+endif ()
+
+# FindPython was added in CMake 3.12, but there it always returned
+#  newest Python on the entire PATH. We want to use the first one.
+if (CMAKE_VERSION VERSION_LESS "3.15.0")
+    if (DEFINED Python_EXECUTABLE)
+        set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
+    endif ()
+
+    find_package (PythonInterp REQUIRED)
+    # forward compatibility with FindPython
+    set(Python_VERSION_STRING "${PYTHON_VERSION_STRING}")
+    set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
+    # for completeness, these are not actually used now
+    set(Python_VERSION_MAJOR "${PYTHON_VERSION_MAJOR}")
+    set(Python_VERSION_MINOR "${PYTHON_VERSION_MINOR}")
+    set(Python_VERSION_PATCH "${PYTHON_VERSION_PATCH}")
+
+    find_package (PythonLibs ${PYTHON_VERSION_STRING} EXACT)
+    set(Python_Development_FOUND "${PYTHONLIBS_FOUND}")
+    set(Python_INCLUDE_DIRS "${PYTHON_INCLUDE_PATH}")
+    set(Python_LIBRARIES "${PYTHON_LIBRARIES}")
+else ()
+    if (DEFINED PYTHON_EXECUTABLE)
+        set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
+    endif ()
+
+    # needed on GitHub Actions CI: actions/setup-python does not touch 
registry/frameworks on Windows/macOS
+    # this mirrors PythonInterp behavior which did not consult 
registry/frameworks first
+    if (NOT DEFINED Python_FIND_REGISTRY)
+        set(Python_FIND_REGISTRY "LAST")
+    endif ()
+    if (NOT DEFINED Python_FIND_FRAMEWORK)
+        set(Python_FIND_FRAMEWORK "LAST")
+    endif ()

Review comment:
       Hmm, not sure this bit of code should go in the find module wrapper at 
all actually. As when we are able to only use cmake 3.15 everywhere (say in a 
decade or so!) we'll still need code like this for Windows/Mac.
   Maybe we should have these lines:
   ```
   set(Python_FIND_REGISTRY "LAST")
   set(Python_FIND_FRAMEWORK "LAST")
   ```
   before the `find_package(Python...)` line in `CMakeLists.txt`.
   Possibly in both places?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


> Python detection logic prefers python2 over python3 when both are installed
> ---------------------------------------------------------------------------
>
>                 Key: PROTON-2217
>                 URL: https://issues.apache.org/jira/browse/PROTON-2217
>             Project: Qpid Proton
>          Issue Type: Bug
>          Components: build, proton-c, python-binding
>    Affects Versions: proton-c-0.31.0
>            Reporter: Jiri Daněk
>            Assignee: Jiri Daněk
>            Priority: Major
>
> I have the same experience that was reported elsewhere:
> bq. For me, the find_package(PythonInterp) call was always finding the older 
> interpreter (2.7) even though everything pointed to the newer one (3.6). 
> (from https://reviews.llvm.org/D64881)
> This behavior is unfortunate on Ubuntu 20.04 Focal, where both python2 and 
> python3 are available, but pip for python2 is not packaged. Therefore it 
> makes sense to build proton with python3; which would make sense anyways, 
> since Python 2.7 is deprecated by the Python Software Foundation nowadays..
> Besides removing python2 as discussed on the linked page, there is currently 
> nicer way to force python3 that worked for me, by setting 
> {{-DPYTHON_EXECUTABLE=/usr/bin/python3}} CMake variable.
> Related dispatch issue, DISPATCH-187



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to