"virtualenv"-like installation

I have multiple repos on my computer that require different / incompatible versions of a library. (Because I develop both the clients and the library and sometimes need to make coordinated changes.) It's a pain to switch what version I have installed constantly. I see from the documentation that you can pass --scope <dir> to raco pkg install but what I can't figure out is how to tell Racket to look in that directory first.

I'm happy to pass extra arguments to Racket or set environment variables or similar. I tried reading the documentation but that only made me more confused; it looks like I need to make a config.rktd file but I couldn't figure out which of the many paths I actually need to configure. But basically I want to be able to install library version A in one place and library version B in another place and then, when I run a client, point to the correct place.

1 Like

Perhaps try Sam's https://docs.racket-lang.org/raco-pkg-env/index.html ? I am writing late and tired, though, so I'm replying more to the subject line than the body :wink:

Sure... There's not much documentation but looking at the source it looks like it works by making the same config.rktd mechanism, and then it looks like inside that it sets up separate lib, share, etc directories. Is this really the best way?

I have this issue a lot when I work with Racket (where "library" means "racket library" and not "libxyz.o") and what I do is just have two versions of racket, each in their own directory, each with their own "raco pkg update --clone" version of the libraries that I'm developing. It may feel like overkill to always build two copies of racket it's pretty smooth overall, I'd say. The only thing you need is to switch your path between the two.

In addition to making it easy to do coordinated changes, this strategy even (kind of) works when one of things you're working on is a dependency of DrRacket and yet you still want to use DrRacket to develop it, the trick for that being that you make sure the base racket version is the same in both builds, then often check syntax's expansion process will come out with "same enough" results as .zo files get mixed across installations. If you're in that boat, relative requires can make a big difference, as you'll be editing a file from the first installation with the second installation so absolute requires will end up coming from the second installation instead of the first. Which you may or may not want, depending on the details .... If you're not in this boat, then just ignore this paragraph :).

All that said, this may not be solving the problem that you face. Apologies if so!

If you're in a situation where the packages you work on can be conveniently installed in user scope as opposed to installation scope[*], then you could switch between sets of user-scope packages with

raco pkg config -i --set name <name-that-you-pick>

This would shift among user-scope sets of packages because the name of an installation determines the default path to the user-specific add-on directory, and user-scope packages and metadata are kept in the add-on directory. The default name of an installation is its version number (unless you build from a Git checkout, in which case it's "development").

[*] The user-scope requirement is the part that doesn't work so well for Robby. He would basically have to put everything in user scope, and then a shared minimal Racket doesn't buy much. So, Robby has separate installations and keeps everything in installation scope. That's also the mode most directly support by a Git checkout build, which not only has the name "development" but also sets installation scope as the default for new packages.

1 Like

One other thing to mention is that if you use multiple installations of Racket, you can switch among them easily using this set of tools: GitHub - takikawa/racket-dev-goodies: Scripts for Racket developers