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

feat(gnovm): packages loader #2932

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft

Conversation

n0izn0iz
Copy link
Contributor

@n0izn0iz n0izn0iz commented Oct 10, 2024

WIP

Continuation of #2201
Taking #2904 into account

This implements a Load function with a similar interface to the packages.Load go function

Screenshot 2024-10-11 at 13 50 18
Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@github-actions github-actions bot added 🧾 package/realm Tag used for new Realms or Packages. 📦 🤖 gnovm Issues or PRs gnovm related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Oct 10, 2024
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.34%. Comparing base (d03581e) to head (2d9fc96).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2932      +/-   ##
==========================================
- Coverage   63.37%   63.34%   -0.04%     
==========================================
  Files         566      566              
  Lines       79490    79200     -290     
==========================================
- Hits        50374    50166     -208     
+ Misses      25727    25670      -57     
+ Partials     3389     3364      -25     
Flag Coverage Δ
contribs/gnodev 60.57% <ø> (ø)
contribs/gnofaucet 14.82% <ø> (ø)
gno.land 67.37% <ø> (ø)
misc/genstd 79.72% <100.00%> (ø)
tm2 62.33% <ø> (-0.06%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
@n0izn0iz n0izn0iz changed the title feat(gnovm): package resolver lib feat(gnovm): packages loader Oct 11, 2024
Signed-off-by: Norman Meier <[email protected]>
@@ -0,0 +1 @@
module gno.land
Copy link
Member

Choose a reason for hiding this comment

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

do we need this file?

if we need it, please explain in a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please see #2904 (comment) and tell me what you think

Copy link
Contributor Author

@n0izn0iz n0izn0iz Oct 11, 2024

Choose a reason for hiding this comment

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

I think the best would be to have a gno.work file at repo root to support multiple modules in a monorepo
But in that case we need to implement the gno work commands

@@ -40,7 +40,7 @@ func TestMachineTestMemPackage(t *testing.T) {
Name: tt.name,
F: func(t2 *testing.T) { //nolint:thelper
rootDir := filepath.Join("..", "..")
store := TestStore(rootDir, "test", os.Stdin, os.Stdout, os.Stderr, ImportModeStdlibsOnly)
store := TestStore(rootDir, "test", nil, os.Stdin, os.Stdout, os.Stderr, ImportModeStdlibsOnly)
Copy link
Member

Choose a reason for hiding this comment

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

create a variable that you set to nil, so we now what is this parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 0123512

func DownloadModule(pkgPath string, dst string) error {
modFilePath := filepath.Join(dst, ModfileName)
if _, err := os.Stat(modFilePath); os.IsNotExist(err) {
fmt.Fprintln(os.Stderr, "gno: downloading", pkgPath)
Copy link
Member

Choose a reason for hiding this comment

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

we usually don't use os.StdXXX, but stdouterr from a struct (io something) which is passed when needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in e648305

}
}

// write gno.mod
Copy link
Member

Choose a reason for hiding this comment

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

do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it depends, but to keep sanity, I think we do, see: #2904 (comment)

Copy link
Contributor Author

@n0izn0iz n0izn0iz Oct 11, 2024

Choose a reason for hiding this comment

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

If you first download a sub-module, for example gno.land/p/demo/json/eisel_lemire
it will create the $GNOHOME/pkg/mod/gno.land/p/demo/json directory since it's a parent directory.
To know that the gno.land/p/demo/json package needs to be downloaded, I'm checking for the presence of $GNOHOME/pkg/mod/gno.land/p/demo/json/gno.mod

@@ -617,3 +592,21 @@ func shouldRun(filter filterMatch, path string) bool {
ok, _ := filter.matches(elem, matchString)
return ok
}

// Adapted from https://yourbasic.org/golang/formatting-byte-size-to-human-readable-format/
func prettySize(nb int64) string {
Copy link
Member

Choose a reason for hiding this comment

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

why moving this from util?

Copy link
Contributor Author

@n0izn0iz n0izn0iz Oct 11, 2024

Choose a reason for hiding this comment

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

conflict resolution fail, reverted in 53c5770

Dir string `json:",omitempty"`
ImportPath string `json:",omitempty"`
Name string `json:",omitempty"`
Root string `json:",omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

add comments to explain the fields.

this one for instance, is it the "location of the package that can be either specified locally or automatically cached on the disk"? or something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 457b0c9

n0izn0iz and others added 7 commits October 11, 2024 17:46
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
Signed-off-by: Norman Meier <[email protected]>
@thehowl
Copy link
Member

thehowl commented Oct 17, 2024

Thanks <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: No status
Status: Triage
Development

Successfully merging this pull request may close these issues.

3 participants