8000 chore: migrate to scikit-build-core by Czaki · Pull Request #45 · 4DNucleome/PartSegCore-compiled-backend · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore: migrate to scikit-build-core #45

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 4 commits into from
Oct 8, 2024
Merged

Conversation

Czaki
Copy link
Contributor
@Czaki Czaki commented Oct 8, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new Cython libraries for enhanced functionality, including euclidean_cython, path_sprawl_cython, and others.
  • Bug Fixes

    • Updated parameter types in calc_bounds functions to improve compatibility and performance.
  • Chores

    • Transitioned build system to utilize scikit-build-core, enhancing build process efficiency.
    • Removed the deprecated setup.py file for streamlined project structure.
    • Expanded .gitignore to exclude a wider range of development-related files and directories.

Copy link
Contributor
coderabbitai bot commented Oct 8, 2024

Walkthrough

The changes in this pull request involve updates to the build configuration of a C++ project utilizing Python and Cython. The CMakeLists.txt file has been modified to set the project name, specify a minimum CMake version, and define libraries for various functionalities. The pyproject.toml file has transitioned the build system to scikit-build-core, updating dependencies and adding configurations. The setup.py file has been deleted, and modifications to function signatures in the calc_bounds.pyx file have been made to change parameter types from Py_ssize_t to int.

Changes

File/Path Change Summary
CMakeLists.txt Introduced build configuration for a C++ project, set minimum CMake version, defined project name, and added multiple Cython libraries for various functionalities.
pyproject.toml Updated [build-system] to use scikit-build-core, modified requires and build-backend, and added new [tool.scikit-build] section with configurations.
setup.py Deleted file that configured the build process for a Python package with C++ extensions.
src/PartSegCore_compiled_backend/calc_bounds.pyx Changed parameter type from Py_ssize_t to int in functions calculating bounds for 2D to 5D label arrays.
.gitignore Expanded entries to exclude various files and directories related to CMake, Python, Jupyter Notebooks, IDEs, operating systems, and miscellaneous temporary files.

Poem

In the garden of code where the bunnies play,
New libraries hop in, brightening the day.
With CMake and Python, they dance in delight,
Building dreams in the moon's gentle light.
So let’s cheer for the changes, both big and small,
For in this code burrow, there’s room for us all! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e0a7cb8 and af80e1a.

📒 Files selected for processing (1)
  • src/PartSegCore_compiled_backend/calc_bounds.pyx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/PartSegCore_compiled_backend/calc_bounds.pyx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (5)
CMakeLists.txt (4)

1-7: LGTM! Consider using a newer C++ standard.

The initial setup looks good. The minimum CMake version, project name setup, and NumPy API version directive are all appropriate. However, you might want to consider using a newer C++ standard (e.g., C++14 or C++17) if your project doesn't require compatibility with older compilers, as newer standards offer additional features and improvements.

If you decide to use a newer C++ standard, you can update line 4 as follows:

-set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD 17)

10-19: LGTM! Consider making OpenMP optional.

The package finding section is well-structured and includes all necessary components for the project. The flexible OpenMP configuration using the OMP environment variable is a good approach. However, you might want to consider making OpenMP optional to increase the portability of your project.

You can make OpenMP optional by modifying the OpenMP finding as follows:

-find_package(OpenMP REQUIRED)
+find_package(OpenMP)
+if(OpenMP_FOUND)
+    add_definitions(-DUSE_OPENMP)
+else()
+    message(STATUS "OpenMP not found. Building without OpenMP support.")
+endif()

Then, in your source code, you can use #ifdef USE_OPENMP to conditionally include OpenMP-related code.


22-27: LGTM! Consider using find_package for NumPy.

The current approach to retrieve the NumPy include directory is functional and ensures the correct directory is used. However, it might be more CMake-idiomatic to use find_package for NumPy if available in your CMake version.

If your CMake version supports it, you could replace the current NumPy include directory retrieval with:

find_package(NumPy REQUIRED)
include_directories(${NumPy_INCLUDE_DIRS})

This approach is more consistent with CMake conventions and might be easier to maintain in the long run.


68-77: LGTM! Consider making OpenMP linking conditional.

The Cython transpilation and library creation for _fast_unique and _napari_mapping follow the established pattern correctly. The linking with OpenMP is appropriate for potential performance improvements. However, to increase portability, consider making the OpenMP linking conditional.

You can make the OpenMP linking conditional by modifying the target_link_libraries commands as follows:

-target_link_libraries(_fast_unique PRIVATE OpenMP::OpenMP_CXX)
+if(OpenMP_FOUND)
+    target_link_libraries(_fast_unique PRIVATE OpenMP::OpenMP_CXX)
+endif()

