-
Notifications
You must be signed in to change notification settings - Fork 0
/
legend_julia_setup.jl
94 lines (79 loc) · 2.78 KB
/
legend_julia_setup.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import Pkg
# Activate default environment
# Can't use `Pkg.activate()` with stacked depots if first(DEPOT_PATH) doesn't exist:
Pkg.activate(joinpath(first(DEPOT_PATH), "environments", "v$(VERSION.major).$(VERSION.minor)"))
# Will also create he environment if it doesn't exist:
Pkg.instantiate()
if !ispath(joinpath(first(DEPOT_PATH), "registries", "LegendJuliaRegistry"))
@info("Installing Legend Julia package registry")
Pkg.Registry.add("General")
Pkg.Registry.add(url = "https://github.com/legend-exp/LegendJuliaRegistry.git")
else
@info("Legend Julia package registry seems to be installed already.")
end
if !("IJulia" in keys(Pkg.project().dependencies))
@info "Installing IJulia into default Julia environment \"$(Pkg.project().path)\""
Pkg.add("IJulia"); Pkg.build("IJulia")
end
if !("Revise" in keys(Pkg.project().dependencies))
@info "Installing IJulia into default Julia environment \"$(Pkg.project().path)\""
Pkg.add("Revise")
end
config_dir = joinpath(first(DEPOT_PATH), "config")
mkpath(config_dir)
startup_jl = joinpath(config_dir, "startup.jl")
if !isfile(startup_jl)
@info "Adding Revise initialization code to \"$startup_jl\"."
write(startup_jl,
"""
try
using Revise
catch e
@warn "Error initializing Revise, try adding Revise.jl to your environment" exception=(e, catch_backtrace())
end
"""
)
else
@warn "File \"$startup_jl\" already exists, not adding Revise initialization code automatically."
end
startup_ijulia_jl = joinpath(config_dir, "startup_ijulia.jl")
if !isfile(startup_ijulia_jl)
@info "Adding Revise initialization code to \"$startup_ijulia_jl\"."
write(startup_ijulia_jl,
"""
try
@eval using Revise
catch e
@warn "Error initializing Revise" exception=(e, catch_backtrace())
end
"""
)
else
@warn "File \"$startup_ijulia_jl\" already exists, not adding Revise initialization code automatically."
end
try
@eval using Revise
catch e
@warn "Error initializing Revise" exception=(e, catch_backtrace())
end
if contains(get(ENV, "LD_LIBRARY_PATH", ""), r"/cuda|/nvidia")
@info "LD_LIBRARY_PATH contains \"cuda\", will use system CUDA installation"
local_prefs_toml = joinpath(dirname(Pkg.project().path), "LocalPreferences.toml")
if !isfile(local_prefs_toml)
@info "Adding setting to use system CUDA to \"$local_prefs_toml\"."
write(local_prefs_toml,
"""
[CUDA_Runtime_jll]
local = "true"
version = "local"
"""
)
else
@warn "File \"$local_prefs_toml\" already exists, not setting local CUDA setting."
end
if !("CUDA_Runtime_jll" in keys(Pkg.project().dependencies))
@info "Installing CUDA_Runtime_jll into default Julia environment \"$(Pkg.project().path)\""
Pkg.add("CUDA_Runtime_jll")
end
end
@info "All done, enjoy using Julia for LEGEND!"