Browse Source

Initial push

master
Micah Halter 9 months ago
parent
commit
41108543d8
Signed by: mehalter GPG Key ID: 4224A6EA9A8CAAA8
5 changed files with 112 additions and 1 deletions
  1. +8
    -0
      .gitignore
  2. +7
    -0
      Project.toml
  3. +3
    -1
      README.md
  4. +57
    -0
      assets/activate
  5. +37
    -0
      src/VirtualEnv.jl

+ 8
- 0
.gitignore View File

@ -24,3 +24,11 @@ docs/site/
# environment.
Manifest.toml
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

+ 7
- 0
Project.toml View File

@ -0,0 +1,7 @@
name = "VirtualEnv"
uuid = "f8ef4a19-0666-4e54-aa90-5d6169a53550"
authors = ["Micah Halter <micah@mehalter.com>"]
version = "0.1.0"
[compat]
julia="1.0"

+ 3
- 1
README.md View File

@ -1,3 +1,5 @@
# VirtualEnv.jl
Self contained virtual environments for Julia.
Self contained virtual environments for Julia.
`julia -e 'using VirtualEnv; venv("env")'`

+ 57
- 0
assets/activate View File

@ -0,0 +1,57 @@
#!/bin/sh
deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
PATH="${_OLD_VIRTUAL_PATH:-}"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_DEPOT_PATH:-}" ] ; then
JULIA_DEPOT_PATH="${_OLD_DEPOT_PATH:-}"
export JULIA_DEPOT_PATH
unset _OLD_DEPOT_PATH
fi
if [ -n "${_OLD_LOAD_PATH:-}" ] ; then
JULIA_LOAD_PATH="${_OLD_LOAD_PATH:-}"
export JULIA_LOAD_PATH
unset _OLD_LOAD_PATH
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r
fi
unset VIRTUAL_ENV
if [ ! "${1:-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}
# unset irrelevant variables
deactivate nondestructive
VIRTUAL_ENV="__VENV_DIR__"
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/__VENV_BIN_NAME__:$PATH"
export PATH
_OLD_DEPOT_PATH="$JULIA_DEPOT_PATH"
JULIA_DEPOT_PATH="__VENV_DIR__"
export JULIA_DEPOT_PATH
_OLD_LOAD_PATH="$JULIA_LOAD_PATH"
JULIA_LOAD_PATH=":"
export JULIA_LOAD_PATH
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r
fi

+ 37
- 0
src/VirtualEnv.jl View File

@ -0,0 +1,37 @@
""" VirtualEnv
Module to provide the ability to create self-contained julia virtual environments.
"""
module VirtualEnv
export venv
assetsdir() = normpath(joinpath(dirname(@__FILE__), "..", "assets"))
function venv(env::String)
if ispath(env)
println("ERROR: Folder ", env, " exists")
exit(1)
end
venv_dir = abspath(env)
bin_name = "bin"
bin_dir = joinpath(venv_dir, bin_name)
julia_exec = ENV["_"]
activate_exec = joinpath(assetsdir(), "activate")
mkpath(bin_dir)
symlink(julia_exec, joinpath(bin_dir, "julia"))
open(joinpath(bin_dir, "activate"), "w") do io
for line in eachline(activate_exec)
line = replace(line, "__VENV_DIR__" => venv_dir)
line = replace(line, "__VENV_BIN_NAME__" => bin_name)
write(io, string(line, "\n"))
end
end
end
end

Loading…
Cancel
Save