Skip to content

Commit

Permalink
Updated vsl.plot setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Oct 9, 2023
1 parent e756a72 commit d8ead59
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
26 changes: 0 additions & 26 deletions plot/plot.v
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
module plot

import os

const (
schema_version = 'v1.0.2'
venv_dir_name = '.plotvenv_${schema_version}'
data_dir_name = '.data_${schema_version}'
)

// init will ensure that all dependencies are correctly installed and venv initiallized
fn init() {
venv_path := solve_mod_path(plot.venv_dir_name)
if !os.is_dir(venv_path) {
println('Creating plotly virtualenv...')
}
init_path := solve_mod_path('scripts', 'create-venv.sh')
result := os.execute('bash ${init_path} "${venv_path}"')
if result.exit_code != 0 {
panic(result.output)
}
println(result.output)
}

fn solve_mod_path(dirs ...string) string {
return os.join_path(@VMODROOT, ...dirs)
}

// Plot is the main structure that contains layout and traces
// to generate plots
pub struct Plot {
Expand Down
33 changes: 29 additions & 4 deletions plot/show.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,33 @@ import os
import time
import vsl.errors

const (
schema_version = 'v1.0.3'
venv_dir_name = '.plotvenv_${schema_version}'
data_dir_name = '.data_${schema_version}'
)

pub fn (p Plot) show() ! {
create_venv()!

ts := time.now().format_ss_micro()
plot_str := json.encode_pretty(p.traces)

venv_path := solve_mod_path(venv_dir_name)
venv_path := solve_mod_path(plot.venv_dir_name)
if !os.is_dir(venv_path) {
return errors.error('plotly virtualenv not found', .efailed)
}

data_dir_path := solve_mod_path(data_dir_name)
data_dir_path := solve_mod_path(plot.data_dir_name)
if !os.is_dir(data_dir_path) {
os.mkdir(data_dir_path) or {
return errors.error('could not create needed dir path at ${data_dir_path}.',
.efailed)
}
}

data_path := solve_mod_path(data_dir_name, 'data-${ts}.json')
layout_path := solve_mod_path(data_dir_name, 'layout-${ts}.json')
data_path := solve_mod_path(plot.data_dir_name, 'data-${ts}.json')
layout_path := solve_mod_path(plot.data_dir_name, 'layout-${ts}.json')
run_path := solve_mod_path('scripts', 'run.sh')

os.write_file(data_path, plot_str) or {
Expand All @@ -43,3 +51,20 @@ pub fn (p Plot) show() ! {
println(result.output)
}
}

// create_venv will ensure that all dependencies are correctly installed and venv initiallized
fn create_venv() ! {
venv_path := solve_mod_path(plot.venv_dir_name)
if !os.is_dir(venv_path) {
println('Creating plotly virtualenv...')
}
init_path := solve_mod_path('scripts', 'create-venv.sh')
result := os.execute('bash ${init_path} "${venv_path}"')
if result.exit_code != 0 {
return errors.error(result.output, .efailed)
}
}

fn solve_mod_path(dirs ...string) string {
return os.join_path(@VMODROOT, ...dirs)
}

0 comments on commit d8ead59

Please sign in to comment.