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

Add CLF parsing capabilities. #1278

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open

Conversation

MichaelMauderer
Copy link
Member

Summary

Adds a module that allows contains the functionality and data structures to parse CLF files.
This is the first step to add full support for CLF into colour.

Preflight

Code Style and Quality

  • Unit tests have been implemented and passed.
  • Pyright static checking has been run and passed.
  • Pre-commit hooks have been run and passed.
  • [N/A] New transformations have been added to the Automatic Colour Conversion Graph.
  • [N/A] New transformations have been exported to the relevant namespaces, e.g. colour, colour.models.

Documentation

  • New features are documented along with examples if relevant.
  • The documentation is Sphinx and numpydoc compliant.

More docs and examples to come in follow-up PRs, once we can do more than parse the CLF files.

@MichaelMauderer MichaelMauderer marked this pull request as ready for review July 15, 2024 11:34
colour/io/clf.py Outdated Show resolved Hide resolved
colour/io/luts/tests/test_clf.py Show resolved Hide resolved
colour/io/luts/tests/test_clf.py Show resolved Hide resolved
Copy link
Contributor

@zachlewis zachlewis left a comment

Choose a reason for hiding this comment

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

Remarkable work -- this is wonderful!

colour/io/clf.py Outdated Show resolved Hide resolved
Copy link
Member

@KelSolaar KelSolaar left a comment

Choose a reason for hiding this comment

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

Thanks you! This looks great overall. The main two comments I would have are:

  • Maybe considering using an ABC dataclass so that we can consistently expose from_xml and a future to_xml
  • I would move all the utility functions to a separate common/utilities module so that the core of the code stays neat and tidy.

def retrieve_attributes(
xml, attribute_mapping: dict[str, str]
) -> dict[str, str | None]:
def get_attribute(name):
Copy link
Member

Choose a reason for hiding this comment

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

Minor

Do we need this function here instead of than calling directly xml.get(attribute_name)?

attributes = retrieve_attributes(xml, attribute_mapping)

def as_float(value):
if value is None:
Copy link
Member

Choose a reason for hiding this comment

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

Minor

At the point we are already leveraging an exception, I would probably remove this clause and use except (TypeError, ValueError): instead.

super_args = ProcessNode.parse_attributes(xml, config)
style = map_optional(ExponentStyle, xml.get("style"))
if style is None:
raise CLFValidationError("Exponent process node has no `style' value.")
Copy link
Member

Choose a reason for hiding this comment

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

Pedantry

The quotes are mismatched here:

`style'

channel: Channel | None

@staticmethod
def from_xml(xml, _config: ParserConfig):
Copy link
Member

Choose a reason for hiding this comment

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

Major

Is there a reason for _config arg here with underscore when the other ones are using config, I'm assuming that it is because it is not used?

This makes me think that we should maybe look at an ABC dataclass so that we can enforce the from_xml signature consistently everywhere.

return register


def valid_processing_node_tags():
Copy link
Member

Choose a reason for hiding this comment

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

Minor

This definition is not used currently.

@fredsavoir
Copy link
Contributor

fredsavoir commented Sep 24, 2024 via email

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

Successfully merging this pull request may close these issues.

4 participants