Skip to content

Third party Library and Component support - #540

Open
alan412 wants to merge 15 commits into
wpilibsuite:mainfrom
alan412:third_parties
Open

alan412 wants to merge 15 commits into
wpilibsuite:mainfrom
alan412:third_parties

Conversation

@alan412

@alan412 alan412 commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Overview

This creates a way for third parties to be able to add components and python libraries into blocks.

Third parties follow the directions in examples/ for creating their own .blocks_lib files which contain metadata, python wheels, samples, and blockly toolboxes.

There is also support for i18n.

Libraries are managed under "Manage... Libraries..."

In order to make sure this could work, this PR also moves all of REV items from being built-in to one of the samples.

Linked Issues

Closes #539

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that causes existing functionality to change)
  • Documentation update
  • Code style/formatting updates
  • Refactoring / Renaming
  • Other

How Has This Been Tested?

Created the four built-in examples which have a variety of options.
Make sure that they show up in components, can be used in blocks, etc.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have run through the [docs/testing_before_pr_checklist.md]

@alan412 alan412 changed the title Third parties Third party Library and Component support Sep 15, 2026

@lizlooney lizlooney left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is really spectacular!

## Building

```bash
./build.sh # builds all of the examples

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Insert the following:

cd <your repo>/example_libraries

Comment thread backend/blocks_lib.py
components/*.json - optional component classes that are added to the components toolbox
python_data/*.json - optional python modules and classes, in the format of the generated
robotpy_data.json, that the library's blocks and components use
samples/<SampleName>/*.json - optional sample projects that are shown with the built in samples

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

built in -> built-in

Comment thread docs/blocks_lib_format.md

Blocks has to know about the Python modules and classes that blocks use, not just the component
classes. For example, a component method might return an object whose fields can be read, take an
enum as an argument, or return a subclass of a built in class. Each `*.json` file in

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

built in -> built-in

Comment thread docs/blocks_lib_format.md
`components/`.
- `aliases` maps type names to the types they are aliases for.
- `subclasses` maps a class name to the names of its subclasses. Blocks that take the class also
accept the subclasses, and a library can add subclasses to a built in class.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

built in -> built-in

Comment thread docs/blocks_lib_format.md
- `subclasses` maps a class name to the names of its subclasses. Blocks that take the class also
accept the subclasses, and a library can add subclasses to a built in class.

Python data doesn't add anything to the toolbox by itself, and it isn't shown with the built in

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

built in -> built-in


"""Generates components/ and python_data/ for the REV Robotics library from robotpy-rev.

This uses python_tools, so run it with the python_tools venv (see python_tools/README.md), with

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Who are these instructions for? Who needs to "run it"?

Does running these commands generate some files? If so, which ones? Maybe these instructions belong in the README.md file.

Comment thread python_tools/json_util.py


def _writeJson(json_data, file_path: str, indent: int = 4, sort_keys: bool = True):
with open(file_path, 'w', encoding='utf-8') as json_file:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Insert the following code so we know what files are being written.

    print(f'INFO: writing file {file_path}',
        file=sys.stderr)

Comment thread python_tools/json_util.py
if not_generated_names and add_unused_to_ignore:
python_toolbox[_KEY_IGNORE] = sorted(ignored_names | set(not_generated_names))
_writeJson(python_toolbox, os.path.join(library_directory, _PYTHON_TOOLBOX_FILE), indent=2,
sort_keys=False)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why aren't the keys sorted?

Comment thread python_tools/json_util.py
if owner is None and name not in generated_enum_names}) - ignored_names)
if not_generated_names and add_unused_to_ignore:
python_toolbox[_KEY_IGNORE] = sorted(ignored_names | set(not_generated_names))
_writeJson(python_toolbox, os.path.join(library_directory, _PYTHON_TOOLBOX_FILE), indent=2,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why indent=2?

"rev.ColorSensorV3",
"rev.ColorSensorV3.RawColor"
],
"ignore": [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't really understand the ignore section.
Are these classes that are not applicable to FIRST and/or to Systemcore/Motioncore?

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.

Create way for third parties to add libraries/components

2 participants