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

Manifest creation helper #1103

Merged
merged 7 commits into from
Mar 22, 2023
Merged

Manifest creation helper #1103

merged 7 commits into from
Mar 22, 2023

Conversation

approxit
Copy link
Contributor

@approxit approxit commented Feb 16, 2023

What I've done:

  • Implemented initial DTO for objects from schema drafts found in GAP4 and GAP5.
  • Only dataclasses are used...
  • ...but with .dict(by_alias) and .parse_obj(obj) methods that reflects methods found in pydantic as this kind of models are just pydantic aim
  • Additionally .parse_imploded_obj(obj) to ease with providing nested structures
  • Tests to have coverage for new code

As this kind of DTOs should be implemented in pydantic, this should be mentioned as work item in golemfactory/golem-core-python#54.

Keep in mind, that parsing object is quite a complex task. This implementation is not mentioned to be so robust as pydantic's. .parse_obj(obj) is just "base minimum".

Also exploding nested dicts is very easy task, but supporting exploding dicts with lists... oh boy, code complexity explodes too... I'm not very happy how it turned out, but at least its working and its covered with tests.

@approxit approxit linked an issue Feb 16, 2023 that may be closed by this pull request
@approxit approxit requested a review from shadeofblue February 22, 2023 10:18
@approxit approxit self-assigned this Feb 22, 2023
@shadeofblue
Copy link
Contributor

as mentioned in the original issue: #1090

the ultimate goal here is to have a helper function able to generate a valid manifest with minimal, obligatory input, e.g.:

manifest = generate_manifest(
   {
      "payload": manifest_payload("sha3:05270a8a938ff5f5e30b0e61bc983a8c3e286c5cd414a32e1a077657"),
      "net.inet.out.urls": ["http://bor.golem.network"],
   }
)

@approxit approxit marked this pull request as ready for review February 27, 2023 12:19
@approxit approxit requested review from a team and lucekdudek February 27, 2023 12:19
@approxit approxit marked this pull request as draft February 27, 2023 12:33
@approxit approxit marked this pull request as ready for review March 3, 2023 10:12
@approxit approxit force-pushed the 1090-manifest-creation-helper branch from 4e6e54c to 57f171c Compare March 7, 2023 15:03
else:
from typing_extensions import Literal

from dateutil.tz import UTC
Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm, isn't this the same as datetime.timezone.utc?

homepage: Optional[str] = None
description: Optional[str] = None

def dict(self, *, by_alias=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

can't we use dataclasses.asdict here?

homepage: Optional[str] = None
description: Optional[str] = None

def dict(self, *, by_alias=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

plus, I believe you're not using the by_alias ... again, no warnings from linters?

Copy link
Contributor

@shadeofblue shadeofblue left a comment

Choose a reason for hiding this comment

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

@approxit I believe the implementation is mostly as good as it can be given the use of plain dataclasses ... I have added a couple of questions/suggestions

the important ones concern the retrieval of an external network resource in unit tests - I'd very much like those to be mocked ...

plus, am I missing something or does this pull request still contain no helper mentioned in the original task?

cls, image_hash: str = None, outbound_urls: List[str] = None, **kwargs
) -> "Manifest":
if image_hash is not None:
kwargs["payload.0.hash"] = image_hash
Copy link
Contributor

Choose a reason for hiding this comment

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

it's almost perfect but the manifest, afaik, must also contain the image url ;)

@approxit approxit force-pushed the 1090-manifest-creation-helper branch from ea1dc5d to c0e5c9c Compare March 22, 2023 15:10
@approxit approxit force-pushed the 1090-manifest-creation-helper branch from c0e5c9c to 5398306 Compare March 22, 2023 15:59
@shadeofblue shadeofblue merged commit b506c24 into master Mar 22, 2023
@shadeofblue shadeofblue deleted the 1090-manifest-creation-helper branch March 22, 2023 17:34
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.

manifest creation helper
3 participants