-target_link_libraries(_napari_mapping PRIVATE OpenMP::OpenMP_CXX)
+if(OpenMP_FOUND)
+    target_link_libraries(_napari_mapping PRIVATE OpenMP::OpenMP_CXX)
+endif()

This change ensures that the project can still be built on systems without OpenMP support.

src/PartSegCore_compiled_backend/calc_bounds.pyx (1)

Line range hint 1-218: Summary of changes and recommendations

The changes in this file involve updating the components_num parameter type from Py_ssize_t to int in the function signatures of calc_bounds2, calc_bounds3, calc_bounds4, and calc_bounds5. While this change improves consistency across function signatures, it introduces some inconsistencies within the functions themselves.

Key points and recommendations:

  1. Update the docstrings for all affected functions to reflect the new int type for components_num.
  2. Consider updating the implementation of each function to use int instead of Py_ssize_t for loop variables and array dimensions, for consistency with the function signatures.
  3. Evaluate the impact of changing from Py_ssize_t to int on the maximum supported array size and component count. Ensure that this change doesn't negatively affect the ability to handle large arrays or high component counts.
  4. The main calc_bounds function is consistent with the changes and doesn't require modifications.

Before merging these changes, it's crucial to:

  • Thoroughly test the functions with various array sizes and component counts to ensure no regression in functionality.
  • Update any related documentation or type hints in other parts of the codebase that may reference these functions.
  • Consider adding a comment explaining the rationale behind changing from Py_ssize_t to int, if there's a specific reason for this change.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e75b0af and 012feec.

📒 Files selected for processing (4)
  • CMakeLists.txt (1 hunks)
  • pyproject.toml (1 hunks)
  • setup.py (0 hunks)
  • src/PartSegCore_compiled_backend/calc_bounds.pyx (4 hunks)
💤 Files with no reviewable changes (1)
  • setup.py
🧰 Additional context used
🔇 Additional comments (8)
pyproject.toml (2)

1-9: Summary: Successful migration to scikit-build-core

The changes in this file successfully implement the migration to scikit-build-core as intended. The [build-system] section has been updated appropriately, and a new [tool.scikit-build] section has been added with the necessary configurations. These changes should improve the build process and integration with CMake.

To ensure a smooth transition, please:

  1. Verify that all team members and CI systems have the required dependencies installed.
  2. Test the build process thoroughly in different environments.
  3. Update any documentation or README files to reflect the new build system requirements.

Great job on implementing this migration!


6-9: LGTM! Verify CMake version requirement.

The new [tool.scikit-build] section is well-configured for the scikit-build-core migration. The metadata version provider and sdist include settings are appropriate.

Please verify that the CMake version requirement (>=3.21) is compatible with your development and CI environments:

#!/bin/bash
# Description: Verify CMake version compatibility

# Test: Check installed CMake version
cmake --version

# Test: Verify minimum required version
if cmake --version | grep -q "cmake version 3.2[1-9]" || cmake --version | grep -q "cmake version 3.[3-9]" || cmake --version | grep -q "cmake version [4-9]"; then
    echo "CMake version is compatible"
else
    echo "CMake version may not meet the minimum requirement"
fi
CMakeLists.txt (5)

30-43: LGTM! Consistent and well-structured Cython transpilation.

The Cython transpilation and library creation for euclidean_cython, path_sprawl_cython, and sprawl_utils_cython are implemented consistently and correctly. The use of WITH_SOABI ensures unique naming for the compiled modules, and the include directories are properly set to include both NumPy and local source directories.


46-55: LGTM! Consistent implementation for additional Cython modules.

The Cython transpilation and library creation for fuzzy_distance_cython and color_image_cython follow the same consistent and correct pattern as the previous modules. Include directories are properly set, ensuring access to the necessary headers.


57-65: LGTM! Consistent implementation with appropriate include directories.

The Cython transpilation and library creation for calc_bounds and mso_bind maintain the consistent pattern established in previous sections. The additional include directory for mso_bind is correctly set, ensuring access to the necessary headers in the multiscale_opening subdirectory.


80-88: LGTM! Well-organized installation structure.

The installation commands are well-structured and ensure that each compiled module is placed in the correct location within the PartSegCore_compiled_backend package structure. This organization is consistent with the module names and likely reflects the desired package layout, which will facilitate proper importing and usage of the compiled modules.


1-88: Overall, excellent CMakeLists.txt with minor suggestions for improvement.

This CMakeLists.txt file sets up a comprehensive and well-structured build system for a Python/Cython project with C++ components. It effectively handles package finding, Cython transpilation, library creation, and installation. The consistency in handling multiple Cython modules is commendable.

