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

Autogenerate the validation tables for Python #1797

Merged
merged 12 commits into from
Sep 6, 2024
Merged

Autogenerate the validation tables for Python #1797

merged 12 commits into from
Sep 6, 2024

Conversation

Jingru923
Copy link
Contributor

Fixes #1779

@Jingru923 Jingru923 requested a review from evetion September 4, 2024 11:59
@Jingru923 Jingru923 linked an issue Sep 4, 2024 that may be closed by this pull request
@Jingru923 Jingru923 marked this pull request as draft September 4, 2024 12:08
@Jingru923 Jingru923 marked this pull request as ready for review September 4, 2024 13:12
python/ribasim/ribasim/validation.py Outdated Show resolved Hide resolved
utils/gen_python.jl Show resolved Hide resolved
@evetion evetion changed the title Auto tables Autogenerate the validation tables for Python Sep 4, 2024
@@ -49,6 +49,15 @@ end

snake_case(sym::Symbol)::Symbol = Symbol(snake_case(String(sym)))

"Convert a string from snake_case to CamelCase."
function camel_case(snake_case::AbstractString)::String
Copy link
Contributor

Choose a reason for hiding this comment

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

Take a look at titlecase

Copy link
Contributor

Choose a reason for hiding this comment

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

image

Copy link
Contributor

Choose a reason for hiding this comment

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

If it should become CamelCase, I would probably go for: titlecase(), and then replace('_' => '')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want this function to return the same string when the input is already camel case.
image

Seems titlecase() is not able to do it because it treats CamelCase as one word and return Camelcase.

The old way is the same amount of lines but more robust

'{{n[:name]}}': [
{% for value in n[:connectivity] %}
'{{ value }}',
{% end %}],
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good source! In this case the white space trimming doesn't do much, because after ruff formatting the code, the code looks the same.

@Jingru923 Jingru923 merged commit 4e48967 into main Sep 6, 2024
27 checks passed
@Jingru923 Jingru923 deleted the auto-tables branch September 6, 2024 07:41
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.

Auto-generate validation tables in python
4 participants