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

Distinguish generic code_template from specific code_generator #298

Merged
merged 7 commits into from
Mar 25, 2025

Conversation

mccalluc
Copy link
Contributor

@mccalluc mccalluc commented Mar 20, 2025

  • Fix Distinguish generic codegen from the specifics used here #297
  • Separate the generic from the specific code generation utilities, and also the corresponding tests. With this change, code_template has no logic that only applies to this project.
  • Make the __file__ explicit, since the generic code can be used from different locations.
  • Split the notebook and script generation classes. (Java idioms aren't always best, but these classes are big enough to have their own files.)
  • Move the analyses into this new directory, so all the templates are near each other.

before:

├── dp_wizard
│   ├── analyses # Top-level directory separated from the other template instances
│   │   ├── histogram
│   │   └── mean
│   └── utils
│       ├── code_generators
│       │   ├── _template.py # Mixes application specific and generic code
└── tests
    └── utils
        ├── test_code_generators.py # Tests are mixed, too

after:

├── dp_wizard
│   └── utils
│       ├── code_generators # ALL of the templates instances, and code to fill the templates
│       │   ├── analyses
│       │   │   ├── histogram
│       │   │   ├── mean
│       │   ├── abc.py # Pull classes out for visibility
│       │   ├── notebook.py
│       │   └── script.py
│       ├── code_template.py # NONE of the template instances specific to this application
└── tests
    └── utils
        ├── test_code_generators.py
        ├── test_code_template.py

@mccalluc mccalluc marked this pull request as ready for review March 20, 2025 16:17
@ekraffmiller ekraffmiller self-assigned this Mar 24, 2025
Copy link
Member

@ekraffmiller ekraffmiller left a comment

Choose a reason for hiding this comment

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

Hi Chuck this looks good, I just had some questions about the naming and reorganization. One more general comment, it might help the code readability to re-name the 'no-tests' folder to something that describes the contents, such as 'template-instances'. Unless the testing code requires the that specific folder name to skip over the files.

Copy link
Member

Choose a reason for hiding this comment

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

To improve readability, can this file name be changed to code_generator.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure: I'll also add abstract to make that clear.

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why this needed to be moved, since it's used specifically for code generation? It seems a little out of place in the generic /utils directory.

Copy link
Contributor Author

@mccalluc mccalluc Mar 25, 2025

Choose a reason for hiding this comment

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

I want to separate the code_generation with the details of code generation for this particular application, from code_template which is more general, and might eventually be factored out of this repo entirely. The distinction might be most clear looking at the tests.

Perhaps better names would make the distinction more clear, but for now:

  • code_generation describes the result, and avoids specifying the implementation. There are different ways you could generate code. For example, you could start from a parse tree instead, but it would still be "code generation"
  • code_template is describing the implementation. There are other template libraries, and this works a lot like them, but it is particularly adapted to python code with it's different fill_* methods.

Copy link
Member

Choose a reason for hiding this comment

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

ok, thanks for the explanation, I see what you mean.

@ekraffmiller
Copy link
Member

@mccalluc I think this is ready to merge, after the file name change we discussed. thanks!

@mccalluc mccalluc requested a review from ekraffmiller March 25, 2025 18:32
Copy link
Member

@ekraffmiller ekraffmiller left a comment

Choose a reason for hiding this comment

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

approved

@mccalluc mccalluc merged commit acb00da into main Mar 25, 2025
4 checks passed
@mccalluc mccalluc deleted the 297-clarify-codegen branch March 25, 2025 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

Distinguish generic codegen from the specifics used here
2 participants