question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support (tempita/template) based code generation

See original GitHub issue

We semi-recently started using cythonize in pandas, and I’m thinking some of the wrapping code used there might be worth pushing upstream. I’d like to get opinions before making PR(s) here.

Further ideas:

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
da-woodscommented, Mar 4, 2022

I’m basically in favour of this - I think it’s a good idea to solve this kind of problem with something that works as a separate phase (and with distinct syntax) rather than trying to load too much into Cython syntax. Designing a robust “macro-like” language seems like a fairly hard problem, especially since Cython is pretty constrained to be close to Python syntax.

I’ve generally recommended Tempita for this kind of problem (just because it’s there, and because people like Numpy and Scipy already use it), so building it into the build process a little more thoroughly seems like a good idea.

I’d prefer not killing off DEF and IF too quickly. I definitely think we should deprecate them, issue a warning, and refuse to add new features to them. But I don’t think they’re causing much harm just by existing, so I’d rather leave a good long while for people to adapt and make sure that our proposed replacement is actually fit for purpose. To me Cython 3.1 seems too soon (given that the gap between 3.0 and 3.1 is currently planned to be fairly short).

1reaction
jakirkhamcommented, Aug 2, 2022

Yeah some kind of templating in Cython could be pretty powerful, but probably needs to be done thoughtfully.

Tempita does seem like an easy way forward. Think there are some libraries already using it (like scikit-learn). There are other templating libraries like this in the wild (like Jinja) that might also make sense. It might be worth considering how to templating while maintaining Python looking code (valuable for linting, reading by new devs, pure Python mode, etc.).

Fused types can already be pretty useful on their own. One can even use these to do SFINAE like things in Cython. For example here’s an enable_if analogue in Cython ( https://github.com/cython/cython/issues/2660#issuecomment-687493653 ).

Have wondered if C++ style templating could be used in Cython directly.

Maybe it is worth enumerating what use cases templating would support?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code Generation and T4 Text Templates - Visual Studio ...
Learn how a T4 text template is a mixture of text blocks and control logic that can generate a text file.
Read more >
5 AI Tools That Can Generate Code To Help Programmers
Here are five AI-based code generators based on the large language models that can generate high-quality code:
Read more >
A Guide to Code Generation - Strumenta
It can do what all template engines do: create unique documents based on the provided data. It supports modular templates, control flow, variables,...
Read more >
CodeSmith Generator
CodeSmith Generator is a software development tool to help you get your job done ... and your templates can output any ASCII-based (text...
Read more >
Generate code | WebStorm Documentation
These can be either file templates used when creating a new file, custom or predefined live templates that are applied differently based on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found