From 9642922445790b05daae722c15be7a301c12dce5 Mon Sep 17 00:00:00 2001 From: despiegk Date: Thu, 21 Aug 2025 12:05:20 +0200 Subject: [PATCH] ... --- .../openapi_e2e/generate_actor_module.vsh | 2 +- examples/core/generate.vsh | 4 +- examples/data/countries.vsh | 8 ++- .../develop/heroprompt/heroprompt_example.vsh | 12 ++-- examples/installers/net/mycelium.vsh | 2 +- examples/lang/python/codewalker.vsh | 3 +- examples/schemas/example/generate_model.vsh | 7 +- lib/core/httpconnection/caching.v | 6 +- lib/data/countries/factory.v | 56 ++++++++-------- lib/develop/codewalker/model.v | 10 +-- lib/develop/gittools/repository_model.v | 2 +- lib/installers/install_multi.v | 4 +- .../mycelium_installer_actions.v | 6 +- .../mycelium_installer_factory_.v | 4 -- .../daguserver/daguserver_actions.v | 28 ++++---- .../garage_s3/garage_s3_actions.v | 18 ++--- lib/lang/python/freeze.v | 2 +- lib/lang/python/python.v | 56 ++++++++-------- lib/lang/python/python_test.v | 66 +++++++++---------- lib/lang/python/shell.v | 10 +-- lib/lang/python/templates.v | 44 ++++++++----- lib/osal/startupmanager/startupmanager.v | 10 +-- .../grid4/datamodel/model_aggregated.v | 15 ++--- lib/threefold/grid4/datamodel/model_node.v | 57 ++++++++-------- .../grid4/datamodel/model_nodegroup.v | 33 +++++----- .../grid4/datamodel/model_simulations.v | 2 +- lib/threefold/grid4/datamodel/model_slices.v | 43 ++++++------ .../datamodelsimulator/model_aggregated.v | 15 ++--- lib/threefold/grid4/datamodelsimulator/play.v | 2 +- lib/web/heroprompt/server.v | 16 ++--- lib/web/ui/factory.v | 12 ++-- lib/web/ui/utils.v | 7 +- 32 files changed, 281 insertions(+), 281 deletions(-) diff --git a/examples/baobab/generator/openapi_e2e/generate_actor_module.vsh b/examples/baobab/generator/openapi_e2e/generate_actor_module.vsh index 50ac7785..47d25349 100755 --- a/examples/baobab/generator/openapi_e2e/generate_actor_module.vsh +++ b/examples/baobab/generator/openapi_e2e/generate_actor_module.vsh @@ -19,7 +19,7 @@ println(actor_spec) // )! actor_module := generator.generate_actor_module(actor_spec, - interfaces: [ .http] + interfaces: [.http] )! actor_module.write(example_dir, diff --git a/examples/core/generate.vsh b/examples/core/generate.vsh index e9703d00..a7014130 100755 --- a/examples/core/generate.vsh +++ b/examples/core/generate.vsh @@ -9,9 +9,9 @@ import freeflowuniverse.herolib.core.pathlib // } mut args2 := generator.GeneratorArgs{ - path: '~/code/github/freeflowuniverse/herolib/lib/develop/heroprompt' + path: '~/code/github/freeflowuniverse/herolib/lib/develop/heroprompt' force: true -} +} generator.scan(args2)! // mut args := generator.GeneratorArgs{ diff --git a/examples/data/countries.vsh b/examples/data/countries.vsh index 4566462c..b8e9c9a5 100755 --- a/examples/data/countries.vsh +++ b/examples/data/countries.vsh @@ -12,7 +12,9 @@ println('Total countries loaded: ${all_countries.len}') // --- Example: Print the first few countries --- println('\n--- First 5 Countries ---') for i, country in all_countries { - if i >= 5 { break } + if i >= 5 { + break + } println(country.str()) } @@ -44,7 +46,7 @@ println('Found ${eu_countries.len} European countries.') // --- Example: Using the helper function --- println('\n--- Using helper function to find Japan ---') japan := countries.find_country_by_iso('JP') or { - println('Error finding Japan: ${err}') - return + println('Error finding Japan: ${err}') + return } println('Found Japan: ${japan.str()}') diff --git a/examples/develop/heroprompt/heroprompt_example.vsh b/examples/develop/heroprompt/heroprompt_example.vsh index e41842e7..37072186 100755 --- a/examples/develop/heroprompt/heroprompt_example.vsh +++ b/examples/develop/heroprompt/heroprompt_example.vsh @@ -9,8 +9,8 @@ import os // )! mut workspace := heroprompt.get( - name: 'example_ws' - path: '${os.home_dir()}/code/github/freeflowuniverse/herolib' + name: 'example_ws' + path: '${os.home_dir()}/code/github/freeflowuniverse/herolib' create: true )! @@ -19,7 +19,9 @@ println('selected (initial): ${workspace.selected_children()}') // Add a directory and a file workspace.add_dir(path: '${os.home_dir()}/code/github/freeflowuniverse/herolib/docker')! -workspace.add_file(path: '${os.home_dir()}/code/github/freeflowuniverse/herolib/docker/docker_ubuntu_install.sh')! +workspace.add_file( + path: '${os.home_dir()}/code/github/freeflowuniverse/herolib/docker/docker_ubuntu_install.sh' +)! println('selected (after add): ${workspace.selected_children()}') // Build a prompt from current selection (should be empty now) @@ -39,7 +41,9 @@ println('selected (after remove): ${workspace.selected_children()}') // List workspaces (names only) mut all := heroprompt.list_workspaces() or { []&heroprompt.Workspace{} } mut names := []string{} -for w in all { names << w.name } +for w in all { + names << w.name +} println('workspaces: ${names}') // Optionally delete the example workspace diff --git a/examples/installers/net/mycelium.vsh b/examples/installers/net/mycelium.vsh index e2101c32..97da5f20 100755 --- a/examples/installers/net/mycelium.vsh +++ b/examples/installers/net/mycelium.vsh @@ -8,7 +8,7 @@ println(installer) installer.start()! -$dbg; +// $dbg; mut r := mycelium.inspect()! println(r) diff --git a/examples/lang/python/codewalker.vsh b/examples/lang/python/codewalker.vsh index 3449e853..e0dd3758 100755 --- a/examples/lang/python/codewalker.vsh +++ b/examples/lang/python/codewalker.vsh @@ -1,5 +1,6 @@ #!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run -import freeflowuniverse.herolib.lib.lang.codewalker + +import freeflowuniverse.herolib.lib.lang.codewalker import freeflowuniverse.herolib.core.pathlib import freeflowuniverse.herolib.osal.core as osal diff --git a/examples/schemas/example/generate_model.vsh b/examples/schemas/example/generate_model.vsh index c2aac606..dac356f0 100755 --- a/examples/schemas/example/generate_model.vsh +++ b/examples/schemas/example/generate_model.vsh @@ -1,10 +1,10 @@ #!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run import os -import freeflowuniverse.herolib.core.code { Alias, Struct } +import freeflowuniverse.herolib.core.code { Alias } import freeflowuniverse.herolib.core.pathlib import freeflowuniverse.herolib.schemas.openrpc -import freeflowuniverse.herolib.schemas.openrpc.codegen {generate_model} +import freeflowuniverse.herolib.schemas.openrpc.codegen { generate_model } const doc_path = '${os.dir(@FILE)}/testdata/openrpc.json' @@ -18,8 +18,7 @@ assert model[0] is Alias pet_id := model[0] as Alias assert pet_id.name == 'PetId' println(pet_id) -$dbg; - +// $dbg; // assert pet_id.typ.symbol == 'int' diff --git a/lib/core/httpconnection/caching.v b/lib/core/httpconnection/caching.v index 62fd4936..baadc0f1 100644 --- a/lib/core/httpconnection/caching.v +++ b/lib/core/httpconnection/caching.v @@ -5,10 +5,8 @@ import json import net.http { Method } // https://cassiomolin.com/2016/09/09/which-http-status-codes-are-cacheable/ -const ( - default_cacheable_codes = [200, 203, 204, 206, 300, 404, 405, 410, 414, 501] - unsafe_http_methods = [Method.put, .patch, .post, .delete] -) +const default_cacheable_codes = [200, 203, 204, 206, 300, 404, 405, 410, 414, 501] +const unsafe_http_methods = [Method.put, .patch, .post, .delete] pub struct CacheConfig { pub mut: diff --git a/lib/data/countries/factory.v b/lib/data/countries/factory.v index c1f48273..7466f5f4 100644 --- a/lib/data/countries/factory.v +++ b/lib/data/countries/factory.v @@ -1,10 +1,8 @@ module countries - // --- Embed the data file content at compile time --- // The path is relative to the location of this `factory.v` file. - // get_all_countries parses the country data embedded in the executable. // It returns a list of Country structs. pub fn get_all_countries() ![]Country { @@ -26,7 +24,8 @@ pub fn get_all_countries() ![]Country { // --- Identify and skip the header --- // Check if this line looks like the header (contains key identifiers) - if !found_header && trimmed_line.contains('ISO') && trimmed_line.contains('Country') && trimmed_line.contains('CurrencyCode') { + if !found_header && trimmed_line.contains('ISO') && trimmed_line.contains('Country') + && trimmed_line.contains('CurrencyCode') { found_header = true continue // Skip the header line itself } @@ -37,29 +36,28 @@ pub fn get_all_countries() ![]Country { // Use strings.split to split the line by tab character fields := line.split_by_space() - // --- Create Country struct instance --- // Map fields by index based on the header structure. // Handle potential out-of-bounds or missing data gracefully using `or {}`. // The last field might sometimes be empty or missing in the data, handle it - iso_field := fields[0] or { '' } - iso3_field := fields[1] or { '' } - iso_numeric_field := fields[2] or { '' } - fips_field := fields[3] or { '' } - country_name_field := fields[4] or { '' } - capital_field := fields[5] or { '' } - area_sqkm_field := fields[6] or { '' } - population_field := fields[7] or { '' } - continent_field := fields[8] or { '' } - tld_field := fields[9] or { '' } - currency_code_field := fields[10] or { '' } - currency_name_field := fields[11] or { '' } - phone_field := fields[12] or { '' } - postal_format_field := fields[13] or { '' } - postal_regex_field := fields[14] or { '' } - languages_field := fields[15] or { '' } - geonameid_field := fields[16] or { '' } - neighbours_field := fields[17] or { '' } + iso_field := fields[0] or { '' } + iso3_field := fields[1] or { '' } + iso_numeric_field := fields[2] or { '' } + fips_field := fields[3] or { '' } + country_name_field := fields[4] or { '' } + capital_field := fields[5] or { '' } + area_sqkm_field := fields[6] or { '' } + population_field := fields[7] or { '' } + continent_field := fields[8] or { '' } + tld_field := fields[9] or { '' } + currency_code_field := fields[10] or { '' } + currency_name_field := fields[11] or { '' } + phone_field := fields[12] or { '' } + postal_format_field := fields[13] or { '' } + postal_regex_field := fields[14] or { '' } + languages_field := fields[15] or { '' } + geonameid_field := fields[16] or { '' } + neighbours_field := fields[17] or { '' } equiv_fips_code_field := fields[18] or { '' } country := Country{ @@ -93,11 +91,11 @@ pub fn get_all_countries() ![]Country { // Optional: Helper function to find a country by ISO code pub fn find_country_by_iso(iso_code string) !Country { - countries := get_all_countries()! - for country in countries { - if country.iso == iso_code { - return country - } - } - return error('Country with ISO code "${iso_code}" not found') + countries := get_all_countries()! + for country in countries { + if country.iso == iso_code { + return country + } + } + return error('Country with ISO code "${iso_code}" not found') } diff --git a/lib/develop/codewalker/model.v b/lib/develop/codewalker/model.v index 057602af..7baf07a9 100644 --- a/lib/develop/codewalker/model.v +++ b/lib/develop/codewalker/model.v @@ -2,15 +2,15 @@ module codewalker pub struct CWError { pub: - message string - linenr int + message string + linenr int category string } pub struct FMError { pub: - message string - linenr int //is optional + message string + linenr int // is optional category string filename string -} \ No newline at end of file +} diff --git a/lib/develop/gittools/repository_model.v b/lib/develop/gittools/repository_model.v index b42eb84f..0c97e875 100644 --- a/lib/develop/gittools/repository_model.v +++ b/lib/develop/gittools/repository_model.v @@ -37,5 +37,5 @@ pub mut: pub struct GitRepoConfig { pub mut: - remote_check_period int = 3600*24*7 // seconds = 7d + remote_check_period int = 3600 * 24 * 7 // seconds = 7d } diff --git a/lib/installers/install_multi.v b/lib/installers/install_multi.v index 5d1ae3de..106c534a 100644 --- a/lib/installers/install_multi.v +++ b/lib/installers/install_multi.v @@ -113,8 +113,8 @@ pub fn install_multi(args_ InstallArgs) ! { // herolib.hero_install(reset: args.reset)! // } // 'caddy' { - // caddy.install(reset: args.reset)! - // caddy.configure_examples()! + // caddy.install(reset: args.reset)! + // caddy.configure_examples()! // } // 'chrome' { // chrome.install(reset: args.reset, uninstall: args.uninstall)! diff --git a/lib/installers/net/mycelium_installer/mycelium_installer_actions.v b/lib/installers/net/mycelium_installer/mycelium_installer_actions.v index dbfadd7e..c24c1fde 100644 --- a/lib/installers/net/mycelium_installer/mycelium_installer_actions.v +++ b/lib/installers/net/mycelium_installer/mycelium_installer_actions.v @@ -19,15 +19,15 @@ fn startupcmd() ![]startupmanager.ZProcessNewArgs { mut peers_str := installer.peers.join(' ') mut tun_name := 'tun${installer.tun_nr}' - mut cmd:='mycelium --key-file ${osal.hero_path()!}/cfg/priv_key.bin --peers ${peers_str} --tun-name ${tun_name}' + mut cmd := 'mycelium --key-file ${osal.hero_path()!}/cfg/priv_key.bin --peers ${peers_str} --tun-name ${tun_name}' if core.is_osx()! { - cmd = "sudo ${cmd}" + cmd = 'sudo ${cmd}' } res << startupmanager.ZProcessNewArgs{ name: 'mycelium' startuptype: .zinit - cmd: cmd + cmd: cmd env: { 'HOME': os.home_dir() } diff --git a/lib/installers/net/mycelium_installer/mycelium_installer_factory_.v b/lib/installers/net/mycelium_installer/mycelium_installer_factory_.v index e6d09fa0..daa9a475 100644 --- a/lib/installers/net/mycelium_installer/mycelium_installer_factory_.v +++ b/lib/installers/net/mycelium_installer/mycelium_installer_factory_.v @@ -218,10 +218,7 @@ pub fn (mut self MyceliumInstaller) start() ! { start_pre()! - - for zprocess in startupcmd()! { - mut sm := startupmanager_get(zprocess.startuptype)! console.print_debug('starting mycelium_installer with ${zprocess.startuptype}...') @@ -229,7 +226,6 @@ pub fn (mut self MyceliumInstaller) start() ! { sm.new(zprocess)! sm.start(zprocess.name)! - } start_post()! diff --git a/lib/installers/sysadmintools/daguserver/daguserver_actions.v b/lib/installers/sysadmintools/daguserver/daguserver_actions.v index 5bc9c62d..0e6daf29 100644 --- a/lib/installers/sysadmintools/daguserver/daguserver_actions.v +++ b/lib/installers/sysadmintools/daguserver/daguserver_actions.v @@ -139,19 +139,19 @@ fn destroy() ! { osal.execute_silent(cmd) or {} mut zinit_factory := zinit_lib.Zinit{} - if zinit_factory.exists('dagu') { - zinit_factory.stop('dagu')! or { return error('Could not stop dagu service due to: ${err}') } - zinit_factory.delete('dagu')! or { - return error('Could not delete dagu service due to: ${err}') - } - } + // if zinit_factory.exists('dagu') { + // zinit_factory.stop('dagu')! or { return error('Could not stop dagu service due to: ${err}') } + // zinit_factory.delete('dagu')! or { + // return error('Could not delete dagu service due to: ${err}') + // } + // } - if zinit_factory.exists('dagu_scheduler') { - zinit_factory.stop('dagu_scheduler')! or { - return error('Could not stop dagu_scheduler service due to: ${err}') - } - zinit_factory.delete('dagu_scheduler')! or { - return error('Could not delete dagu_scheduler service due to: ${err}') - } - } + // if zinit_factory.exists('dagu_scheduler') { + // zinit_factory.stop('dagu_scheduler')! or { + // return error('Could not stop dagu_scheduler service due to: ${err}') + // } + // zinit_factory.delete('dagu_scheduler')! or { + // return error('Could not delete dagu_scheduler service due to: ${err}') + // } + // } } diff --git a/lib/installers/sysadmintools/garage_s3/garage_s3_actions.v b/lib/installers/sysadmintools/garage_s3/garage_s3_actions.v index bc3e638f..88a618ff 100644 --- a/lib/installers/sysadmintools/garage_s3/garage_s3_actions.v +++ b/lib/installers/sysadmintools/garage_s3/garage_s3_actions.v @@ -154,16 +154,16 @@ fn destroy() ! { return error('failed to uninstall garage_s3: ${res.output}') } - mut zinit_factory := zinit_lib.Zinit{} + // mut zinit_factory := zinit_lib.Zinit{} - if zinit_factory.exists('garage_s3') { - zinit_factory.stop('garage_s3')! or { - return error('Could not stop garage_s3 service due to: ${err}') - } - zinit_factory.delete('garage_s3')! or { - return error('Could not delete garage_s3 service due to: ${err}') - } - } + // if zinit_factory.exists('garage_s3'){ + // zinit_factory.stop('garage_s3') or { + // return error('Could not stop garage_s3 service due to: ${err}') + // } + // zinit_factory.delete('garage_s3') or { + // return error('Could not delete garage_s3 service due to: ${err}') + // } + // } console.print_header('garage_s3 is uninstalled') } diff --git a/lib/lang/python/freeze.v b/lib/lang/python/freeze.v index 04ea5243..ace6b977 100644 --- a/lib/lang/python/freeze.v +++ b/lib/lang/python/freeze.v @@ -65,4 +65,4 @@ pub fn (py PythonEnv) restore_from_lock() ! { ' osal.exec(cmd: cmd)! console.print_debug('Successfully restored from lock file') -} \ No newline at end of file +} diff --git a/lib/lang/python/python.v b/lib/lang/python/python.v index 5ae774cb..dff129a7 100644 --- a/lib/lang/python/python.v +++ b/lib/lang/python/python.v @@ -15,12 +15,12 @@ pub mut: @[params] pub struct PythonEnvArgs { pub mut: - name string = 'default' - reset bool - python_version string = '3.11' - dependencies []string + name string = 'default' + reset bool + python_version string = '3.11' + dependencies []string dev_dependencies []string - description string = 'A Python project managed by Herolib' + description string = 'A Python project managed by Herolib' } pub fn new(args_ PythonEnvArgs) !PythonEnv { @@ -47,14 +47,14 @@ pub fn new(args_ PythonEnvArgs) !PythonEnv { // Check if the Python environment exists and is properly configured pub fn (py PythonEnv) exists() bool { - return os.exists('${py.path.path}/.venv/bin/activate') && - os.exists('${py.path.path}/pyproject.toml') + return os.exists('${py.path.path}/.venv/bin/activate') + && os.exists('${py.path.path}/pyproject.toml') } // Initialize the Python environment using uv pub fn (mut py PythonEnv) init_env(args PythonEnvArgs) ! { console.print_green('Initializing Python environment at: ${py.path.path}') - + // Remove existing environment if reset is requested if args.reset && py.path.exists() { console.print_debug('Removing existing environment for reset') @@ -69,13 +69,13 @@ pub fn (mut py PythonEnv) init_env(args PythonEnvArgs) ! { // Generate project files from templates template_args := TemplateArgs{ - name: py.name - python_version: args.python_version - dependencies: args.dependencies + name: py.name + python_version: args.python_version + dependencies: args.dependencies dev_dependencies: args.dev_dependencies - description: args.description + description: args.description } - + py.generate_all_templates(template_args)! // Initialize uv project @@ -84,12 +84,12 @@ pub fn (mut py PythonEnv) init_env(args PythonEnvArgs) ! { uv venv --python ${args.python_version} ' osal.exec(cmd: cmd)! - + // Sync dependencies if any are specified if args.dependencies.len > 0 || args.dev_dependencies.len > 0 { py.sync()! } - + console.print_debug('Python environment initialization complete') } @@ -109,20 +109,20 @@ pub fn (py PythonEnv) add_dependencies(packages []string, dev bool) ! { if packages.len == 0 { return } - - console.print_debug('Adding Python packages: ${packages.join(", ")}') + + console.print_debug('Adding Python packages: ${packages.join(', ')}') packages_str := packages.join(' ') - + mut cmd := ' cd ${py.path.path} uv add ${packages_str}' - + if dev { cmd += ' --dev' } - + osal.exec(cmd: cmd)! - console.print_debug('Successfully added packages: ${packages.join(", ")}') + console.print_debug('Successfully added packages: ${packages.join(', ')}') } // Remove dependencies from the project @@ -130,20 +130,20 @@ pub fn (py PythonEnv) remove_dependencies(packages []string, dev bool) ! { if packages.len == 0 { return } - - console.print_debug('Removing Python packages: ${packages.join(", ")}') + + console.print_debug('Removing Python packages: ${packages.join(', ')}') packages_str := packages.join(' ') - + mut cmd := ' cd ${py.path.path} uv remove ${packages_str}' - + if dev { cmd += ' --dev' } - + osal.exec(cmd: cmd)! - console.print_debug('Successfully removed packages: ${packages.join(", ")}') + console.print_debug('Successfully removed packages: ${packages.join(', ')}') } // Legacy pip method for backward compatibility - now uses uv add @@ -189,4 +189,4 @@ pub fn (py PythonEnv) run(command string) !osal.Job { ${command} ' return osal.exec(cmd: cmd)! -} \ No newline at end of file +} diff --git a/lib/lang/python/python_test.v b/lib/lang/python/python_test.v index 7b15717c..4f1e41d4 100644 --- a/lib/lang/python/python_test.v +++ b/lib/lang/python/python_test.v @@ -4,13 +4,13 @@ import freeflowuniverse.herolib.ui.console fn test_python_env_creation() { console.print_debug('Testing Python environment creation') - + // Test basic environment creation - py := new(name: 'test_env') or { + py := new(name: 'test_env') or { console.print_stderr('Failed to create Python environment: ${err}') - panic(err) + panic(err) } - + assert py.name == 'test_env' assert py.path.path.contains('test_env') console.print_debug('✅ Environment creation test passed') @@ -18,97 +18,97 @@ fn test_python_env_creation() { fn test_python_env_with_dependencies() { console.print_debug('Testing Python environment with dependencies') - + // Test environment with initial dependencies py := new( - name: 'test_deps' - dependencies: ['requests', 'click'] + name: 'test_deps' + dependencies: ['requests', 'click'] dev_dependencies: ['pytest', 'black'] - reset: true - ) or { + reset: true + ) or { console.print_stderr('Failed to create Python environment with dependencies: ${err}') - panic(err) + panic(err) } - + assert py.exists() console.print_debug('✅ Environment with dependencies test passed') } fn test_python_package_management() { console.print_debug('Testing package management') - - py := new(name: 'test_packages', reset: true) or { + + py := new(name: 'test_packages', reset: true) or { console.print_stderr('Failed to create Python environment: ${err}') - panic(err) + panic(err) } - + // Test adding packages py.add_dependencies(['ipython'], false) or { console.print_stderr('Failed to add dependencies: ${err}') panic(err) } - + // Test legacy pip method py.pip('requests') or { console.print_stderr('Failed to install via pip method: ${err}') panic(err) } - + console.print_debug('✅ Package management test passed') } fn test_python_freeze_functionality() { console.print_debug('Testing freeze functionality') - + py := new( - name: 'test_freeze' + name: 'test_freeze' dependencies: ['click'] - reset: true - ) or { + reset: true + ) or { console.print_stderr('Failed to create Python environment: ${err}') - panic(err) + panic(err) } - + // Test freeze requirements := py.freeze() or { console.print_stderr('Failed to freeze requirements: ${err}') panic(err) } - + assert requirements.len > 0 console.print_debug('✅ Freeze functionality test passed') } fn test_python_template_generation() { console.print_debug('Testing template generation') - - py := new(name: 'test_templates', reset: true) or { + + py := new(name: 'test_templates', reset: true) or { console.print_stderr('Failed to create Python environment: ${err}') - panic(err) + panic(err) } - + // Check that pyproject.toml was generated pyproject_exists := py.path.file_exists('pyproject.toml') assert pyproject_exists - + // Check that shell scripts were generated env_script_exists := py.path.file_exists('env.sh') install_script_exists := py.path.file_exists('install.sh') assert env_script_exists assert install_script_exists - + console.print_debug('✅ Template generation test passed') } // Main test function that runs all tests fn test_python() { console.print_header('Running Python module tests') - + test_python_env_creation() test_python_env_with_dependencies() test_python_package_management() test_python_freeze_functionality() test_python_template_generation() - + console.print_green('🎉 All Python module tests passed!') -} \ No newline at end of file +} diff --git a/lib/lang/python/shell.v b/lib/lang/python/shell.v index 25851eb3..d2605d9f 100644 --- a/lib/lang/python/shell.v +++ b/lib/lang/python/shell.v @@ -28,16 +28,16 @@ pub fn (py PythonEnv) python_shell() ! { // Open IPython if available, fallback to regular Python pub fn (py PythonEnv) ipython_shell() ! { console.print_green('Opening IPython shell for environment: ${py.name}') - + // Check if IPython is available check_cmd := ' cd ${py.path.path} source .venv/bin/activate python -c "import IPython" ' - + check_result := osal.exec(cmd: check_cmd, raise_error: false)! - + mut shell_cmd := '' if check_result.exit_code == 0 { shell_cmd = ' @@ -53,7 +53,7 @@ pub fn (py PythonEnv) ipython_shell() ! { python ' } - + osal.execute_interactive(shell_cmd)! } @@ -76,4 +76,4 @@ pub fn (py PythonEnv) uv_run(command string) !osal.Job { uv ${command} ' return osal.exec(cmd: cmd)! -} \ No newline at end of file +} diff --git a/lib/lang/python/templates.v b/lib/lang/python/templates.v index 58cf9c75..0e121250 100644 --- a/lib/lang/python/templates.v +++ b/lib/lang/python/templates.v @@ -7,41 +7,41 @@ import os @[params] pub struct TemplateArgs { pub mut: - name string = 'herolib-python-project' - version string = '0.1.0' - description string = 'A Python project managed by Herolib' - python_version string = '3.11' - dependencies []string + name string = 'herolib-python-project' + version string = '0.1.0' + description string = 'A Python project managed by Herolib' + python_version string = '3.11' + dependencies []string dev_dependencies []string - scripts map[string]string + scripts map[string]string } // generate_pyproject_toml creates a pyproject.toml file from template pub fn (mut py PythonEnv) generate_pyproject_toml(args TemplateArgs) ! { template_path := '${@VMODROOT}/lang/python/templates/pyproject.toml' mut template_content := os.read_file(template_path)! - + // Format dependencies mut deps := []string{} for dep in args.dependencies { deps << ' "${dep}",' } dependencies_str := deps.join('\n') - + // Format dev dependencies mut dev_deps := []string{} for dep in args.dev_dependencies { dev_deps << ' "${dep}",' } dev_dependencies_str := dev_deps.join('\n') - + // Format scripts mut scripts := []string{} for name, command in args.scripts { scripts << '${name} = "${command}"' } scripts_str := scripts.join('\n') - + // Replace template variables content := template_content .replace('@{name}', args.name) @@ -51,7 +51,7 @@ pub fn (mut py PythonEnv) generate_pyproject_toml(args TemplateArgs) ! { .replace('@{dependencies}', dependencies_str) .replace('@{dev_dependencies}', dev_dependencies_str) .replace('@{scripts}', scripts_str) - + // Write to project directory mut pyproject_file := py.path.file_get_new('pyproject.toml')! pyproject_file.write(content)! @@ -61,10 +61,10 @@ pub fn (mut py PythonEnv) generate_pyproject_toml(args TemplateArgs) ! { pub fn (mut py PythonEnv) generate_env_script(args TemplateArgs) ! { template_path := '${@VMODROOT}/lang/python/templates/env.sh' mut template_content := os.read_file(template_path)! - + content := template_content .replace('@{python_version}', args.python_version) - + mut env_file := py.path.file_get_new('env.sh')! env_file.write(content)! os.chmod(env_file.path, 0o755)! @@ -74,11 +74,11 @@ pub fn (mut py PythonEnv) generate_env_script(args TemplateArgs) ! { pub fn (mut py PythonEnv) generate_install_script(args TemplateArgs) ! { template_path := '${@VMODROOT}/lang/python/templates/install.sh' mut template_content := os.read_file(template_path)! - + content := template_content .replace('@{name}', args.name) .replace('@{python_version}', args.python_version) - + mut install_file := py.path.file_get_new('install.sh')! install_file.write(content)! os.chmod(install_file.path, 0o755)! @@ -123,10 +123,18 @@ source env.sh ## Dependencies ### Production -${if args.dependencies.len > 0 { '- ' + args.dependencies.join('\n- ') } else { 'None' }} +${if args.dependencies.len > 0 { + '- ' + args.dependencies.join('\n- ') + } else { + 'None' + }} ### Development -${if args.dev_dependencies.len > 0 { '- ' + args.dev_dependencies.join('\n- ') } else { 'None' }} +${if args.dev_dependencies.len > 0 { + '- ' + args.dev_dependencies.join('\n- ') + } else { + 'None' + }} ' mut readme_file := py.path.file_get_new('README.md')! @@ -139,4 +147,4 @@ pub fn (mut py PythonEnv) generate_all_templates(args TemplateArgs) ! { py.generate_env_script(args)! py.generate_install_script(args)! py.generate_readme(args)! -} \ No newline at end of file +} diff --git a/lib/osal/startupmanager/startupmanager.v b/lib/osal/startupmanager/startupmanager.v index 4e8c59e6..7e5899a5 100644 --- a/lib/osal/startupmanager/startupmanager.v +++ b/lib/osal/startupmanager/startupmanager.v @@ -76,11 +76,11 @@ pub fn (mut sm StartupManager) new(args ZProcessNewArgs) ! { // Map ZProcessNewArgs to zinit.ServiceConfig mut service_config := zinit.ServiceConfig{ - exec: args.cmd - test: args.cmd_test // Direct mapping - oneshot: args.oneshot // Use the oneshot flag directly - after: args.after // Direct mapping - log: "ring" + exec: args.cmd + test: args.cmd_test // Direct mapping + oneshot: args.oneshot // Use the oneshot flag directly + after: args.after // Direct mapping + log: 'ring' env: args.env // Direct mapping dir: args.workdir // Direct mapping shutdown_timeout: 0 // Default, or add to ZProcessNewArgs if needed diff --git a/lib/threefold/grid4/datamodel/model_aggregated.v b/lib/threefold/grid4/datamodel/model_aggregated.v index d76b4270..9bacc3bd 100644 --- a/lib/threefold/grid4/datamodel/model_aggregated.v +++ b/lib/threefold/grid4/datamodel/model_aggregated.v @@ -2,7 +2,6 @@ module datamodel import time - // NodeTotalSim represents the aggregated data for a node simulation, including hardware specs, pricing, and location. pub struct NodeTotalSim { pub mut: @@ -23,14 +22,14 @@ pub fn (n NodeSim) total() !NodeTotalSim { } mut total := NodeTotalSim{ - id: n.id - cost: n.cost - deliverytime: time.now() // Placeholder; replace with actual logic if needed - inca_reward: 0 // Placeholder; compute from policy if available - reputation: 50 // Default; compute from uptime/history - uptime: n.uptime + id: n.id + cost: n.cost + deliverytime: time.now() // Placeholder; replace with actual logic if needed + inca_reward: 0 // Placeholder; compute from policy if available + reputation: 50 // Default; compute from uptime/history + uptime: n.uptime price_simulation: 0.0 - capacity: NodeCapacity{} + capacity: NodeCapacity{} } // Aggregate from compute slices diff --git a/lib/threefold/grid4/datamodel/model_node.v b/lib/threefold/grid4/datamodel/model_node.v index 40c6dd79..41ec9cdd 100644 --- a/lib/threefold/grid4/datamodel/model_node.v +++ b/lib/threefold/grid4/datamodel/model_node.v @@ -3,46 +3,46 @@ module datamodel @[heap] pub struct Node { pub mut: - id int - nodegroupid int - uptime int // 0..100 - computeslices []ComputeSlice - storageslices []StorageSlice - devices DeviceInfo - country string // 2 letter code as specified in lib/data/countries/data/countryInfo.txt, use that library for validation - capacity NodeCapacity // Hardware capacity details - provisiontime u32 //lets keep it simple and compatible + id int + nodegroupid int + uptime int // 0..100 + computeslices []ComputeSlice + storageslices []StorageSlice + devices DeviceInfo + country string // 2 letter code as specified in lib/data/countries/data/countryInfo.txt, use that library for validation + capacity NodeCapacity // Hardware capacity details + provisiontime u32 // lets keep it simple and compatible } - pub struct DeviceInfo { pub mut: - vendor string - storage []StorageDevice - memory []MemoryDevice + vendor string + storage []StorageDevice + memory []MemoryDevice cpu []CPUDevice gpu []GPUDevice network []NetworkDevice } + pub struct StorageDevice { pub mut: - id string //can be used in node - size_gb f64 // Size of the storage device in gigabytes + id string // can be used in node + size_gb f64 // Size of the storage device in gigabytes description string // Description of the storage device } pub struct MemoryDevice { pub mut: - id string //can be used in node - size_gb f64 // Size of the memory device in gigabytes + id string // can be used in node + size_gb f64 // Size of the memory device in gigabytes description string // Description of the memory device } pub struct CPUDevice { pub mut: - id string //can be used in node - cores int // Number of CPU cores - passmark int + id string // can be used in node + cores int // Number of CPU cores + passmark int description string // Description of the CPU cpu_brand string // Brand of the CPU cpu_version string // Version of the CPU @@ -50,19 +50,18 @@ pub mut: pub struct GPUDevice { pub mut: - id string //can be used in node - cores int // Number of GPU cores - memory_gb f64 // Size of the GPU memory in gigabytes + id string // can be used in node + cores int // Number of GPU cores + memory_gb f64 // Size of the GPU memory in gigabytes description string // Description of the GPU - gpu_brand string - gpu_version string - + gpu_brand string + gpu_version string } pub struct NetworkDevice { pub mut: - id string //can be used in node - speed_mbps int // Network speed in Mbps + id string // can be used in node + speed_mbps int // Network speed in Mbps description string // Description of the network device } @@ -84,5 +83,5 @@ pub mut: } fn (mut n Node) check() ! { - //todo + // todo } diff --git a/lib/threefold/grid4/datamodel/model_nodegroup.v b/lib/threefold/grid4/datamodel/model_nodegroup.v index 69130be8..57346f4b 100644 --- a/lib/threefold/grid4/datamodel/model_nodegroup.v +++ b/lib/threefold/grid4/datamodel/model_nodegroup.v @@ -1,31 +1,30 @@ module datamodel - +// is a root object, is the only obj farmer needs to configure in the UI, this defines how slices will be created @[heap] -//is a root object, is the only obj farmer needs to configure in the UI, this defines how slices will be created pub struct NodeGroup { pub mut: - id u32 - farmerid u32 //link back to farmer who owns the nodegroup, is a user? - secret string //only visible by farmer, in future encrypted, used to boot a node - description string - slapolicy SLAPolicy - pricingpolicy PricingPolicy - compute_slice_normalized_pricing_cc f64 //pricing in CC - cloud credit, per 2GB node slice - storage_slice_normalized_pricing_cc f64 //pricing in CC - cloud credit, per 1GB storage slice - reputation int = 50 //between 0 and 100, earned over time - uptime int //between 0 and 100, set by system, farmer has no ability to set this + id u32 + farmerid u32 // link back to farmer who owns the nodegroup, is a user? + secret string // only visible by farmer, in future encrypted, used to boot a node + description string + slapolicy SLAPolicy + pricingpolicy PricingPolicy + compute_slice_normalized_pricing_cc f64 // pricing in CC - cloud credit, per 2GB node slice + storage_slice_normalized_pricing_cc f64 // pricing in CC - cloud credit, per 1GB storage slice + reputation int = 50 // between 0 and 100, earned over time + uptime int // between 0 and 100, set by system, farmer has no ability to set this } pub struct SLAPolicy { pub mut: - sla_uptime int //should +90 - sla_bandwidth_mbit int //minimal mbits we can expect avg over 1h per node, 0 means we don't guarantee - sla_penalty int //0-100, percent of money given back in relation to month if sla breached, e.g. 200 means we return 2 months worth of rev if sla missed + sla_uptime int // should +90 + sla_bandwidth_mbit int // minimal mbits we can expect avg over 1h per node, 0 means we don't guarantee + sla_penalty int // 0-100, percent of money given back in relation to month if sla breached, e.g. 200 means we return 2 months worth of rev if sla missed } pub struct PricingPolicy { pub mut: - marketplace_year_discounts []int = [30,40,50] //e.g. 30,40,50 means if user has more CC in wallet than 1 year utilization on all his purchaes then this provider gives 30%, 2Y 40%, ... - volume_discounts []int = [10,20,30] //e.g. 10,20,30 + marketplace_year_discounts []int = [30, 40, 50] // e.g. 30,40,50 means if user has more CC in wallet than 1 year utilization on all his purchaes then this provider gives 30%, 2Y 40%, ... + volume_discounts []int = [10, 20, 30] // e.g. 10,20,30 } diff --git a/lib/threefold/grid4/datamodel/model_simulations.v b/lib/threefold/grid4/datamodel/model_simulations.v index 13a1c12e..178c6a0b 100644 --- a/lib/threefold/grid4/datamodel/model_simulations.v +++ b/lib/threefold/grid4/datamodel/model_simulations.v @@ -3,5 +3,5 @@ module datamodel pub struct NodeSim { Node pub mut: - cost f64 //free + cost f64 // free } diff --git a/lib/threefold/grid4/datamodel/model_slices.v b/lib/threefold/grid4/datamodel/model_slices.v index e3df9e5f..682124c6 100644 --- a/lib/threefold/grid4/datamodel/model_slices.v +++ b/lib/threefold/grid4/datamodel/model_slices.v @@ -1,32 +1,29 @@ module datamodel -//typically 1GB of memory, but can be adjusted based based on size of machine +// typically 1GB of memory, but can be adjusted based based on size of machine pub struct ComputeSlice { pub mut: - nodeid u32 //the node in the grid, there is an object describing the node - id int //the id of the slice in the node - mem_gb f64 - storage_gb f64 - passmark int - vcores int - cpu_oversubscription int - storage_oversubscription int - price_range []f64 = [0.0, 0.0] - gpus u8 //nr of GPU's see node to know what GPU's are - price_cc f64 //price per slice (even if the grouped one) - pricing_policy PricingPolicy - sla_policy SLAPolicy - + nodeid u32 // the node in the grid, there is an object describing the node + id int // the id of the slice in the node + mem_gb f64 + storage_gb f64 + passmark int + vcores int + cpu_oversubscription int + storage_oversubscription int + price_range []f64 = [0.0, 0.0] + gpus u8 // nr of GPU's see node to know what GPU's are + price_cc f64 // price per slice (even if the grouped one) + pricing_policy PricingPolicy + sla_policy SLAPolicy } -//1GB of storage +// 1GB of storage pub struct StorageSlice { pub mut: - nodeid u32 //the node in the grid - id int //the id of the slice in the node, are tracked in the node itself - price_cc f64 //price per slice (even if the grouped one) - pricing_policy PricingPolicy - sla_policy SLAPolicy + nodeid u32 // the node in the grid + id int // the id of the slice in the node, are tracked in the node itself + price_cc f64 // price per slice (even if the grouped one) + pricing_policy PricingPolicy + sla_policy SLAPolicy } - - diff --git a/lib/threefold/grid4/datamodelsimulator/model_aggregated.v b/lib/threefold/grid4/datamodelsimulator/model_aggregated.v index d2011d78..dc9293b2 100644 --- a/lib/threefold/grid4/datamodelsimulator/model_aggregated.v +++ b/lib/threefold/grid4/datamodelsimulator/model_aggregated.v @@ -2,7 +2,6 @@ module datamodelsimulator import time - // NodeTotalSim represents the aggregated data for a node simulation, including hardware specs, pricing, and location. pub struct NodeTotalSim { pub mut: @@ -23,14 +22,14 @@ pub fn (n NodeSim) total() !NodeTotalSim { } mut total := NodeTotalSim{ - id: n.id - cost: n.cost - deliverytime: time.now() // Placeholder; replace with actual logic if needed - inca_reward: 0 // Placeholder; compute from policy if available - reputation: 50 // Default; compute from uptime/history - uptime: n.uptime + id: n.id + cost: n.cost + deliverytime: time.now() // Placeholder; replace with actual logic if needed + inca_reward: 0 // Placeholder; compute from policy if available + reputation: 50 // Default; compute from uptime/history + uptime: n.uptime price_simulation: 0.0 - capacity: NodeCapacity{} + capacity: NodeCapacity{} } // Aggregate from compute slices diff --git a/lib/threefold/grid4/datamodelsimulator/play.v b/lib/threefold/grid4/datamodelsimulator/play.v index 81aad0a6..18677206 100644 --- a/lib/threefold/grid4/datamodelsimulator/play.v +++ b/lib/threefold/grid4/datamodelsimulator/play.v @@ -8,7 +8,7 @@ pub fn play(mut plbook PlayBook) !map[string]&Node { mut nodesdict := map[string]&Node{} for action in actions2 { - echo("TODO: Implement action handling for ${action.name}") + echo('TODO: Implement action handling for ${action.name}') } return nodesdict } diff --git a/lib/web/heroprompt/server.v b/lib/web/heroprompt/server.v index f901eb3f..8ba215cf 100644 --- a/lib/web/heroprompt/server.v +++ b/lib/web/heroprompt/server.v @@ -30,8 +30,8 @@ pub mut: pub fn new(args FactoryArgs) !&App { base := os.dir(@FILE) mut app := App{ - title: args.title - port: args.port + title: args.title + port: args.port base_path: base } // Serve static assets from this module at /static @@ -62,10 +62,10 @@ fn render_index(app &App) string { } fn render_index_fallback(app &App) string { - return '\n' - + html_escape(app.title) - + '

