Skip to content

Commit

Permalink
Merge pull request #56 from hetalang/artifacts
Browse files Browse the repository at this point in the history
Artifacts
  • Loading branch information
ivborissov committed Aug 20, 2024
2 parents 8b71000 + 38204b2 commit e1fef1b
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 92 deletions.
25 changes: 25 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 1 addition & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -31,7 +31,6 @@ Distributions = "0.25"
LabelledArrays = "1.6.1"
NLopt = "0.6"
NaNMath = "1"
NodeJS = "2"
OrdinaryDiffEq = "6"
ProgressMeter = "1"
RecipesBase = "1"
Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions artifacts_scripts/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
ArtifactUtils = "8b73e784-e7d8-4ea5-973d-377fed4e3bce"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
21 changes: 21 additions & 0 deletions artifacts_scripts/build_artifacts.jl
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions build.log
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 0 additions & 4 deletions cases/story_0/run.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#=
Example from README.md file
use heta_update_dev()
=#

using HetaSimulator, Plots

Expand Down
1 change: 0 additions & 1 deletion cases/story_1/run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion cases/story_2/run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using HetaSimulator, Plots

################################## Model Upload ###########################################
# heta_update_dev()

platform = load_platform("$HetaSimulatorDir/cases/story_2", rm_out=false);
# platform.models
Expand Down
9 changes: 2 additions & 7 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 0 additions & 12 deletions docs/src/tutorial/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
1 change: 0 additions & 1 deletion docs/src/tutorial/sim-files/sim-run.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using HetaSimulator, Plots, CSV
# heta_update()

### creating platform

Expand Down
32 changes: 22 additions & 10 deletions src/HetaSimulator.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down
11 changes: 0 additions & 11 deletions src/heta_cli/connect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/hetalang/heta-compiler>.
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;
Expand Down
52 changes: 16 additions & 36 deletions src/heta_cli/heta.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -49,31 +55,15 @@ 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)
options_array = String[]
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

Expand Down Expand Up @@ -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)

Expand All @@ -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
3 changes: 2 additions & 1 deletion src/import_platform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 2 additions & 0 deletions test/heta_compiler_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

@test chomp(read(`$(HetaSimulator.heta_exe_path) -v`, String)) == HetaSimulator.HETA_COMPILER_VERSION
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e1fef1b

Please sign in to comment.