Skip to content

Fix for issue #126162: warn for inconsistent Python search options #126329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

dbabokin
Copy link
Contributor

@dbabokin dbabokin commented Feb 8, 2025

Fixes #126162

I check locally that it works without warning for:

  • neither options are defined
  • both defined to the same value

And I checked that it warns if:

  • only one is defined
  • they defined to different values

Copy link

github-actions bot commented Feb 8, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the mlir label Feb 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 8, 2025

@llvm/pr-subscribers-mlir

Author: Dmitry Babokin (dbabokin)

Changes

Fixes #126162

I check locally that it works without warning for:

  • neither options are defined
  • both defined to the same value

And I checked that it warns if:

  • only one is defined
  • they defined to different values

Full diff: https://github.com/llvm/llvm-project/pull/126329.diff

1 Files Affected:

  • (modified) mlir/cmake/modules/MLIRDetectPythonEnv.cmake (+15)
diff --git a/mlir/cmake/modules/MLIRDetectPythonEnv.cmake b/mlir/cmake/modules/MLIRDetectPythonEnv.cmake
index 3a87d39c28a061b..f7a6fa624844046 100644
--- a/mlir/cmake/modules/MLIRDetectPythonEnv.cmake
+++ b/mlir/cmake/modules/MLIRDetectPythonEnv.cmake
@@ -22,6 +22,21 @@ macro(mlir_configure_python_dev_packages)
     find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION}
       COMPONENTS Interpreter ${_python_development_component} REQUIRED)
 
+    # We look for both Python3 and Python, the search algorithm should be
+    # consistent, otherwise disastrous result is almost guaranteed.
+    # Warn if the policies for treating virtual environment are not defined
+    # consistently.
+    # For more details check issue #126162.
+    if(((DEFINED Python_FIND_VIRTUALENV) AND (NOT DEFINED Python3_FIND_VIRTUALENV)) OR
+       ((NOT DEFINED Python_FIND_VIRTUALENV) AND (DEFINED Python3_FIND_VIRTUALENV)))
+      message(WARNING "Only one of Python3_FIND_VIRTUALENV and Python_FIND_VIRTUALENV variables is defined. "
+                      "Make sure that both variables are defined and have the same value.")
+    elseif((DEFINED Python_FIND_VIRTUALENV) AND (DEFINED Python3_FIND_VIRTUALENV) AND
+           (NOT Python_FIND_VIRTUALENV STREQUAL Python3_FIND_VIRTUALENV))
+      message(WARNING "Python3_FIND_VIRTUALENV and Python_FIND_VIRTUALENV are defined differently. "
+                      "Make sure that the variables have the same values.")
+    endif()
+
     # It's a little silly to detect Python a second time, but nanobind's cmake
     # code looks for Python_ not Python3_.
     find_package(Python ${LLVM_MINIMUM_PYTHON_VERSION}

Copy link
Contributor

@makslevental makslevental left a comment

Choose a reason for hiding this comment

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

Sorry this took so long - thanks for the extra warnings. Let me know if you need me to merge.

@dbabokin
Copy link
Contributor Author

Sorry this took so long - thanks for the extra warnings. Let me know if you need me to merge.

Thanks for the review. Yeah, please merge, I don't have write access.

@makslevental makslevental merged commit 56e0bf2 into llvm:main Feb 18, 2025
10 checks passed
Copy link

@dbabokin Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

wldfngrs pushed a commit to wldfngrs/llvm-project that referenced this pull request Feb 19, 2025
llvm#126329)

Fixes llvm#126162

I check locally that it works without warning for:
- neither options are defined
- both defined to the same value

And I checked that it warns if:
- only one is defined
- they defined to different values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[mlir] Inconsistency when searching for Python3 and Python
3 participants