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

fix(modules): use parse from packaging module #14732

Merged
merged 8 commits into from
Apr 1, 2024

Conversation

caila-marashaj
Copy link
Contributor

Fix for #14712.

We were using parse_version from pkg_resources, which can raise an InvalidVersionError, and importing InvalidVersionError from a separate packaging module. This imports the parse function from the same module the error would be raised from.

@caila-marashaj caila-marashaj requested a review from a team as a code owner March 25, 2024 22:29
Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

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

Let's get some tests of the version handling by forcing it to evaluate some invalid versions. This was a very weird issue that happened because of packaging minutia lol

Copy link

codecov bot commented Mar 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.19%. Comparing base (0fbb4c7) to head (a4470d6).
Report is 6 commits behind head on edge.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             edge   #14732      +/-   ##
==========================================
+ Coverage   67.17%   67.19%   +0.02%     
==========================================
  Files        2495     2495              
  Lines       71483    71403      -80     
  Branches     9020     8992      -28     
==========================================
- Hits        48020    47982      -38     
+ Misses      21341    21305      -36     
+ Partials     2122     2116       -6     
Flag Coverage Δ
g-code-testing 92.43% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
.../src/opentrons/hardware_control/modules/mod_abc.py 80.64% <ø> (-0.61%) ⬇️

... and 2 files with indirect coverage changes

Copy link
Contributor

@DerekMaggio DerekMaggio left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -16,6 +15,14 @@
TaskPayload = TypeVar("TaskPayload")


def parse_fw_version(version: str) -> Version:
Copy link
Contributor

@DerekMaggio DerekMaggio Mar 27, 2024

Choose a reason for hiding this comment

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

What is the difference when using parse instead of instantiating a Version object directly?
The answer is nothing, absolutely nothing.
https://github.com/pypa/packaging/blob/main/src/packaging/version.py#L47-L56

It is for backward compatibility when parse used to return a Version or a LegacyVersion 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.

yeah, I was mostly using it here to detect a bad version name so we can default it to 0.0.0

Copy link
Contributor

Choose a reason for hiding this comment

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

No, your function is totally good. What I mean is all packaging.version.parse(string_version) does is call Version(string_version) under the hood. Ignore me lol

Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

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

The test looks good but it should really be in like api/tests/opentrons/hardware_control/, not all the way over in the robot server

["v3.0.dshjfd", Version("v0.0.0")],
],
)
async def test_catch_invalid_fw_version(
Copy link
Member

Choose a reason for hiding this comment

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

this should be next to the actual code it's testing

@caila-marashaj caila-marashaj force-pushed the RQA-2303-handle-unexpected-mod-fw-name branch from c11b186 to bcf9f53 Compare March 29, 2024 22:19
Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

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

remove the rest of the diff from the robot server and we're good, nice!

@caila-marashaj caila-marashaj merged commit bb33f7c into edge Apr 1, 2024
22 checks passed
@caila-marashaj caila-marashaj deleted the RQA-2303-handle-unexpected-mod-fw-name branch April 1, 2024 17:09
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.

3 participants