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

change list command output from tabulate to rich tables #359

Merged
merged 12 commits into from
Nov 20, 2024

Conversation

Haris-Ali007
Copy link
Contributor

Issue resolved: I have updated the list bash output by replacing the tabulate table with rich tables.

File updated: cli/_print_utils.py

The output looks like this:
image

@CLA-Mercedes-Benz
Copy link

CLA-Mercedes-Benz commented Nov 3, 2024

CLA assistant check
All committers have signed the CLA.

odxtools/cli/_print_utils.py Show resolved Hide resolved
odxtools/cli/_print_utils.py Show resolved Hide resolved
Copy link
Collaborator

@andlaus andlaus left a comment

Choose a reason for hiding this comment

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

except for the fact that the CI system complains about this, this looks good to me. (replacing the tabulate module for browse and compare would be nice, too...)

@andlaus
Copy link
Collaborator

andlaus commented Nov 12, 2024

@Haris-Ali007: what's the status here? before I can merge this, at least the CI complaints must be fixed...

@Haris-Ali007
Copy link
Contributor Author

@Haris-Ali007: what's the status here? before I can merge this, at least the CI complaints must be fixed...

Yes apologies for the delay. I am fixing the issues.

odxtools/cli/browse.py Outdated Show resolved Hide resolved
value_type: List[Optional[str]] = []
data_type: List[Optional[str]] = []
dop: List[Optional[str]] = []
name: List[Optional[object]] = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can use just list instead of List[Optional[object]]

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 defined it as object to solve the cli issue. So you say I keep it simply like name = [ ]?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am just proposing a simpler syntax, yours work if you want to keep it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay sure thank you.

Copy link
Collaborator

Choose a reason for hiding this comment

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

AFAICS this code is still unchanged? But actually I prefer to use List[Any] here, or -- even better -- replacing the Any by the types which can actually occur here. Since the latter might be quite a bit of work, Any is okay for now...

Copy link
Collaborator

Choose a reason for hiding this comment

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

hm, isn't the name column non-optional and always a string, i.e., List[str]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. you are right. let me fix this.

Copy link
Contributor Author

@Haris-Ali007 Haris-Ali007 Nov 19, 2024

Choose a reason for hiding this comment

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

@andlaus I have made changes, I kept the List[Any] for two variables because here I was getting static type error if defined as int, str or None.

Copy link
Collaborator

@kayoub5 kayoub5 left a comment

Choose a reason for hiding this comment

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

CI failed

Comment on lines 158 to 159
byte: List[Any] = []
bit_length: List[Any] = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

that should probably be

Suggested change
byte: List[Any] = []
bit_length: List[Any] = []
byte: List[Optional[int]] = []
bit_length: List[Optional[int]] = []

?

@@ -228,9 +228,10 @@ def extract_parameter_tabulation_data(parameters: List[Parameter]) -> Table:
value_type.append(None)
dop.append(None)

for lst in [byte, semantic, bit_length, value, value_type, data_type, dop]:
lst[:] = ["" if x is None else x for x in lst]
Copy link
Collaborator

Choose a reason for hiding this comment

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

great that you made this code here more readably. line 232 should probably better be

Suggested change
lst[:] = ["" if x is None else x for x in lst]
# replace `None` entries by empty strings
lst = ["" if x is None else x for x in lst]

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 have tried using simple lst it doesn't override the list in-place.

Copy link
Collaborator

Choose a reason for hiding this comment

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

why does it need to be overwritten in-place? (memory wise it should not make any difference because the current solution creates a temporary list as well and also the required memory hopefully is miniscule...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it does create a temporary list in both case, but in case of list[:] it copies the temporary list to the original address. So in a way I am able to edit the list in it's place.

Copy link
Collaborator

@andlaus andlaus Nov 19, 2024

Choose a reason for hiding this comment

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

okay, I had a hands-on look and I now understand why the in-place copy of the list is necessary. That said, declaring List[Any] for any of the variables above causes mypy to give up with these variables altogether, so -- while not optimal either -- I prefer to use List[Optional[int]] above and add a # type: ignore[attr-defined, index] comment here...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay thanks for the that. I am new to this static type checks. I'll push the changes

@andlaus andlaus merged commit 94f106c into mercedes-benz:main Nov 20, 2024
7 checks passed
@andlaus
Copy link
Collaborator

andlaus commented Nov 20, 2024

all good now. merging, thanks for your work :)

nada-ben-ali pushed a commit to nada-ben-ali/odxtools that referenced this pull request Dec 9, 2024
…z#359)

* change list command output from tabulate to rich tables

* Add indentation to rich tables

* fix coding style errors

* Resolve static type checking error in _print_utils.py

* Update browse.py from tabulate to rich table

* Remove commented code

* Fix lint coding style issues

* Fix lint code quality issue

* Fix static type definition for paramters

* Fix static type definitions for variables defined as List[Any]
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.

4 participants