To further improve the file, consider the following suggestions:

  1. Update to a newer C++ standard if backward compatibility is not a concern.
  2. Make OpenMP optional to increase portability.
  3. Use find_package(NumPy) instead of execute_process if supported by your CMake version.
  4. Make OpenMP linking conditional for _fast_unique and _napari_mapping.

These changes will enhance the flexibility and portability of your build system while maintaining its current functionality.

src/PartSegCore_compiled_backend/calc_bounds.pyx (1)

Line range hint 15-38: Main calc_bounds function looks good

The main calc_bounds function is consistent with the changes made to the dimension-specific implementations. It correctly uses Optional[int] for the components_num parameter, which aligns with the updates made to the other functions.

No changes are required for this function.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
.gitignore (3)

Line range hint 1-6: Consider refining ignore patterns for C++ and HTML files.

The current ignore patterns for C++ source files (*.cpp) and HTML files (*.html) might be too broad:

  1. Ignoring all C++ source files could potentially exclude important source code from version control.
  2. Ignoring all HTML files might not be necessary unless they are generated documentation.

Consider specifying more targeted patterns to ignore only generated or temporary files while keeping important source files under version control.


Line range hint 168-301: Python ignore patterns are comprehensive but may include unnecessary entries.

The Python-specific ignore patterns are extensive and cover most scenarios a Python project might encounter. This includes bytecode, distribution packages, virtual environments, and various tools, which is beneficial for maintaining a clean repository.

However, some patterns might be redundant or unnecessary depending on your project's specific needs. For example, there are ignores for Django, Flask, and Scrapy, which may not be relevant if your project doesn't use these frameworks.

Consider reviewing these patterns and removing any that are not applicable to your project to keep the .gitignore file as concise as possible.


Line range hint 1-301: Overall, the .gitignore file is comprehensive and well-structured.

This .gitignore file provides excellent coverage for various development environments, tools, and operating systems. It's based on a reputable template, which ensures it follows best practices.

To further improve it:

  1. Review the project-specific ignores at the beginning of the file to ensure they accurately reflect your project's needs.
  2. Consider removing ignore patterns for tools and frameworks that are not used in your project to keep the file concise.
  3. Periodically review and update this file as your project evolves to maintain its effectiveness.

Great job on implementing such a thorough .gitignore file!

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 012feec and 6c93f47.

📒 Files selected for processing (2)
  • .gitignore (1 hunks)
  • CMakeLists.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CMakeLists.txt
🧰 Additional context used
🔇 Additional comments (4)
.gitignore (4)

Line range hint 13-18: VS Code ignore patterns look good.

The VS Code ignore patterns follow best practices by excluding user-specific settings while allowing shared workspace configurations to be tracked. This approach promotes consistency across the development team.


Line range hint 20-30: Jupyter Notebooks ignore patterns are appropriate.

The ignore patterns for Jupyter Notebooks are comprehensive and follow best practices. Excluding checkpoint files and IPython configuration prevents unnecessary files from being tracked, which is beneficial for maintaining a clean repository.


Line range hint 32-85: Operating system specific ignore patterns are comprehensive.

The ignore patterns for Linux, macOS, and Windows are thorough and cover a wide range of system-generated files and directories. This comprehensive approach helps maintain a clean repository across different development environments.


Line range hint 87-166: PyCharm and JetBrains IDE ignore patterns are well-structured.

The ignore patterns for PyCharm and other JetBrains IDEs are extensive and follow best practices. They effectively exclude user-specific settings and generated files while allowing for potential shared configurations. The use of comments to explain certain choices (like auto-import related ignores) is particularly helpful and promotes understanding among team members.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
pyproject.toml (1)

6-11: LGTM! Consider adding a comment for the CMake version requirement.

The new [tool.scikit-build] section is well-configured for the project's needs. It correctly sets up version metadata, sdist inclusions/exclusions, and wheel exclusions.

Consider adding a comment explaining the reason for the CMake version requirement:

# Minimum CMake version required for the project
cmake.version = ">=3.21"

This helps future maintainers understand why this specific version was chosen.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6c93f47 and e0a7cb8.

📒 Files selected for processing (1)
  • pyproject.toml (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
pyproject.toml (1)

3-4: LGTM! Verify CMake installation.

The changes to the [build-system] section correctly implement the migration to scikit-build-core as per the PR objective. The updated requires list and build-backend are appropriate for this transition.

Please ensure that CMake is installed and available in the build environment, as it's essential for the new build system. Run the following script to verify:

@Czaki Czaki merged commit 6a189be into master Oct 8, 2024
21 checks passed
@Czaki Czaki deleted the change_to_scikit_build branch October 8, 2024 14:51
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
0