Skip to content

Conversation

vinothk-master
Copy link
Contributor

Hi @andlaus

Added these set of lines which is used to reduce the type :ignore comments in compare.py file which increases the readability and to maintain a structured dict. Please check these line commits and let me know I can help on this regard.

class SpecsServiceDict(TypedDict): diag_layer: str diag_layer_type: str new_services: List[str] # List of new service names deleted_services: List[DiagService] # List of deleted services renamed_service: List[Tuple[str, DiagService]] # List of (old_name, DiagService) changed_name_of_service: List[Tuple[str, DiagService]] # Similar to renamed_service changed_parameters_of_service: List[Tuple[str, DiagService, List[Union[str, int, float]]]] class SpecsChangesVariants(TypedDict): new_variants : List[str] deleted_variants : List[str] service_changes : SpecsServiceDict

Thanks
Vinoth Kannan

@CLA-Mercedes-Benz
Copy link

CLA-Mercedes-Benz commented Feb 22, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@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.

In principle, I like it. IMO -- besides the usual bits and pieces that need to be fixed -- for whatever reason it seems that a lot of unrelated formatting changes slipped into this (which makes reviewing it more difficult than it needs to be and also prevents the CI from passing). To fix the formatting, install yapf and isort via pip and run the reformat-source.sh script in the toplevel directory of your working copy...

@vinothk-master
Copy link
Contributor Author

Member

Overall executed the reformat-source.sh as a result it would satisfy the formatting conditions.

$ sh reformat-source.sh
Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\basicstructure.py
Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\nameditemlist.py
Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\odxtypes.py
Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\request.py
Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\response.py
Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\cli\compare.py
Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\diaglayers\hierarchyelement.py
Fixing E:\OpenSource Contributions\Mercedes\odxtools\tests\test_compu_methods.py

@andlaus
Copy link
Member

andlaus commented Feb 25, 2025

Overall executed the reformat-source.sh as a result it would satisfy the formatting conditions.

yes. ideally you run this script before you commit anything, so you don't need to worry about the formatting...

@andlaus
Copy link
Member

andlaus commented Feb 25, 2025

(before you push to github, it is IMO advisable to run mypy and ruff as well because these are build into the CI and your PR will fail if these two do not pass locally...)

@vinothk-master
Copy link
Contributor Author

(before you push to github, it is IMO advisable to run mypy and ruff as well because these are build into the CI and your PR will fail if these two do not pass locally...)

Ok let me work on it and thanks for letting me know

Copy link
Contributor Author

@vinothk-master vinothk-master left a comment

Choose a reason for hiding this comment

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

1. refractored the code by adding dataclass and formated using reformat.sh
2. Verfied using ruff and mypy

class ServiceSpecs:
diag_layer: str
diag_layer_type: str
new_services: List[DiagService] # List of new service name
Copy link
Collaborator

Choose a reason for hiding this comment

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

comments that just repeat variable name are redundant

Copy link
Member

@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.

are you sure that you have run the reformatting script? On my machine it still conducts quite a few changes on this PR:

~/src/odxtools|7f75ca4... > ./reformat-source.sh
Fixing /home/and/src/odxtools/odxtools/request.py
Fixing /home/and/src/odxtools/odxtools/response.py
Fixing /home/and/src/odxtools/odxtools/odxtypes.py
Fixing /home/and/src/odxtools/odxtools/version.py
Fixing /home/and/src/odxtools/odxtools/nameditemlist.py
Fixing /home/and/src/odxtools/odxtools/basicstructure.py
Fixing /home/and/src/odxtools/odxtools/cli/compare.py
Fixing /home/and/src/odxtools/odxtools/diaglayers/hierarchyelement.py
Fixing /home/and/src/odxtools/tests/test_compu_methods.py
~/src/odxtools|7f75ca4... > git diff --stat
 odxtools/cli/compare.py | 398 +++++++++++++++++-------------------------------
 1 file changed, 136 insertions(+), 262 deletions(-)


if service_spec["deleted_services"]:
if service_specs.deleted_services:
assert isinstance(service_specs.deleted_services, List)
Copy link
Member

Choose a reason for hiding this comment

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

that assert should be superfluous now...

if service_spec["changed_name_of_service"][0]:
rich_print(extract_service_tabulation_data(service_specs.deleted_services))
if service_specs.changed_name_of_service:
# assert isinstance(service_specs.changed_name_of_service[0], List)
Copy link
Member

Choose a reason for hiding this comment

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

only leave such "ruins" in the code base in exceptional circumstances (IMO this is not one of these)

Comment on lines 141 to 149
for variant in changes_variants["deleted_diagnostic_layers"]:
assert isinstance(variant, DiagLayer)
rich_print(
f" [magenta]{variant.short_name}[/magenta] ({variant.variant_type.value})")

# diagnostic services
for _, value in changes_variants.items():
if isinstance(value, dict):
self.print_dl_changes(value)
Copy link
Member

Choose a reason for hiding this comment

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

where did this go?

# add old service name (type: String)
service_dict["changed_name_of_service"][1].append(service2.short_name)
# service_specs.changed_name_of_service[1].append(service2.short_name)
Copy link
Member

