https://toitlang.org/ logo
local packages registry error
# help
k
I created a local packages folder "T:\packages" and tried to add it to the registry using:
jag pkg registry add local t:\packages --local
it returned with:
Unhandled error: open C:\Users\Axel\.config\toit\config.yaml: Das System kann den angegebenen Pfad nicht finden.
=> then I copied
C:\Users\Axel\.config\jaguar\config.yaml
to
C:\Users\Axel\.config\toit
and the command above succeeded.
Copy code
jag pkg registry list
toit: github.com/toitware/registry (git)
local: t:\packages (local)
A path specification may need to be adjusted ?
Is it possible to use a 'global package' inside the example folder of a 'local package' ?
Copy code
import pixel_strip show *   // github.com/toitware/toit-pixel-strip
import rgb-strip show *     // local package
reports: Package for prefix 'pixel-strip' not found I struggle with package.yaml/.lock ? Does anyone have a tip?
f
Sorry. Didn't see your messages. Reading through them now.
Hmm. I will have a look at this. Looks like we are missing a check. Thanks for reporting.
Each package.yaml/lock has its own entries. If your example needs a package it needs to install it too.
So basically you just have to
jag pkg install pixel_strip
inside the examples folder.
k
ok, I thought the pixel_strip is a global package, installed in /.packages, and importable from all modules.🤔
f
The moment you have a
package.yaml/lock
you are a separate project.
Tests and examples often have different requirements than the actual package one is working with.
For exampel, the pixel_strip might be needed by the example, but not by every user of the package.
-> it's only in the examples.
Some other languages have separate sections (like "dev_dependencies" or so).
k
So but if I use this pixel_strip functionality inside own 'rgb-strip' package ?
f
Then you need to duplicate the work.
Alternatively, your package can export some of the classes if it really makes sense (quite rare).
Note that your users wouldn't benefit from the nesting either, so they would need to install the pixel_strip package themselves too.
What we could do, though, is have something like "suggested packages".
So if you install
rgb-strip
it could suggest to install
pixel_strip
too.
k
My intention with creating
rgb-strip
was to encapsulate PixelStrip, ByteArray, Colors, ... and to reuse that package in different applications. I thought if pixel_strip is globally installed in `.packages' and 'rgb-strip' is installed in 'local-packages'. And the jag apps have only to import a single rgb-strip definition.
f
Toit doesn't support that. It would make it hard to control which package gets which prefix... You shouldn't really think of "local" and external packages as different. They are pretty much the same, except that one is referring to code on your disk, while the other is downloaded.
What you can do is create a package/library that reexports code from multiple packages. Like:
Copy code
import pixel-strip show *
import something-else show *
export *
If you then import that library (in a package or not) you get all the types from it. However, it also means that you lose the prefix. So all of the identifiers would be mixed together. You could avoid that by having different files:
Copy code
// pixel-strip.toit
import pixel-strip show *
export *
Copy code
// something-else.toit
import something-else show *
export *
You could then
import merged.pixel-strip
or
import merged.something-else
.
That's probably the closest to what you want.
k
Copy code
import .color show *
import .bytearray show *

import pixel_strip show *
import gpio

export *

/**
Implements a universal (application independent) Neopixel led strip interface.
*/
class Rgb-Strip:
...
thats what I tried, but i always get an error after >>> import pixel_strip show *
f
Where is this file located?
k
in 'src'-folder
f
What's the package.yaml for that file?
What's the error message?
Copy code
PS T:\local-packages\rgb-strip\examples> jag run .\app.toit --device Radar
Scanning for  device with name: 'Radar'
Running '.\app.toit' on 'Radar' ...
<pkg:..>\rgb-strip.toit:4:8: error: Package for prefix 'pixel-strip' not found
import pixel_strip show *
       ^~~~~~~~~~~
Compilation failed
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x15b1a3b]

goroutine 1 [running]:
main.main()
        D:/a/jaguar/jaguar/cmd/jag/main.go:38 +0x1db
PS T:\local-packages\rgb-strip\examples>
f
Can you show me the package.lock file of the example folder?
f
Try running
jag pkg install
in your example folder
It looks like you changed the dependencies of the package but didn't rerun install. So it doesn't have all dependencies in the example folder yet.
k
Copy code
PS T:\local-packages\rgb-strip\examples> jag pkg install
Error: Failed to parse package description 'T:\local-packages\rgb-strip\package.yaml': %!w(*yaml.TypeError=&{[line 5: cannot unmarshal !!map into []tpkg.descPackage]})
PS T:\local-packages\rgb-strip\examples>
f
Ok. What if you run pkg install in the rgb-strip folder?
The error indicates that the package file is corrupted. I don't really see what's wrong, though
(not on my computer to test it)
k
Copy code
PS T:\local-packages\rgb-strip> jag pkg install
Error: Failed to parse package description 'T:\local-packages\rgb-strip\package.yaml': %!w(*yaml.TypeError=&{[line 5: cannot unmarshal !!map into []tpkg.descPackage]})`
f
Ok. So it really isn't happy with that file
Did you edit it by hand?
k
yes
f
It looks like one of these should be a list and is a map instead.
k
how can I generate a fresh one
f
Hmm. Isn't that the syntax of the lock file?
Remove package.* And then
jag pkg init
Then
jag pkg install toit-pixel-strip
k
Copy code
PS T:\local-packages\rgb-strip> jag pkg init
PS T:\local-packages\rgb-strip> jag pkg install toit-pixel-strip
Error: Description at 'T:\local-packages\rgb-strip\package.yaml' is missing a name
f
Right. Just add a
name
and
description
to your package file
That said: I'm surprised you need that just for
pkg install
.
I need to leave now, but I will read from time to time and try to answer. If you don't manage to get it to work, feel free to send me whatever you have and I will fix it.
k
Danke, sehr gerne:
f
I will have a look tomorrow. Please remind me if I forget.
k
😴
f
It was almost working. I just did, in the example folder:
Copy code
jag pkg init
jag pkg install --local ..
And then removed the
pixel_strip
line:
Copy code
// import pixel_strip show *   // github.com/toitware/toit-pixel-strip
With that everything worked.
I can send back the zip on request.
k
jag pkg init ==> creates empty package.yaml/.lock files jag pkg install --local .. ==> Error: Description at 'T:\local-packages\rgb-strip\examples\package.yaml' is missing a name
Copy code
PS T:\local-packages\rgb-strip\examples> jag pkg init
PS T:\local-packages\rgb-strip\examples> jag pkg install --local ..
Error: Description at 'T:\local-packages\rgb-strip\examples\package.yaml' is missing a name
f
which version of jaguar do you use?
k
PS T:\local-packages\rgb-strip\examples> jag version Version: v1.39.0 SDK version: v2.0.0-alpha.159 Build date: 2024-06-24T08:44:15Z
f
Could you try updating to the latest version?
k
nothing changed
Copy code
PS T:\local-packages\rgb-strip\examples> jag pkg init
PS T:\local-packages\rgb-strip\examples> jag pkg install --local ..
Error: Description at 'T:\local-packages\rgb-strip\examples\package.yaml' is missing a name
PS T:\local-packages\rgb-strip\examples> jag version
Version:         v1.41.0
SDK version:     v2.0.0-alpha.160
Build date:      2024-09-01T11:40:26Z
f
I don't see this. Maybe we have a bug with windows 😦
Let me send you the package files so you are unstuck. I'm in the middle of another debugging session, but I will investigate this.
I looked up the error. My current understanding is that it should only happen when the package-manager tries to parse a registry.
Could you do a
jag pkg registry list
?
If you added the example folder as registry folder, it might explain the error.
k
PS T:\local-packages\rgb-strip\examples> jag pkg registry list toit: github.com/toitware/registry (git) local: T:\local-packages (local)
f
right. That explains it.
I think I understand more what you are trying to do.
A local registry allows you to have packages that aren't visible on pkg.toit.io.
This makes it possible to write
jag pkg install xxx
where
xxx
is not on pkg.toit.io but only in your local registry.
I have started a process of rewriting our package manager and would like to remove local registries (and only support git repositories as registries), but for now it's supported and works.
A registry (local or not) is fundamentally just a bunch of description of available packages.
That is, in doesn't contain any code.
So if you want a local registry, you should point it to a "fresh" directory.
And then add descriptions to it.
Descriptions are generated by
jag pkg describe
By default they are geared for "global" access. That is, they want a url, version and hash. Let me check, how to make "local" package descriptions. (I'm pretty sure we use them for tests).
Nope. Looks like we only have git descriptions.
k
AHA: my idea ... - In the first step, I created the application containing the rgp-strip as sub folder. (it works) - then I moved the rgp-strip subfolder to a local-package and the app code into examples (to test the package) - possibly later, the local package could be pulished into the toit-package environment
f
For now you have to just
jag pkg install --local ...
I would like to add functionality so that you can tell
jag pkg
that it should add a certain local folder as
URL@version
for resolution.
This would make it much easier to test local packages (even if they are used transitively by other packages).
Unfortunately, that's not implemented yet.
As I said: I started rewriting the package manager (in Toit), and new features will probably have to wait until that is done.
In any case: you should remove the
local
registry again. Any
yaml
file in the local-packages folder will trip up the package manager.
k
Thank you for the support, I wil try ...
- app in examples folder runs - now trying to install the local package
Copy code
PS T:\> jag pkg install --local t:\rgb-strip
Info: Package 't:\rgb-strip' installed with name 'rgb-strip'
PS T:\> jag pkg list rgb-strip
Error: Failed to parse package description 'rgb-strip\examples\package.yaml': %!w(*yaml.TypeError=&{[line 2: cannot unmarshal !!map into []tpkg.descPackage]})
I don't understand why the yaml in examples is taken ?
if I rename yaml in examples to 'package.yaml_' and complete package.yaml in T:/pkg-strip to
Copy code
name: rgb-strip
description: Implements a universal (application independent) Neopixel led strip interface.
license: proprietary
version: v1.0.0
url: T:/rgb-strip
PS T:\> jag pkg list rgb-strip rgb-strip: rgb-strip - 1.0.0
f
Did you remove the local registry?
k
PS T:\> jag pkg registry list toit: github.com/toitware/registry (git) yes
f
hmm. Where does
jag pkg list
find the
rgb-strip
package from?
k
jag pkg install --local t:\rgb-strip
f
jag pkg list
lists all packages of a registry.
The argument must either be the name of a registry or a folder.
Wait.
hmm. No. Had a hunch that doesn't apply..
f
Right. That would be all packages that are in the default pkg registry.
When you did
jag pkg list rgb-strip
in which directory were you?
was there a folder
rgb-strip
there?
k
I generated the list in project root 'T:/'
f
I just reread the failed command.
Makes complete sense.
Copy code
jag pkg list rgb-strip
Error: Failed to parse package description 'rgb-strip\examples\package.yaml': %!w(*yaml.TypeError=&{[line 2: cannot unmarshal !!map into []tpkg.descPackage]})
You are asking
jag pkg list
to list all packages that are in the registry folder 'rgb-strip'.
However that folder isn't a registry.
It's your package.
(for a registry all yaml files are treated like package descriptions).
So the question now: what did you intend to do with
jag pkg list rgb-strip
?
And maybe the same question for:
jag pkg install --local t:\rgb-strip
k
I wanted to check if the installation of the local package 'rgb-strip' worked. In the next step i want to use that package in a app
import rgb-strip show *
f
The easiest way to check is to have a look at your package.lock file.
But since there wasn't any error you should be good.
f
exactly. Your current project now has a package
rgb-strip
at the given path.
k
So for a new app referencing to pkg rgb-strip , I have to create a yaml file with dependencies ?
f
You have to
jag pkg init
and
jag pkg install --local t:\rgb-strip
That should do it.
That will download all of rgb-strip's dependencies and then give you access to them through
rgb-strip
(since you do an export from it).
k
Installing container 'APP' from 'app.toit' on 'Radar' ... T:\Test-rgb-strip\Package-App\package.lock:5:11: error: Package '/T:/rgb-strip' not found at 'T:\Test-rgb-strip\Package-App\T:\rgb-strip' path: /T:/rgb-strip
f
argh.
That looks like a Windows bug.
I will look into this. In the meantime you can work around it by installing the package with a relative path.
k
ok solved! packages: rgb-strip: path: T:/rgb-strip
The preceeding / was too much for the path
f
So you changed the package.lock file by hand?
k
yes For me it took a long way with a lot fumbling, and i have to repeat this again ...
f
It's definitely a bug in the package manager.
I have it already on my TODO list.
k
Nevertheless Thank you for the support
f
Very welcome. Sorry you are encountering so many issues...
k
the life of a scout 😅
2 Views