A Chicken Scheme equivalent to Python's virtualenv?
Asked Answered
P

4

5

Is there a way to create an equivalent of Python's virtual environments (virtualenv)? With virtualenvs, one can install Python packages inside the virtual environment (a separate directory) without messing up the global python environment. One can remove packages that one decides they don't need without worrying about removing a package that is depended upon by another Python project. I'm sure there are other benefits that I'm not thinking of at the moment. I notice that when I use chicken-install, it installs all of the eggs in my /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/ dir. Is there a way to have them install that egg in a project specific directory similarly to how Python's virtualenv works?

Perretta answered 6/10, 2017 at 19:34 Comment(0)
S
4

There isn't really such a thing in CHICKEN 4. The problem here is that installing eggs to a different location is one part, the other is running programs so that they look up eggs in that location. You can emulate it by using something along these lines:

export LOCAL_EGGS=/path/to/project/local
chicken-install -init $LOCAL_EGGS
export CHICKEN_REPOSITORY=$LOCAL_EGGS
chicken-install r7rs ...
csc ...
Sidelight answered 7/10, 2017 at 6:56 Comment(0)
O
3

The easiest way to do this is to simply install CHICKEN to a different location using the PREFIX option to make when building it (see the README for instructions). This allows you to have a CHICKEN specifically built for each of your projects. I vastly prefer this option over the others because it is very easy to understand, and CHICKEN itself is very fast to build and not very big, so I find the overhead of doing this quite acceptable.

Alternatively, use what wasamasa proposed, or use the -deploy option to install eggs with the program. See the deployment chapter in the manual for more info.

Oxidate answered 7/10, 2017 at 16:36 Comment(0)
B
3

Actually you don't need any "virtual environment" - everything already in place.

There is straightforward way to change repository location:

CHICKEN_INSTALL_REPOSITORY is the place where eggs will be installed and which the egg-related tools like chicken-install, chicken-uninstall and chicken-status consult and update. Make sure the paths given in these environment variables are absolute and not relative.

and

CHICKEN_REPOSITORY_PATH is a directory (or a list of directories separated by :/;) where eggs are to be loaded from for all chicken-based programs.

Point CHICKEN_INSTALL_REPOSITORY to the location where you want it to be. Note that you need to point CHICKEN_REPOSITORY_PATH to your local repository as well as system one in order to be able to import extensions distributed with Chicken system.

Also you most likely need to setup installation prefix:

An alternative installation prefix that will be prepended to extension installation paths if specified. It is set by the -prefix option or environment variable CHICKEN_INSTALL_PREFIX.

and update your PATH:

PATH="$CHICKEN_INSTALL_PREFIX/bin:$PATH"

This allows you to install extensions which provide console programs.

The only thing left to do is export all these variables.

That's it!

This is basically what Python's virtualenv activate script does in essence. As you can see, this is very simple steps to do. You don't need a dedicated tool to manage that. A very simple shell script can serve very well.

How it works?

This works by introducing an one more depth level local hierarchy, (as it does for /usr and /usr/local, please, see FHS). If you wonder what the hell is local hierarchy, take a look at your $HOME/.local - probably you have something interesting inside.

Bonus

As far as setting up per-project extensions repository involves only environment modification, this definitely can be automated. There is very handy tool to solve this kind of problems in general: direnv. Using this simple function in your $HOME/.envrc:

use_chicken() {
    LOCAL=$(expand_path .local)

    system_repository=$(chicken-install -repository)
    binary_version=${system_repository##*/}

    local_repository=${LOCAL}/lib/chicken/${binary_version}

    path_add CHICKEN_REPOSITORY_PATH ${system_repository}
    path_add CHICKEN_REPOSITORY_PATH ${local_repository}

    export CHICKEN_REPOSITORY_PATH
    export CHICKEN_INSTALL_REPOSITORY=${local_repository}
    export CHICKEN_INSTALL_PREFIX=${LOCAL}

    PATH_add ${LOCAL}/bin
}

you can setup your Chicken project just with these two lines in .envrc inside project directory:

source_up
use chicken
Bolanos answered 18/4, 2020 at 18:30 Comment(3)
It would be very helpful to future readers if you could add a link in your answer to where these environment variables are documented, and if you could state which version(s) of Chicken it applies to. It's also worth nothing that Python Venv and its big sister Virtualenv (in principle) both work in much the same way that you showed here.Raffinose
Isn't it already what the answer about? There is even links to documentation as well.Bolanos
I missed the link to the docs, never mind :)Raffinose
P
2

I know https://github.com/ursetto/cenv exists (never used it myself), and it is for CHICKEN 5 only, though (it won't work with CHICKEN 4). Thought about mentioning it in case you plan to migrate to CHICKEN 5.

Pyrophyllite answered 19/4, 2020 at 17:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.