Choose a reason for hiding this comment

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

this seems to have gone MIA?

@vinothk-master
Copy link
Contributor Author

vinothk-master commented Mar 27, 2025

  • executed the reformat-source.sh
    $ sh reformat-source.sh Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\basicstructure.py Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\nameditemlist.py Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\odxtypes.py Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\request.py Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\response.py Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\cli\compare.py Fixing E:\OpenSource Contributions\Mercedes\odxtools\odxtools\diaglayers\hierarchyelement.py Fixing E:\OpenSource Contributions\Mercedes\odxtools\tests\test_compu_methods.py Skipped 1 files

  • Executed mypy and Ruff

@vinothk-master vinothk-master force-pushed the refractor_compare_tool branch from c82509d to 23f1323 Compare April 16, 2025 12:17
@andlaus
Copy link
Member

andlaus commented Apr 16, 2025

since we raised the minimum python version to 3.10, ruff now complains. the good news is that running ruff check --fix will take care of most -- maybe all -- issues. besides that, the PR can be merged...

@vinothk-master
Copy link
Contributor Author

since we raised the minimum python version to 3.10, ruff now complains. the good news is that running ruff check --fix will take care of most -- maybe all -- issues. besides that, the PR can be merged...

@andlaus I used the same command ruff check --fix . as you have mentioned before, but still it is failing!

@vinothk-master
Copy link
Contributor Author

vinothk-master commented Apr 16, 2025

since we raised the minimum python version to 3.10, ruff now complains. the good news is that running ruff check --fix will take care of most -- maybe all -- issues. besides that, the PR can be merged...

@andlaus I used the same command ruff check --fix . as you have mentioned before, but still it is failing!
d $ODXTOOLS_SOURCE_DIR git checkout main git pull git checkout -b WIP git checkout refractor_compare_tool odxtools/cli/compare.py ruff check --fix . ./reformat-source.sh git commit -a -m "refactor the compare tool to reduce the number of type: ignore comments" git checkout refractor_compare_tool git reset --hard WIP git push -f origin refractor_compare_tool
Is there anything else we have do inorder to proceed with this linting issue?

Thanks

@vinothk-master
Copy link
Contributor Author

vinothk-master commented Apr 17, 2025

Hi @andlaus

Can you please help me with resolving this lint issue. I executed the same ruff command in local repo but after resolving the conflicts it is failing I guess.

build/lib/odxtools/version.py:8:5: UP035 typing.Tupleis deprecated, usetuple instead | 6 | TYPE_CHECKING = False 7 | if TYPE_CHECKING: 8 | from typing import Tuple | ^^^^^^^^^^^^^^^^^^^^^^^^ UP035 9 | from typing import Union |
The error is w.r.t build/lib/odxtools/version.py

Thanks
Vinoth Kannan

@andlaus
Copy link
Member

andlaus commented Apr 20, 2025

Can you please help me with resolving this lint issue

weird: it seems like that for whatever reason, ruff starts complaining about the auto-generated file version.py. this can be fixed by adding "odxtools/version.py", to tool.ruff.exclude in pyproject.toml.

@andlaus
Copy link
Member

andlaus commented Apr 20, 2025

thanks for the fix. it still does not work, but I suspect that this is due to leftover artifacts from packaging (the offending file is in the build/ sub directory). I'll fix this when I'm back from easter (i.e., Tuesday)

andlaus added a commit to andlaus/odxtools that referenced this pull request Apr 22, 2025
for whatever reason, ruff starts to care about the `build/`
subdirectory with mercedes-benz#393
. Since this is probably an artifact of pip, let's just delete this
directory before linting.

Signed-off-by: Andreas Lauser <andreas.lauser@mercedes-benz.com>
Signed-off-by: Christian Hackenbeck <christian.hackenbeck@mercedes-benz.com>
@andlaus
Copy link
Member

andlaus commented Apr 22, 2025

I opened a PR for this PR: vinothk-master#1 . I hope that after you've merged it, the issue is fixed. Note that, due to my unfamiliarity with github actions, I was unable to test if it works...

andlaus and others added 2 commits April 22, 2025 09:46
for whatever reason, ruff starts to care about the `build/`
subdirectory with mercedes-benz#393
. Since this is probably an artifact of pip, let's just delete this
directory before linting.

Signed-off-by: Andreas Lauser <andreas.lauser@mercedes-benz.com>
Signed-off-by: Christian Hackenbeck <christian.hackenbeck@mercedes-benz.com>
attempt to fix the github actions
@vinothk-master
Copy link
Contributor Author

I opened a PR for this PR: vinothk-master#1 . I hope that after you've merged it, the issue is fixed. Note that, due to my unfamiliarity with github actions, I was unable to test if it works...

Thanks @andlaus ! I have merged your workflow fix.

@andlaus
Copy link
Member

andlaus commented Apr 23, 2025

seems like my fix worked. merging, thanks for your patience!

@andlaus andlaus merged commit a602a79 into mercedes-benz:main Apr 23, 2025
7 checks passed
@vinothk-master
Copy link
Contributor Author

seems like my fix worked. merging, thanks for your patience!

Thanks @andlaus and @kayoub5 for helping me in merging this PR

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