diff --git a/Artifacts.toml b/Artifacts.toml new file mode 100644 index 0000000..18f7fc6 --- /dev/null +++ b/Artifacts.toml @@ -0,0 +1,25 @@ +[[heta_app]] +arch = "x86_64" +git-tree-sha1 = "fe79a7d34e362a7038a8ee7b7b5653a0895eba22" +libc = "glibc" +os = "linux" + + [[heta_app.download]] + sha256 = "4dde32c2ba534e51b25030ed409d926008ff4ce44023f80d983810625bd54abd" + url = "https://github.com/hetalang/heta-compiler/releases/download/v0.8.6/heta-compiler-linux.tar.gz" +[[heta_app]] +arch = "x86_64" +git-tree-sha1 = "93c1330a1dce7f8aa62214c0cb5e612c02187956" +os = "windows" + + [[heta_app.download]] + sha256 = "a0611f5ca671bd67edda6fbb062322ca89dbe2f4f0852ea8db30788f43c789c7" + url = "https://github.com/hetalang/heta-compiler/releases/download/v0.8.6/heta-compiler-windows.tar.gz" +[[heta_app]] +arch = "x86_64" +git-tree-sha1 = "367cd23e5cbfebcd8f0c175703fbe7da734e4039" +os = "macos" + + [[heta_app.download]] + sha256 = "f8d6b97cc06a9fc51e1c99f4383450c778f4067e7880fff3d709f2a510a3b230" + url = "https://github.com/hetalang/heta-compiler/releases/download/v0.8.6/heta-compiler-macos.tar.gz" diff --git a/Project.toml b/Project.toml index a1482b0..4598acf 100644 --- a/Project.toml +++ b/Project.toml @@ -14,8 +14,8 @@ LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" NLopt = "76087f3c-5699-56af-9a33-bf431cd00edd" NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" -NodeJS = "2bd173c7-0d6d-553b-b6af-13a54713934c" OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca" RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" @@ -31,7 +31,6 @@ Distributions = "0.25" LabelledArrays = "1.6.1" NLopt = "0.6" NaNMath = "1" -NodeJS = "2" OrdinaryDiffEq = "6" ProgressMeter = "1" RecipesBase = "1" diff --git a/README.md b/README.md index 9e20880..8e3d565 100644 --- a/README.md +++ b/README.md @@ -33,12 +33,7 @@ julia> ] (@v1.10) pkg> add HetaSimulator ``` -Internally HetaSimulator uses heta-compiler. -Sometimes it is required to update the compiler's version. -```julia -# update heta compiler for v0.8.4 -julia> heta_update("0.8.4") -``` +Internally HetaSimulator installs Heta compiler as an artifact. ## Basic usage diff --git a/artifacts_scripts/Project.toml b/artifacts_scripts/Project.toml new file mode 100644 index 0000000..26df56d --- /dev/null +++ b/artifacts_scripts/Project.toml @@ -0,0 +1,3 @@ +[deps] +ArtifactUtils = "8b73e784-e7d8-4ea5-973d-377fed4e3bce" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" diff --git a/artifacts_scripts/build_artifacts.jl b/artifacts_scripts/build_artifacts.jl new file mode 100644 index 0000000..dc2f718 --- /dev/null +++ b/artifacts_scripts/build_artifacts.jl @@ -0,0 +1,21 @@ +using ArtifactUtils +using Pkg.Artifacts + +const HETA_COMPILER_RELEASE = "v0.8.6" + +const artifacts_toml = joinpath(@__DIR__, "..", "Artifacts.toml") + +for os in ("linux", "windows", "macos") + + url = "https://github.com/hetalang/heta-compiler/releases/download/$HETA_COMPILER_RELEASE/heta-compiler-$os.tar.gz" + platform = Artifacts.Platform("x86_64", os) + + add_artifact!( + artifacts_toml, + "heta_app", + url; + platform, + force = true, + lazy = false, + ) +end diff --git a/build.log b/build.log new file mode 100644 index 0000000..79abf27 --- /dev/null +++ b/build.log @@ -0,0 +1,8 @@ +[info] Namespace "nameless" was set as "concrete" +[info] Builder initialized in directory "C:\Julia\dev\HetaSimulator". +[info] Compilation of module "index.heta" of type "heta"... +[info] Reading module of type "heta" from file "C:\Julia\dev\HetaSimulator\index.heta"... +[error] ENOENT: no such file or directory, open 'C:\Julia\dev\HetaSimulator\index.heta' +[info] Setting references in elements, total length 77 +[info] Checking for circular references in Records. +[warn] Units checking and export were skipped because of errors in compilation. \ No newline at end of file diff --git a/cases/story_0/run.jl b/cases/story_0/run.jl index e34781c..a37b63f 100644 --- a/cases/story_0/run.jl +++ b/cases/story_0/run.jl @@ -1,7 +1,3 @@ -#= - Example from README.md file - use heta_update_dev() -=# using HetaSimulator, Plots diff --git a/cases/story_1/run.jl b/cases/story_1/run.jl index bf2d2d7..ec95b44 100644 --- a/cases/story_1/run.jl +++ b/cases/story_1/run.jl @@ -9,7 +9,6 @@ using HetaSimulator, Plots ################################## Model Upload ########################################### -# heta_update_dev("nan-math") platform = load_platform("$HetaSimulatorDir/cases/story_1", rm_out = false) #platform = load_jlplatform("$HetaSimulatorDir/cases/story_1/_julia/model.jl") diff --git a/cases/story_2/run.jl b/cases/story_2/run.jl index 2e58021..f9f27a5 100644 --- a/cases/story_2/run.jl +++ b/cases/story_2/run.jl @@ -4,7 +4,6 @@ using HetaSimulator, Plots ################################## Model Upload ########################################### -# heta_update_dev() platform = load_platform("$HetaSimulatorDir/cases/story_2", rm_out=false); # platform.models diff --git a/docs/src/index.md b/docs/src/index.md index dcf64d4..8a813fe 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -27,15 +27,10 @@ To install or update HetaSimulator run the code below in Julia environment: ```julia julia> ] -(@v1.9) pkg> add HetaSimulator +(@v1.10) pkg> add HetaSimulator ``` -Internally HetaSimulator uses Heta compiler. -Sometimes it is required to update the compiler's version. -```julia -# update heta compiler for v0.6.14 -julia> heta_update("0.6.14") -``` +Internally HetaSimulator installs Heta compiler as an artifact. ## Basic usage diff --git a/docs/src/tutorial/intro.md b/docs/src/tutorial/intro.md index 339053c..79e173c 100644 --- a/docs/src/tutorial/intro.md +++ b/docs/src/tutorial/intro.md @@ -34,15 +34,3 @@ They use the same standards of model notation and can be used in the same projec Furthermore currently `heta-compiler` JS code is used internally in HetaSimulator. When a user installs HetaSimulator in Julia the most appropriate version of __heta compiler__ is installed as well. - -If you need to reinstall `heta-compiler` it can be done with the following code. - -```julia -heta_update() -``` - -To install a specific version of `heta-compiler` you can use - -```julia -heta_update("0.6.14") # for heta-compiler v0.6.14 -``` diff --git a/docs/src/tutorial/sim-files/sim-run.jl b/docs/src/tutorial/sim-files/sim-run.jl index 349a4fc..b407736 100644 --- a/docs/src/tutorial/sim-files/sim-run.jl +++ b/docs/src/tutorial/sim-files/sim-run.jl @@ -1,5 +1,4 @@ using HetaSimulator, Plots, CSV -# heta_update() ### creating platform diff --git a/src/HetaSimulator.jl b/src/HetaSimulator.jl index b35d550..a2f9e26 100644 --- a/src/HetaSimulator.jl +++ b/src/HetaSimulator.jl @@ -1,13 +1,26 @@ module HetaSimulator - # heta-compiler supported version - const HETA_COMPILER_SUPPORTED = "0.8.4" - const SUPPORTED_VERSIONS = ["0.8.4"] - using Reexport # heta compiler support - using NodeJS + using Pkg.Artifacts + import Base: SHA1 + + # heta-compiler supported version + const HETA_COMPILER_VERSION = "0.8.6" + #const SUPPORTED_VERSIONS = ["0.8.4", "0.8.5", "0.8.6"] + + function heta_compiler_load() + artifact_info = artifact_meta("heta_app", joinpath(@__DIR__, "..", "Artifacts.toml")) + + artifact_info === nothing && return nothing # throw? + + return artifact_path(SHA1(artifact_info["git-tree-sha1"])) + end + + const heta_path = heta_compiler_load() + const heta_exe_name = Sys.iswindows() ? "heta-compiler.exe" : "heta-compiler" + const heta_exe_path = heta_path === nothing ? heta_exe_name : joinpath(heta_path, heta_exe_name) # diffeq-related pkgs using SciMLBase @@ -37,7 +50,7 @@ module HetaSimulator #plots using RecipesBase - const HetaSimulatorDir = dirname(Base.@__DIR__) + const HetaSimulatorDir = dirname(@__DIR__) include("types.jl") include("heta_cli/connect.jl") @@ -61,11 +74,10 @@ module HetaSimulator include("gsa.jl") include("save_as_heta.jl") include("heta_funcs.jl") - - heta_update() - export heta, heta_help, heta_init, heta_update, heta_build - export heta_update_dev, load_platform, load_jlplatform, load_jlmodel + + export heta, heta_version, heta_help, heta_init, heta_build + export load_platform, load_jlplatform, load_jlmodel export Platform, Model, Scenario export read_scenarios, add_scenarios! export read_measurements, add_measurements!, measurements_as_table diff --git a/src/heta_cli/connect.jl b/src/heta_cli/connect.jl index 7dcb3c9..ef2284e 100644 --- a/src/heta_cli/connect.jl +++ b/src/heta_cli/connect.jl @@ -2,17 +2,6 @@ const MODEL_DIR = "_julia" const MODEL_NAME = "model.jl" -""" - heta_update_dev(branch::String = "master") - -Installs heta-compiler from GitHub's repository . - -Arguments: - -- `branch` : branch to install, default is "master". -""" -heta_update_dev(branch::String = "master") = run(`$NPM_PATH i -g https://github.com/hetalang/heta-compiler.git\#$branch --prefix $NODE_DIR`) - """ load_platform( target_dir::AbstractString; diff --git a/src/heta_cli/heta.jl b/src/heta_cli/heta.jl index 44b7b9f..751a5d9 100644 --- a/src/heta_cli/heta.jl +++ b/src/heta_cli/heta.jl @@ -1,7 +1,3 @@ -# paths to npm.cmd and nodejs.exe -const NPM_PATH = npm_cmd() -const NODE_DIR = dirname(nodejs_cmd().exec[1]) -const HETA_PATH = Sys.iswindows() ? "$NODE_DIR/node_modules/heta-compiler" : "$NODE_DIR/lib/node_modules/heta-compiler" """ heta(;version::Bool=false, help::Bool=false) @@ -20,10 +16,21 @@ function heta(;version::Bool=false, help::Bool=false) version != false && push!(options_array, "--version") help != false && push!(options_array, "--help") - run_build = run(ignorestatus(`$NODE_DIR/node $HETA_PATH/bin/heta.js $options_array`)) + run_build = run(ignorestatus(`$heta_exe_path $options_array`)) return run_build.exitcode end +""" + heta_version() + +Display heta-compiler version + +""" +function heta_version() + run_build = run(ignorestatus(`$heta_exe_path -v`)) + return run_build.exitcode +end + """ heta_help(command::String) @@ -34,9 +41,8 @@ Arguments: - `command`: command to display """ - function heta_help(command::String) - run_build = run(ignorestatus(`$NODE_DIR/node $HETA_PATH/bin/heta.js help $command`)) + run_build = run(ignorestatus(`$heta_exe_path help $command`)) return run_build.exitcode end @@ -49,7 +55,7 @@ Argument: - `dir`: platform directory - `force`: if `true` then replace files and directories -- `silent`: if `true` create with default options without prompt +- `silent`: if `true` use default options without prompt """ function heta_init(dir::String; force::Bool=false, silent::Bool=false) @@ -57,23 +63,7 @@ function heta_init(dir::String; force::Bool=false, silent::Bool=false) force != false && push!(options_array, "--force") silent != false && push!(options_array, "--silent") - run_build = run(ignorestatus(`$NODE_DIR/node $HETA_PATH/bin/heta-init.js $options_array $dir`)) - return run_build.exitcode -end - -""" - heta_update(version::String = HETA_COMPILER_SUPPORTED) - -To install or update heta-compiler from NPM. - -Arguments: - -- `version` : `heta compiler` version. If the value is not provided, `heta_update` installs - the latest version of `heta compiler` compartible with HetaSimulator. -""" -function heta_update(version::String=HETA_COMPILER_SUPPORTED) - # XXX: Do we need to check if version in SUPPORTED_VERSIONS - run_build = run(`$NPM_PATH i -g heta-compiler@$version --prefix $NODE_DIR`) + run_build = run(ignorestatus(`$heta_exe_path init $options_array $dir`)) return run_build.exitcode end @@ -125,8 +115,6 @@ function heta_build( type::String = "heta" ) - !isdir(HETA_PATH) && throw("Heta compiler is not installed. Run `heta_update()` to install it.") - # convert to absolute path _target_dir = abspath(target_dir) @@ -150,16 +138,8 @@ function heta_build( type != "heta" && push!(options_array, "--type", type) push!(options_array, "--skip-updates") - # build the dist - #= - if Sys.iswindows() - heta_cmd = "heta.cmd" - else - heta_cmd = "heta" # not tested on unix - end - =# - run_build = run(ignorestatus(`$NODE_DIR/node $HETA_PATH/bin/heta-build.js $options_array $_target_dir`)) + run_build = run(ignorestatus(`$heta_exe_path build $options_array $_target_dir`)) return run_build.exitcode end diff --git a/src/import_platform.jl b/src/import_platform.jl index 1fde0b7..8177947 100644 --- a/src/import_platform.jl +++ b/src/import_platform.jl @@ -9,7 +9,8 @@ function Platform( version::String ) # TODO: semver approach might be better - @assert version in SUPPORTED_VERSIONS "Heta compiler of the version \"$version\" is not supported." + @assert version == HETA_COMPILER_VERSION "The model was build with Heta compiler v$version, which is not supported.\n"* + "This HetaSimulator release includes Heta compiler v$HETA_COMPILER_VERSION. Please re-compile the model with HetaSimulator load_platform()." print("Loading platform... ") model_pairs = [pair[1] => Model(pair[2]...) for pair in pairs(models)] diff --git a/test/heta_compiler_test.jl b/test/heta_compiler_test.jl new file mode 100644 index 0000000..9af8405 --- /dev/null +++ b/test/heta_compiler_test.jl @@ -0,0 +1,2 @@ + +@test chomp(read(`$(HetaSimulator.heta_exe_path) -v`, String)) == HetaSimulator.HETA_COMPILER_VERSION \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 88e9abc..f8fe8ed 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,6 +11,7 @@ function test_show(t) end @testset "HetaSimulator" begin + @testset "Heta compiler tests" begin include("heta_compiler_test.jl") end @testset "Single-compartment model without events" begin include("single_comp_test.jl") end @testset "Single-compartment model with events" begin include("single_comp_events_test.jl") end @testset "Functions used in heta models" begin include("heta_funcs_test.jl") end