Skip to content
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

Rework class / namespace discovery #456

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

Wuestengecko
Copy link
Member

@Wuestengecko Wuestengecko commented Oct 2, 2024

No description provided.

@Wuestengecko Wuestengecko force-pushed the class-discovery branch 3 times, most recently from ab8e8a6 to 12d008f Compare October 14, 2024 15:07
@Wuestengecko Wuestengecko force-pushed the class-discovery branch 4 times, most recently from bf99b03 to 98e903d Compare October 18, 2024 08:01
@Wuestengecko Wuestengecko force-pushed the class-discovery branch 3 times, most recently from 7e13af6 to e6a3963 Compare November 14, 2024 09:03
@Wuestengecko Wuestengecko force-pushed the class-discovery branch 3 times, most recently from 1ca4fa8 to bb63451 Compare November 18, 2024 13:18
@Wuestengecko Wuestengecko force-pushed the class-discovery branch 3 times, most recently from 58ce90d to c1cf3c0 Compare November 27, 2024 14:12
@Wuestengecko Wuestengecko force-pushed the class-discovery branch 6 times, most recently from c3f5125 to 43f0f85 Compare December 13, 2024 13:41
@Wuestengecko Wuestengecko changed the base branch from master to html-newlines December 13, 2024 13:42
@Wuestengecko Wuestengecko force-pushed the class-discovery branch 2 times, most recently from c3d890c to ed5d538 Compare December 20, 2024 15:55
@Wuestengecko Wuestengecko changed the base branch from master to uv December 23, 2024 09:29
@Wuestengecko Wuestengecko force-pushed the class-discovery branch 2 times, most recently from 8d3e8d2 to 64b7e6e Compare December 23, 2024 10:07
@Wuestengecko Wuestengecko force-pushed the uv branch 2 times, most recently from 5fa9035 to d2b94dc Compare December 23, 2024 10:52
@Wuestengecko Wuestengecko force-pushed the class-discovery branch 2 times, most recently from 78fad73 to e9ea787 Compare December 23, 2024 16:56
Base automatically changed from uv to master January 7, 2025 09:20
@Wuestengecko Wuestengecko force-pushed the class-discovery branch 4 times, most recently from 0aec4d1 to 110a0dd Compare January 13, 2025 17:05
@Wuestengecko Wuestengecko force-pushed the class-discovery branch 2 times, most recently from 274ef3c to 4c532a4 Compare January 24, 2025 16:27
This commit reworks the code that handles 'by_X' style list filtering.
The new code can now also filter on attributes that contain lists, where
an element matches if a filtering target is contained (or not contained)
in the list.

Note that the new implementation no longer special-cases Enum PODs for
comparison purposes, and instead delegates the string comparison to the
enum itself. This special-casing was incomplete anyways, as it wasn't
properly accounting for enums being passed in as filter argument. For
example, the following call would actually do a string comparison of the
enum member's name:

    mylist.by_kind(ComponentExchangeKind.ASSEMBLY)

This also deprecates the use of 'by_type' and 'exclude_types' for
filtering on the type of object (i.e. the Python class). These filters
collide with the commonly used 'type' attribute, which may link to
another model object of interest. Which one of these two options gets
used is very non-obvious and can lead to hard to diagnose bugs.
Instead, users are advised to use 'by_class' and 'exclude_classes', or
the '__class__' attribute for nested filter attributes.

For the time until the next major release, 'by_type' will keep the
current behavior by automatically translating it to '__class__' where
applicable. A UserWarning will be emitted in these cases to inform users
about needed actions.
This commit reworks the discovery of metamodel classes and namespaces.
It introduces the `Namespace` object, whose instances keep track of the
contained classes. Namespace objects are discovered through the Python
entrypoint system. This makes extending the metamodel significantly
easier. It's no longer necessary to add weirdly formatted entries into
barely documented dictionaries, with errors only appearing at some
arbitrary later point.

Discovery of classes now happens via a custom metaclass by simply
inheriting from `ModelElement`. This also allows additional metadata to
be specified at subclassing time, which is especially relevant for
namespace versioning. Due to this, the following decorators are now no
longer needed and have been deprecated:

- `@xtype_handler`: Was used to register classes for discovery, which is
  now done by the metaclass.
- `@attr_equal`: This overwrites the `__eq__` method to compare against
  an attribute. Now handled by the `eq=...` class keyword argument.
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