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

Make our CSRD processing code easier to make plugins from #70

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

mrchrisadams
Copy link
Member

@mrchrisadams mrchrisadams commented Jan 27, 2025

This PR is the result of me rethinking how we use the Arelle XBRL parsing library in the carbon.txt validator, with a view to making it much easier to build plugins that query other CSRD datapoints that might be of interest.

The big change is that rather than there being a a single CSRD processor which contains a bunch of hard coded datapoints (i.e. "our" datapoints for tracking green energy), we:

  1. move much of logic of using an XBRL parsing library into the ArelleProcessor which is a simplified wrapper around the Arelle's Python API
  2. create a new GreenwebCSRDProcessor class that makes much more explicit use of the methods offered by the ArelleProcessor directly. We're only really querying for a few datapoints, so we don't really need / want full access to what Arelle offers us.
  3. defines a Protocol for other Processors to satisfy, in order to be considered compatible with this use of the logic encapsulated in the ArelleProcessor.

The thinking here is that others who want to make use of the CSRD parsing language need only make a relatively small class similar to the GreenwebCSRDProcessor themselves, that also consumes the ArelleProcessor methods directly.

I've used a Protocol and composition here instead of inheritance - the intention here is that ultimately it's better to have a bit of upfront friction to create a new class yourself, that you understand fully, and uses a small, well defined API on a separate object, than to subclass something you don't fully understand, and then have to guess at what methods might be "yours" vs in the class hierarchy.

Anyway - the ML generated summary is below too.

This pull request includes significant changes to the carbon_txt module, particularly focusing on refactoring the CSRD processing classes and updating related tests. The main changes involve replacing the CSRDProcessor with the new GreenwebCSRDProcessor and ArelleProcessor, as well as introducing a protocol for CSRD processing plugins.

Refactoring and Class Renaming:

Code Simplification and Cleanup:

  • Removed unnecessary logging setup and cleaned up the initialization process in ArelleProcessor. [1] [2]

Test Updates:

  • Updated tests to use GreenwebCSRDProcessor and ArelleProcessor instead of CSRDProcessor. [1] [2] [3] [4] [5] [6] [7]

Configuration Adjustments:

  • Minor adjustments to src/carbon_txt/web/config/settings/base.py to improve readability and ensure proper environment variable handling. [1] [2] [3]

Also create a GreenwebCSRDProcessor that wraps the logic
we want other to be able to use, so it only
contains the logic specific to our use case
@mrchrisadams mrchrisadams merged commit 6b4d99d into main Jan 27, 2025
4 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.

1 participant