Skip to content

fix: correctly set default PYTHONOCC_WRAP_VISU build option#1484

Open
justend29 wants to merge 1 commit intotpaviot:masterfrom
justend29:fix-python-wrap-visu-cmake
Open

fix: correctly set default PYTHONOCC_WRAP_VISU build option#1484
justend29 wants to merge 1 commit intotpaviot:masterfrom
justend29:fix-python-wrap-visu-cmake

Conversation

@justend29
Copy link

@justend29 justend29 commented Mar 25, 2026

Previously, the PYTHONOCC_WRAP_VISU build setting was incorrectly set to a non-empty string instead of the value OFF here. This caused all subsequent if(PYTHONOCC_WRAP_VISU) checks to evaluate the variable as set.

Furthermore, a user couldn't set PYTHONOCC_WRAP_VISU on the command line, as it was always overwritten within CMakeLists.txt.

Summary by Sourcery

Fix configuration of the visualization wrapper build option to respect user overrides and correctly depend on OpenGL availability.

Bug Fixes:

  • Ensure PYTHONOCC_WRAP_VISU defaults to OFF when OpenGL is not found instead of being set to a non-empty string that always evaluates as enabled.
  • Allow PYTHONOCC_WRAP_VISU to be set from the CMake command line without being overridden in CMakeLists.

Build:

  • Tie the default value of PYTHONOCC_WRAP_VISU directly to OPENGL_FOUND while centralizing OpenGL detection and warnings in the CMake configuration.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 25, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts how the PYTHONOCC_WRAP_VISU CMake option is initialized so it properly defaults based on OpenGL detection while respecting user-provided values, and avoids assigning an invalid non-boolean default; also slightly restructures OpenGL discovery and messaging.

File-Level Changes

Change Details Files
Make PYTHONOCC_WRAP_VISU a proper boolean option that defaults to OpenGL availability and no longer overwrites user-provided values.
  • Initialize OPENGL_FOUND to FALSE before OpenGL discovery to ensure a defined state.
  • Gate the OpenGL find_package/include_directories calls behind a check that PYTHONOCC_WRAP_VISU is not already defined, so user-specified values are preserved.
  • Emit a warning if OpenGL is not found when attempting to enable visualization.
  • Replace the conditional OPENGL_FOUND-based option/SET logic with a single option_with_default call, using OPENGL_FOUND as the default value instead of a non-empty string assignment that forced the option on.
CMakeLists.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The PYTHONOCC_WRAP_DATAEXCHANGE option is now declared twice in a row, which is redundant and could be confusing; please keep only a single option_with_default(PYTHONOCC_WRAP_DATAEXCHANGE ...) line.
  • When PYTHONOCC_WRAP_VISU is explicitly set to ON by the user, find_package(OpenGL) and include_directories(${OPENGL_INCLUDE_DIR}) are skipped, which may leave the OpenGL headers and libraries unset even though visualization is enabled; consider still running the OpenGL discovery (and emitting a warning if it is not found) in that case.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `PYTHONOCC_WRAP_DATAEXCHANGE` option is now declared twice in a row, which is redundant and could be confusing; please keep only a single `option_with_default(PYTHONOCC_WRAP_DATAEXCHANGE ...)` line.
- When `PYTHONOCC_WRAP_VISU` is explicitly set to `ON` by the user, `find_package(OpenGL)` and `include_directories(${OPENGL_INCLUDE_DIR})` are skipped, which may leave the OpenGL headers and libraries unset even though visualization is enabled; consider still running the OpenGL discovery (and emitting a warning if it is not found) in that case.

## Individual Comments

### Comment 1
<location path="CMakeLists.txt" line_range="87" />
<code_context>
+  find_package(OpenGL)
+  include_directories(${OPENGL_INCLUDE_DIR})
+  if(NOT OPENGL_FOUND)
+    message(WARNING "OpenGL library not found, Visualization compilation is turned OFF")
+  endif(NOT OPENGL_FOUND)
+endif(NOT DEFINED PYTHONOCC_WRAP_VISU)

 #################
 # Build options #
 #################
 include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/OCCT_Modules.cmake)
 # add an option to choose toolkits to compile
-if(OPENGL_FOUND)
-  option_with_default(PYTHONOCC_WRAP_VISU "Compile Visualisation" ON)
-else(OPENGL_FOUND)
-  message(WARNING "OpenGL library not found, Visualization compilation is turned OFF")
-  set(PYTHONOCC_WRAP_VISU "Compile Visualisation" OFF)
-endif(OPENGL_FOUND)
+option_with_default(PYTHONOCC_WRAP_VISU "Compile Visualisation" ${OPENGL_FOUND})
+option_with_default(PYTHONOCC_WRAP_DATAEXCHANGE "Compile DataExchange wrapper" ON)
 option_with_default(PYTHONOCC_WRAP_DATAEXCHANGE "Compile DataExchange wrapper" ON)
</code_context>
<issue_to_address>
**nitpick (typo):** Inconsistent spelling of 'Visualization/Visualisation' in user-facing strings.

The warning uses "Visualization" while the option text uses "Visualisation". Please pick one (US or UK) and use it consistently across these user-facing strings.

```suggestion
option_with_default(PYTHONOCC_WRAP_VISU "Compile Visualization" ${OPENGL_FOUND})
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

message(WARNING "OpenGL library not found, Visualization compilation is turned OFF")
set(PYTHONOCC_WRAP_VISU "Compile Visualisation" OFF)
endif(OPENGL_FOUND)
option_with_default(PYTHONOCC_WRAP_VISU "Compile Visualisation" ${OPENGL_FOUND})
Copy link

Choose a reason for hiding this comment

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

nitpick (typo): Inconsistent spelling of 'Visualization/Visualisation' in user-facing strings.

The warning uses "Visualization" while the option text uses "Visualisation". Please pick one (US or UK) and use it consistently across these user-facing strings.

Suggested change
option_with_default(PYTHONOCC_WRAP_VISU "Compile Visualisation" ${OPENGL_FOUND})
option_with_default(PYTHONOCC_WRAP_VISU "Compile Visualization" ${OPENGL_FOUND})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant