-
Notifications
You must be signed in to change notification settings - Fork 180
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(shared-data): find latest definition if version not specified #17223
Conversation
a275f47
to
e3345df
Compare
e3345df
to
884f185
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## edge #17223 +/- ##
==========================================
+ Coverage 73.84% 79.04% +5.20%
==========================================
Files 43 120 +77
Lines 3303 4586 +1283
==========================================
+ Hits 2439 3625 +1186
- Misses 864 961 +97
Flags with carried forward coverage won't be shown. Click here to find out more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I'm late for the review here. I'm not sure about these changes.
schema_3_dir = get_shared_data_root() / STANDARD_DEFS_PATH / "3" / load_name | ||
if schema_3_dir.exists(): | ||
schema_3_files = os.listdir(schema_3_dir) | ||
version_filename = f"{version}.json" if version else max(schema_3_files) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of minor code-level nitpicks:
- As a general habit in Python, I think we should favor writing
if version
asif version is not None
. Becauseversion
is an int, soif version
would behave unexpectedly if somebody suppliedversion=0
. Granted, I don't think any labware will actually have a version 0, so it probably doesn't matter here, but, habits. max(schema_3_files)
would accidentally favor2.json
over10.json
(it will return the lexicographic maximum, not the numeric maximum). I'd also worry about it accidentally picking up things like.gitignore
and.DS_Store
. If we want to find the highest-numbered JSON file, I think we should filter the filenames by regex and extract properly comparableint
s from them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate a bit on the context of this change and its intended effect?
Right now:
- For
apiLevel
≥2.14 Python protocols, I don't think this will change anything, because of this higher-up code that setsversion
explicitly. - For
apiLevel
≤2.13 Python protocols, because of this code, I think it will change their behavior from defaulting to labware version 1, to defaulting to the highest labware version, but only if the labware happens to have a schema 3 definition. (Example reproduction case.) That is probably not what we want, is it? I wouldn't think we want those protocols to be affected at all.
In my opinion:
- In terms of overall system behavior, we want the default labware version to be a higher-level concern, so it can change depending on higher-level concepts such as the protocol's
apiLevel
. Here's my thinking on this from a while ago. - In terms of code implementation, a good way to organize that would be:
- These functions primarily take fully-resolved, explicit
namespace
+load_name
+version
params, never assuming any default. Given anamespace
+load_name
+version
, there should only be one file that matches, and that's something that we should enforce in theshared-data
tests if we're not already. - Python protocols should automatically select a
version
, depending on theirapiLevel
. That code lives in load_labware_params.py. I do not think it's a good idea for Python protocols to automatically find the highest version of a labware, again for the reasons described here, but if we want to do it anyway, I still think the code should live in load_labware_params.py.
- These functions primarily take fully-resolved, explicit
|
||
namespace = namespace.lower() | ||
def_path = _get_path_to_labware(load_name, namespace, checked_version) | ||
def_path = _get_path_to_labware(load_name, namespace, version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hang on, there are multiple places where checked_version
was used in this function, and only this one is being changed to version
. That means the error messages are out of sync with the version that was actually read, for one thing. But more seriously, it looks like we now have different version-defaulting behavior depending on exactly how the namespace
was provided (see line 233). Is that intentional?
Overview
When grabbing a labware definition, if a version is not specified, we default the file version to
1.json
and check whether that file exists. This was done under the impression that all labware definitions in schema 3 would start at1.json
, but since that isn't the case, if no version is specified, we should just find the latest available labware def version that exists and load that.