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

api: Add Metadata.from_bytes() #1354

Merged
merged 1 commit into from
Apr 21, 2021

Conversation

jku
Copy link
Member

@jku jku commented Apr 16, 2021

This is essentially short-hand for

JSONDeserializer().deserialize(data)

but seems easier for the API user so may be worth it.

Metadata.from_file() now uses Metadata.from_bytes() internally.


(message and title edited later to replace string with bytes)

Fixes #1336

I think adding this makes sense in that we're trying to "hide" serialization details from the default use case and currently that wasn't possible if you just have a string (and not a file).

Please verify and check that the pull request fulfills the following
requirements
:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

Copy link
Contributor

@avelichka avelichka left a comment

Choose a reason for hiding this comment

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

LGTM :)

Copy link
Collaborator

@MVrachev MVrachev left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@joshuagl joshuagl left a comment

Choose a reason for hiding this comment

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

LGTM. Minor question inline.


Arguments:
data: metadata content as string.
deserializer: Optional; A MetadataDeserializer instance that
Copy link
Member

Choose a reason for hiding this comment

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

is this notation standard? Would we be better off just relying on the typing annotations to indicate optional arguments?

Copy link
Member Author

Choose a reason for hiding this comment

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

I saw that in a google style guide example -- could leave that out as well, it does duplicate the annotation...

Copy link
Member

Choose a reason for hiding this comment

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

Let's leave it for now. Could you create an issue to ensure we review docstrings and make sure they are consistent before we cut a release.

@jku
Copy link
Member Author

jku commented Apr 19, 2021

Let's not merge just yet, I'm still going to doublecheck whether str is the correct type -- the Metadata API seems to use bytes in some places

This is essentially short-hand for
    JSONDeserializer().deserialize(data)
but seems much easier for the API user so may be worth it.

Metadata.from_file() now uses Metadata.from_bytes() internally.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
@jku jku changed the title api: Add Metadata.from_string() api: Add Metadata.from_bytes() Apr 21, 2021
@jku
Copy link
Member Author

jku commented Apr 21, 2021

I had another look and decided bytes makes more sense than str:

  • a hypothetical serializer could take a binary format
  • Existing code already uses bytes (see api/serialization/)

@joshuagl want to have another look? (mostly this was a literal replace of string with bytes)

# Assert that it chokes correctly on an unknown metadata type
bad_metadata_path = 'bad-metadata.json'
bad_metadata = {'signed': {'_type': 'bad-metadata'}}
bad_string = json.dumps(bad_metadata).encode('utf-8')
Copy link
Member

Choose a reason for hiding this comment

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

Is indentation off here, or is it just the GitHub app?


Arguments:
data: metadata content as string.
deserializer: Optional; A MetadataDeserializer instance that
Copy link
Member

Choose a reason for hiding this comment

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

Let's leave it for now. Could you create an issue to ensure we review docstrings and make sure they are consistent before we cut a release.

@joshuagl
Copy link
Member

Looks good to me, thanks for the str->bytes change.

@jku
Copy link
Member Author

jku commented Apr 21, 2021

GitHub Actions has encountered an internal error when running your job. Seems to be https://www.githubstatus.com/incidents/cj7gzzj30411
Re-running...

@jku jku merged commit 41f7e80 into theupdateframework:develop Apr 21, 2021
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.

Implement from_object/from_string method in Metadata class
4 participants