/
dependencies.jl
42 lines (36 loc) · 1.02 KB
/
dependencies.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
using Pkg
function is_installed(package::AbstractString)
try
Pkg.installed(package)
return true
catch
return false
end
end
function download_packages(file_path::AbstractString)
# Read the file and retrieve the import statements
file = open(file_path, "r")
imports = readlines(file)
close(file)
# Download and import the packages
for package in imports
package = strip(package)
if !is_installed(package)
try
Pkg.add(package)
println("Successfully downloaded and added $package")
catch err
println("Failed to download and add $package: $err")
continue
end
end
try
eval(Meta.parse("import $package"))
println("Successfully imported $package")
catch err
println("Failed to import $package: $err")
end
end
end
# Provide the file path of the imports.txt file
download_packages("imports.txt")