samdphillips / raco-pkg-env

virtualenv like tool for Racket
Other
31 stars 2 forks source link

Error reading collection links file #8

Open countvajhula opened 2 years ago

countvajhula commented 2 years ago

I created a new package and added a basic info.rkt file. Then I went through these steps:

mynewpkg> raco pkg-env _env
mynewpkg> source _env/activate.sh
mynewpkg> raco pkg install

And got this error:

error reading collection links file #<path:/Users/siddhartha/work/racket/sandbox/mynewpkg/_env/links.rktd>: path->complete-path: contract violation
  expected: (or/c path-string? path-for-some-system?)
  given: 'up
path->complete-path: contract violation
  expected: (or/c path-string? path-for-some-system?)
  given: 'up

The info.rkt file, for reference:

#lang info
(define collection "mynewpkg")
(define deps '("base"))
(define build-deps '("scribble-lib"
                     "scribble-abbrevs"
                     "racket-doc"
                     "rackunit-lib"
                     "sandbox-lib"))
(define pkg-desc "A cool new package.")
(define version "1.0")
(define pkg-authors '(countvajhula))
countvajhula commented 2 years ago

The _env/links.rktd file looks like this:

(("mynewpkg" (up))
 ("scribble-abbrevs" (#"pkgs" #"scribble-abbrevs"))
 (root (#"pkgs" #"reprovide-lang-lib"))
 ("rackunit-abbrevs" (#"pkgs" #"rackunit-abbrevs"))
 (root (#"pkgs" #"lang-file-lib"))
 (root (#"pkgs" #"syntax-macro-lang")))

It does say up there -- I'm on Mac OSX, in case that's relevant.

samdphillips commented 2 years ago

I think the problem is that the package directory cannot be inside of a collection like this.

I'll check when i get home.

On Tue, Apr 19, 2022, 15:52 Siddhartha Kasivajhula @.***> wrote:

The _env/links.rktd file looks like this:

(("mynewpkg" (up)) ("scribble-abbrevs" (#"pkgs" #"scribble-abbrevs")) (root (#"pkgs" #"reprovide-lang-lib")) ("rackunit-abbrevs" (#"pkgs" #"rackunit-abbrevs")) (root (#"pkgs" #"lang-file-lib")) (root (#"pkgs" #"syntax-macro-lang")))

It does say up there -- I'm on Mac OSX, in case that's relevant.

— Reply to this email directly, view it on GitHub https://github.com/samdphillips/raco-pkg-env/issues/8#issuecomment-1103239789, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADJ37SQSDX22FX4XVM36D3VF42LZANCNFSM5T2HW34Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>

samdphillips commented 2 years ago

I've confirmed the env directory needs to be outside of a collection. Setting up like this works:

sam@shardik:~/tmp$ mkdir project
sam@shardik:~/tmp$ cd project/
sam@shardik:~/tmp/project$ raco pkg new test-package
Initializing license (Apache-2.0 OR MIT). You are free to change the license.
sam@shardik:~/tmp/project$ raco pkg-env _env
sam@shardik:~/tmp/project$ source _env/activate.sh
sam@shardik:~/tmp/project$ raco pkg install --link test-package
raco setup: version: 8.4
raco setup: platform: x86_64-linux [cs]
raco setup: target machine: ta6le
raco setup: installation name: 8.4
raco setup: variants: cs
... a lot of messages ...
... maybe some errors about permissions depending on how Racket was installed ...
sam@shardik:~/tmp/project$ raco pkg show
/usr/local/stow/racket-8.4/share/racket/pkgs:
 Package            Checksum             Source
 main-distribution  bd4ec185d1ecc7a8...  catalog...tribution
 racket-lib         6b115615e96d691c...  catalog racket-lib
 [202 auto-installed packages not shown]
Installation-wide:
 Package       Checksum  Source
 test-package            link /home/sam/tmp/project/test-package
countvajhula commented 2 years ago

I went through your steps and that worked! But when I try with the original test project in the issue description, I now get a different error:

raco setup: 2 making: <pkgs>/racket-doc/syntax/scribblings/parse
ffi-lib: could not load foreign library
  path: libintl.9.dylib
  system error: dlopen(libintl.9.dylib, 6): image not found
  context...:
   /Applications/Racket-Latest/collects/ffi/unsafe.rkt:131:0: get-ffi-lib
   body of "/Applications/Racket-Latest/share/pkgs/draw-lib/racket/draw/unsafe/glib.rkt"

And when I do raco pkg show, it shows all of my installed packages and not just the ones in the current activated environment (I verified that $PLTCONFIGDIR points to the local _env). Is that to be expected?

samdphillips commented 2 years ago

I'm not sure about the ffi-lib error. The environment overrides the installation scope and leaves the user scope, so normally installed packages are still visible.

This package is mostly an exercise proof of concept to get something working without changing core Racket. To make something more robust and useful, I think Racket should switch to having an installation scope and a configurable layering scope, with the default scope being the current "user" scope.

samdphillips commented 2 years ago

I'm not sure about the ffi-lib error.

This may be failing because something needed for scribble is missing in the installation scope.

countvajhula commented 2 years ago

I'm not sure about the ffi-lib error. This may be failing because something needed for scribble is missing in the installation scope.

This error is actually no longer happening. Might have just been a transient thing 🤷

This package is mostly an exercise proof of concept to get something working without changing core Racket. To make something more robust and useful, I think Racket should switch to having an installation scope and a configurable layering scope, with the default scope being the current "user" scope.

Do you mean that instead of there being two hardcoded scopes, installation and user, that this should be generalized to scope "layers", where these existing ones are each now individual default layers with the latter (user) layered on top of the former (installation)? And then a package like raco-pkg-env could add new layers and enable/disable existing ones? That sounds like a flexible way to do it, and seems reminiscent of lexical scope which is similarly layered.

So I guess for the moment this package would only be able to swap out the bottom (installation scope) layer? That may still be useful enough for a lot of cases. Out of curiosity, would it be possible to also disable the user scope so that it's a "tabula rasa" environment? Not sure if that would necessarily be more convenient or not, since installing just the basic dependencies in the example info.rkt file above took something like 20 minutes (racket-doc seems to depend on pict and a zillion other packages)! So maybe piggybacking off of user scope would be the most convenient in practice, anyway.

I've added raco-pkg-env to the Contributing instructions for Qi, as one way to install locally for development 😺

countvajhula commented 2 years ago

Actually, thinking again, the instructions I added only work if we are able to disable user scope, since otherwise it complains that the package you are trying to install in the virtual environment is already installed (in user scope). Is there a way to disable or override user scope?

samdphillips commented 2 years ago

So a straightforward and easy way to use a different user scope is to set PLTUSERHOME to a different location. I've tested this on Linux, and it works fine. It should also work on Mac. Windows 🤷🏼

sam@shardik:~$ mkdir tmp
sam@shardik:~$ PLTUSERHOME="$HOME/tmp" raco pkg show
Installation-wide:
 Package            Checksum             Source
 main-distribution  bd4ec185d1ecc7a8...  catalog...tribution
 racket-lib         6b115615e96d691c...  catalog racket-lib
 [202 auto-installed packages not shown]
User-specific for installation "8.4":
 [none]
sam@shardik:~$ PLTUSERHOME="$HOME/tmp" raco pkg install --auto qi
... several minutes later qi and deps are all in tmp ...
countvajhula commented 2 years ago

Would it be worth adding a flag to raco-pkg-env to create an environment like this?

Something like:

raco-pkg-env --empty _env

And then

source _env/activate.sh

would set PLTCONFIGDIR the way it currently does, but also set PLTUSERHOME to _env/home (or another appropriate folder within _env).

Would be a little more convenient than managing environment variables directly - and could gain additional features over time. Wdyt?