ITADN

Config

#151Pull Requestjenuk 创建于 2023-04-07
new feature
J
jenukcommented
Hello @wookayin ! First of all, thank you so much for this package. I have implemented a a new function to format the output of gpustat using a python dataclass. The class saves a color for each entry provided by gpustat, names are the same as in the json (except for replacing `.` with `_`), as well as having a template to layout the final string. This should address issues #51 and #9. Here are two example outputs using it: ![gpustat_box_screen](https://user-images.githubusercontent.com/22528125/230606635-757fc818-46a0-4b00-a957-50ee837dfa30.jpg) ![gpustat_default_screen](https://user-images.githubusercontent.com/22528125/230606622-234fbd48-a4f7-4031-9aa5-27efdb547b9c.jpg) The output is determined by three strings that are formatted using `str.format`, one for the header, the gpu info and the process info. In that environment the corresponding information is provided, and can be used using the standard `{name:specifier}`. I have added an additional parsing for `... $name:specifier$ ...` to input the correct color before and switch back to normal formatting afterward. Also as in your code there are some extra things added like the gpu-name width, the blessed terminal interface and an empty string (to repeat a character `width` times). There are some open todos that need to be implemented before this should be pushed, but I wanted to ask for your opinion so far before I continue this. Remaining todos: - Connection configuration file <-> dataclass. This should be really easy to do when using one of the many libraries designed to do exactly that. I would suggest [omgeconf](https://github.com/omry/omegaconf) if you are fine with adding this as another dependency. - Currently it's either using the config or command line options. Reading and adding command line options with OmegaConf is no problem. The real issue here is that the config at the moment requires a preconfigured template, so that needs to be dynamically adjustable if no fixed template is specified. Probably the biggest todo. - Colors are static at the moment, but I noticed when writing my code that you highlight certain things based on ratios. I'm not sure how customizable this functionality should be. I was thinking of implementing something like "{field a} {operator} {field b) {comp} {field c}", e.g "power_usage / power_limit > 0.9" or "username == jenuk" as a test? I feel like this would support enough flexibility. - Maybe adding an option to color preceding/following characters in the same color as the metrics. - Updating the readme to explain all changes. Do you have any additional feedback/wishes for this? If you are happy with this, I will finish it.
合并状态:未合并 2 条评论