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

Option to make <summary_format> still flexible for user #172

Open
asmacdo opened this issue Sep 3, 2024 · 1 comment · May be fixed by #181
Open

Option to make <summary_format> still flexible for user #172

asmacdo opened this issue Sep 3, 2024 · 1 comment · May be fixed by #181
Assignees

Comments

@asmacdo
Copy link
Member

asmacdo commented Sep 3, 2024

@yarikoptic since you seem attached to the summary_format The user can set a str, (note, not an f string) https://github.com/con/duct/blob/main/src/con_duct/__main__.py#L31-L46

Since the user-provided value is a regular string, we cannot use fancing f-string logic.

Instead we could add the logic to what I'm calling the "human readable preserializer" https://github.com/con/duct/blob/main/src/con_duct/__main__.py#L472-L476. That serializer is currently only responsible for replacing "unknown" string when the value is None, but it could be extended to do any other logic that would be necessary, ie rounding, and possibly even adding unit choices (ie Gb instead of bytes).

This would leave the user-customizable string to much simpler, and only allow the usage of pre-formatted values.

asmacdo added a commit to asmacdo/duct that referenced this issue Sep 20, 2024
asmacdo added a commit to asmacdo/duct that referenced this issue Sep 20, 2024
If we don't do the rounding prior to formatting, the summary_format
(being a format string, not an f-string) is not smart enough to handle
floats OR None (or str 'unknown'). So instead we need to handle that
first.

Fixes: con#172
Fixes: con#171
@asmacdo asmacdo linked a pull request Sep 20, 2024 that will close this issue
@yarikoptic
Copy link
Member

yarikoptic commented Sep 20, 2024

we cannot use fancing f-string logic.

correct - no fancy f-string logic but can do quite a bit with custom serializer and telling user what formattings are available. Here is the format helper I pointed out in matrix yesterday:

FWIW here is the formatter I was talking about I did for datalad probably 10 years ago by now: https://github.com/datalad/datalad-deprecated/blob/master/datalad_deprecated/ls.py#L369 . And then here how those formatters were used: https://github.com/datalad/datalad-deprecated/blob/master/datalad_deprecated/ls.py#L484 . So it seems we could easily allow for some !S for humanize.naturalsize wrapping around that value. and the construct for unknown I already gave you. Moreover there for percents we could even color similarly to how dstat does , ie. making them red if getting close to 100% or above.
Do look at that code and see how ansi_colors where used etc - might come handy

I think it provides a very nice helper also to output "unknown" for None etc while concentrating all that formatting logic in the formatter instead of diluting through the code like proposed in

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 a pull request may close this issue.

2 participants