Skip to content

Conversation

@willmmiles
Copy link
Member

@willmmiles willmmiles commented Jun 19, 2025

When removing a usermod from an existing environment, PlatformIO does not clean up the .pio/libdeps folder. This confused the validate_modules.py script: to avoid replicating the usermod mapping logic, it assumed every usermod library it could see in the build ought to be included in the build. So when a usermod was removed, it would incorrectly fault claiming it wasn't included.

Instead, have load_usermods.py leave the actual expected module list in the environment for validate_modules.py to pick up.

As a side effect, this disables the ability to check for modules that aren't compatible with the current platform, as they're filtered out before the list capture in load_usermods.py is run. (This is the normal behaviour of lib_deps, for better or for worse.) I've just removed the nonfunctional code, as out-of-tree modules are expected to be put in lib_deps, so they'll have that behaviour anyways; we might as well just be consistent about it. We can add that feature back later if it turns out to be worthwhile.

Summary by CodeRabbit

  • Refactor
    • Improved the handling and organization of WLED modules for more efficient processing and validation.
    • Centralized the storage of WLED module information for use across different validation steps.

PlatformIO doesn't clean out the libdir when usermods are disabled, so
they still appear in the LibBuilders() set.  Ensure that we validate
only usermods that were actually deps for the build.
Non-platform-safe usermods are filtered out before validation runs;
so this check is no longer functional.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 19, 2025

Walkthrough

The changes refactor how WLED modules are identified and managed in the build process. WLED dependencies are now explicitly filtered and stored in the environment during project configuration, and later retrieved directly for validation, centralizing and simplifying WLED module handling across the scripts.

Changes

Files Change Summary
pio-scripts/load_usermods.py Refactored to filter WLED dependencies into a list, handle their include paths, check lib_archive, and store WLED modules in the environment for later use.
pio-scripts/validate_modules.py Simplified WLED module validation by directly retrieving the filtered list from the environment instead of re-filtering.

Possibly related PRs

  • wled/WLED#4669: Refactors wrapped_ConfigureProjectLibBuilder in pio-scripts/load_usermods.py to fix libArchive settings for usermods and includes explicit error handling for WLED modules with libArchive enabled, overlapping with the current PR's changes to WLED module handling.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d2d5c42 and 368351b.

📒 Files selected for processing (2)
  • pio-scripts/load_usermods.py (2 hunks)
  • pio-scripts/validate_modules.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: wled_build / Build Environments (usermods)
  • GitHub Check: wled_build / Build Environments (esp32s3_4M_qspi)
  • GitHub Check: wled_build / Build Environments (esp32_wrover)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_8MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_16MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32c3dev)
  • GitHub Check: wled_build / Build Environments (esp32_eth)
🔇 Additional comments (4)
pio-scripts/load_usermods.py (3)

80-80: Good refactoring to centralize WLED module filtering.

The list comprehension efficiently filters WLED modules upfront, which aligns with the PR objective to centralize module identification logic.


83-91: Improved logic flow by operating on pre-filtered list.

The change from checking each dependency individually to operating on the pre-filtered wled_deps list is more efficient and clearer. The logic remains functionally equivalent while being more explicit about which modules are being processed.


101-102: Critical fix: Store filtered modules for validation.

This is the key change that solves the validation issue. By storing the actual expected module list in the environment, validate_modules.py can use the correct list instead of re-filtering and potentially including removed modules.

pio-scripts/validate_modules.py (1)

56-57: Simplified validation using centralized module list.

The change to directly use env['WLED_MODULES'] simplifies the logic and fixes the core issue where removed usermods were still being validated. This aligns perfectly with the PR objective.

However, consider adding error handling for the case where WLED_MODULES might not exist in the environment:

-    # Identify the WLED module builders, set by load_usermods.py
-    module_lib_builders = env['WLED_MODULES']
+    # Identify the WLED module builders, set by load_usermods.py
+    try:
+        module_lib_builders = env['WLED_MODULES']
+    except KeyError:
+        secho("ERROR: WLED_MODULES not found in environment. load_usermods.py may not have run correctly.", fg="red", err=True)
+        Exit(1)

Let me verify if this dependency ordering is handled correctly in the build system:

#!/bin/bash
# Description: Check if there are any build configurations that ensure load_usermods.py runs before validate_modules.py

# Search for references to both scripts in build configurations
rg -A 5 -B 5 "load_usermods\.py|validate_modules\.py"
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@netmindz
Copy link
Member

Sounds like a good improvement. Not a blocker for this PR, but is it worth us considering have some CI that tests for actions like this - building then changing the usermod list?

@willmmiles
Copy link
Member Author

Sounds like a good improvement. Not a blocker for this PR, but is it worth us considering have some CI that tests for actions like this - building then changing the usermod list?

Maybe! Truthfully, validate_modules.py probably isn't necessary on regular day-to-day builds; now that most of the kinks with load_usermods.py are worked out, it only really adds value when trying to diagnose build system failures. That said, it's fast enough that it didn't seem to be worth turning off, either -- until it became a source of build breakage itself! We could instead develop a test sequence that applies the validation script only when running the build tests, and reduce the risk that it causes problems in its own right. There's probably room for more extensive validation there too, if we think it's worth the effort.

@willmmiles willmmiles merged commit bbfe90d into wled:main Jun 20, 2025
21 checks passed
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.

2 participants