' - + html_escape(app.title) - + '

Heroprompt server is running.

' + return + '\n' + + html_escape(app.title) + + '

' + + html_escape(app.title) + + '

Heroprompt server is running.

' } - diff --git a/lib/web/ui/factory.v b/lib/web/ui/factory.v index d2a0fa17..5c703d96 100644 --- a/lib/web/ui/factory.v +++ b/lib/web/ui/factory.v @@ -3,7 +3,6 @@ module ui import veb import os - // Public Context type for veb pub struct Context { veb.Context @@ -33,18 +32,17 @@ pub mut: pub struct App { veb.StaticHandler pub mut: - title string = "default" + title string = 'default' menu []MenuItem port int = 7711 } - // Start the webserver (blocking) -pub fn start(args WebArgs) !{ +pub fn start(args WebArgs) ! { mut app := App{ - title: args.title, - menu: args.menu, - port: args.port + title: args.title + menu: args.menu + port: args.port } veb.run[App, Context](mut app, app.port) } diff --git a/lib/web/ui/utils.v b/lib/web/ui/utils.v index 943f7b09..1f81f654 100644 --- a/lib/web/ui/utils.v +++ b/lib/web/ui/utils.v @@ -8,7 +8,11 @@ fn menu_html(items []MenuItem, depth int, prefix string) string { if it.children.len > 0 { // expandable group out << '
' - out << '' + out << '' out << '${it.title}' out << '' out << '
' @@ -24,4 +28,3 @@ fn menu_html(items []MenuItem, depth int, prefix string) string { } return out.join('\n') } -