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

Python Multi Version Test Suite #946

Merged
merged 14 commits into from
Feb 15, 2022
Merged

Conversation

valayDave
Copy link
Collaborator

@valayDave valayDave commented Feb 10, 2022

Changes

  • Ported changes to GH action tests from Test fixes #940
  • Python3.5 is not playing nice with bytes-based JSON loading. Throws an error like TypeError: the JSON object must be str, not 'bytes'. This error doesn't persist in py3.6+. This resulted in minor changes to the way we read task metadata in task_datastore.py and flow_datastore.py
  • The tests in the publish.yml are refactored to come from test.yml. We reuse the jobs in the Test gh action. Workflows being reused need to have on.workflow_call. This helps reuse it locally.

@oavdeev
Copy link
Collaborator

oavdeev commented Feb 10, 2022

should we add Python 3.10 there too? its twice as popular as 3.5, if you go by global pypi download numbers since the beginning of this year
image

@savingoyal
Copy link
Collaborator

Yep, let's add 3.10 and 3.11. @valayDave we would have to install Rcpp from source for R3.5 and R3.6. It's not worth the hassle at the moment, so we can safely disable those tests for now.

value = v.decode("utf-8")
else:
value = v
ret_dict[k] = json.loads(value) if v is not None else None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this correct? if we expect v to be None, then L:495 will break.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that this needs to change. we should have a

if v is None:
  ret_dict[k] = None
  continue

at the top and then we can do this part.

I would actually suggest something like this:

transformer = lambda x: x
if sys.version_info < (3, 6):
  transformer = lambda x: x.decode("utf-8")
return {
  k : json.loads(transformer(v)) if v is not None else None for k, v in self._load_file(names, add_attempt).items()
}

It's a tad more efficient and a bit easier to read maybe.

@@ -1,5 +1,6 @@
import itertools
import json
import sys
Copy link
Collaborator

Choose a reason for hiding this comment

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

spurious import?

@@ -158,7 +159,7 @@ def get_latest_task_datastores(
elif fname == TaskDataStore.METADATA_DATA_SUFFIX:
# This somewhat breaks the abstraction since we are using
# load_bytes directly instead of load_metadata
with open(path, "rb") as f:
with open(path, encoding="utf-8") as f:
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 not familiar with this part of the code. @romain-intel is this the right thing to do here?

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks ok yes. The data is stored with save_metadata which does a json.dumps followed by an encode("utf-8") so this should be reasonable to open as text with that encoding.

This was referenced Feb 10, 2022
Copy link
Contributor

@romain-intel romain-intel left a comment

Choose a reason for hiding this comment

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

Minor comments. O/w LGTM. If addressed, this can go in.

@@ -158,7 +159,7 @@ def get_latest_task_datastores(
elif fname == TaskDataStore.METADATA_DATA_SUFFIX:
# This somewhat breaks the abstraction since we are using
# load_bytes directly instead of load_metadata
with open(path, "rb") as f:
with open(path, encoding="utf-8") as f:
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks ok yes. The data is stored with save_metadata which does a json.dumps followed by an encode("utf-8") so this should be reasonable to open as text with that encoding.

value = v.decode("utf-8")
else:
value = v
ret_dict[k] = json.loads(value) if v is not None else None
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that this needs to change. we should have a

if v is None:
  ret_dict[k] = None
  continue

at the top and then we can do this part.

I would actually suggest something like this:

transformer = lambda x: x
if sys.version_info < (3, 6):
  transformer = lambda x: x.decode("utf-8")
return {
  k : json.loads(transformer(v)) if v is not None else None for k, v in self._load_file(names, add_attempt).items()
}

It's a tad more efficient and a bit easier to read maybe.

@valayDave
Copy link
Collaborator Author

Addressed all comments + nit fixes. Tests are passing. Seems ready to merge.

Copy link
Collaborator

@savingoyal savingoyal left a comment

Choose a reason for hiding this comment

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

lgtm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants