Skip to content

Use Jinja templates in csharp sourcegen#1785

Merged
speth merged 4 commits intoCantera:mainfrom
ischoegl:simplify-sourcegen
Nov 2, 2024
Merged

Use Jinja templates in csharp sourcegen#1785
speth merged 4 commits intoCantera:mainfrom
ischoegl:simplify-sourcegen

Conversation

@ischoegl
Copy link
Copy Markdown
Member

@ischoegl ischoegl commented Aug 21, 2024

Changes proposed in this pull request

This PR is a preamble to a potential solution for Cantera/enhancements#39 , which replaces f-string based code blocks used for the .NET interface by corresponding Jinja templates. In addition, it adds logging as well as service methods to data classes. The PR anticipates/backports some changes envisioned by a development branch that targets an autogenerated version of CLib (ischoegl:sourcegen-doxygen-comments) and should reduce the size of upcoming PRs.

The template approach makes for more readable code, and should both simplify future enhancements and help with long-term maintenance of various generated API's.

Illustration

C# code blocks are defined as templates that are added in a single templates.yaml file, e.g.

csharp-derived-handle: |-
  class {{ derived_class_name }} : {{ base_class_name }} { }

csharp-property-int-double: |-
  public {{ prop_type }} {{ cs_name }}
  {
      get => InteropUtil.CheckReturn(
          LibCantera.{{ getter }}(_handle));
      {%- if setter %}
      set => InteropUtil.CheckReturn(
          LibCantera.{{ setter }}(_handle, value));
      {%- endif %}
  }

csharp-scaffold-interop: |-
  {{ preamble }}

  using System.Runtime.InteropServices;

  namespace Cantera.Interop;

  static partial class LibCantera
  {
      {% for function in cs_functions %}
      {{ function | indent(4) }}
      {% endfor %}
  }

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

@ischoegl ischoegl added the .NET label Aug 21, 2024
@ischoegl ischoegl force-pushed the simplify-sourcegen branch from dc554f5 to 0a9aa24 Compare August 21, 2024 17:43
@ischoegl ischoegl marked this pull request as ready for review August 21, 2024 18:10
@ischoegl ischoegl requested a review from a team August 21, 2024 18:17
@codecov
Copy link
Copy Markdown

codecov bot commented Aug 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.26%. Comparing base (ec0cfdb) to head (853af77).
Report is 108 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1785      +/-   ##
==========================================
+ Coverage   73.23%   73.26%   +0.02%     
==========================================
  Files         381      383       +2     
  Lines       54375    54620     +245     
  Branches     9251     9099     -152     
==========================================
+ Hits        39823    40016     +193     
- Misses      11580    11601      +21     
- Partials     2972     3003      +31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ischoegl ischoegl force-pushed the simplify-sourcegen branch 6 times, most recently from cb0c58b to 036a225 Compare August 22, 2024 02:56
@ischoegl

This comment was marked as outdated.

@ischoegl
Copy link
Copy Markdown
Member Author

ischoegl commented Aug 25, 2024

While this PR is not essential for 3.1, it is nevertheless ready for a review. Edit: I marked it as 'deferred' in the release plan for 3.1. PS: as release of 3.1 is pushed back, I am re-adding to release plan.

@ischoegl ischoegl force-pushed the simplify-sourcegen branch from 036a225 to 16e95db Compare August 27, 2024 23:50
Copy link
Copy Markdown
Member

@speth speth left a comment

Choose a reason for hiding this comment

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

Thanks, @ischoegl. I think this is a useful evolution of the sourcegen infrastructure as we look toward using it for additional interfaces. The implementation looks quite clean. I just had a few minor suggestions below.

@ischoegl ischoegl requested a review from speth November 2, 2024 03:39
@ischoegl
Copy link
Copy Markdown
Member Author

ischoegl commented Nov 2, 2024

Thanks, @speth! I took care of all your suggestions.

Copy link
Copy Markdown
Member

@speth speth left a comment

Choose a reason for hiding this comment

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

Thanks, @ischoegl!

@speth speth merged commit e36c9b9 into Cantera:main Nov 2, 2024
@ischoegl ischoegl deleted the simplify-sourcegen branch November 2, 2024 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants