diff --git a/internal/scripts/build-kclvm.sh b/internal/scripts/build-kclvm.sh index d93d47772..bfd54bba5 100755 --- a/internal/scripts/build-kclvm.sh +++ b/internal/scripts/build-kclvm.sh @@ -47,5 +47,5 @@ echo "================ Summary ================" echo " KCLVM is installed into $kclvm_install_dir" # Run KCL CLI to install dependencies. -$kclvm_install_dir/bin/kclvm -m pip install kclvm --user +$kclvm_install_dir/bin/kclvm -m pip install -U kclvm --user $kclvm_install_dir/bin/kcl diff --git a/internal/scripts/cli/kcl b/internal/scripts/cli/kcl index 1ff0ca0ac..cb11cde58 100755 --- a/internal/scripts/cli/kcl +++ b/internal/scripts/cli/kcl @@ -19,7 +19,7 @@ if [ ! -f $pip_install_done_file ]; then # check python3 version $python3_bin -c "import sys; sys.exit(0) if sys.version_info>=(3,7,3) else (print('please install python 3.7.3+') or sys.exit(1))" # kclvm pip install all libs - $python3_bin -m pip install kclvm --user + $python3_bin -m pip install -U kclvm --user echo 'done' > $pip_install_done_file fi diff --git a/internal/scripts/cli/kcl-doc b/internal/scripts/cli/kcl-doc index 2d66f6f13..1f71e77c2 100755 --- a/internal/scripts/cli/kcl-doc +++ b/internal/scripts/cli/kcl-doc @@ -19,7 +19,7 @@ if [ ! -f $pip_install_done_file ]; then # check python3 version $python3_bin -c "import sys; sys.exit(0) if sys.version_info>=(3,7,3) else (print('please install python 3.7.3+') or sys.exit(1))" # kclvm pip install all libs - $python3_bin -m pip install kclvm --user + $python3_bin -m pip install -U kclvm --user echo 'done' > $pip_install_done_file fi diff --git a/internal/scripts/cli/kcl-fmt b/internal/scripts/cli/kcl-fmt index c083c3ba0..d6d64064a 100755 --- a/internal/scripts/cli/kcl-fmt +++ b/internal/scripts/cli/kcl-fmt @@ -19,7 +19,7 @@ if [ ! -f $pip_install_done_file ]; then # check python3 version $python3_bin -c "import sys; sys.exit(0) if sys.version_info>=(3,7,3) else (print('please install python 3.7.3+') or sys.exit(1))" # kclvm pip install all libs - $python3_bin -m pip install kclvm --user + $python3_bin -m pip install -U kclvm --user echo 'done' > $pip_install_done_file fi diff --git a/internal/scripts/cli/kcl-lint b/internal/scripts/cli/kcl-lint index 7d9bd1aa7..7a7c92adc 100755 --- a/internal/scripts/cli/kcl-lint +++ b/internal/scripts/cli/kcl-lint @@ -19,7 +19,7 @@ if [ ! -f $pip_install_done_file ]; then # check python3 version $python3_bin -c "import sys; sys.exit(0) if sys.version_info>=(3,7,3) else (print('please install python 3.7.3+') or sys.exit(1))" # kclvm pip install all libs - $python3_bin -m pip install kclvm --user + $python3_bin -m pip install -U kclvm --user echo 'done' > $pip_install_done_file fi diff --git a/internal/scripts/cli/kcl-plugin b/internal/scripts/cli/kcl-plugin index 0fade8fa2..990927ac9 100755 --- a/internal/scripts/cli/kcl-plugin +++ b/internal/scripts/cli/kcl-plugin @@ -19,7 +19,7 @@ if [ ! -f $pip_install_done_file ]; then # check python3 version $python3_bin -c "import sys; sys.exit(0) if sys.version_info>=(3,7,3) else (print('please install python 3.7.3+') or sys.exit(1))" # kclvm pip install all libs - $python3_bin -m pip install kclvm --user + $python3_bin -m pip install -U kclvm --user echo 'done' > $pip_install_done_file fi diff --git a/internal/scripts/cli/kcl-vet b/internal/scripts/cli/kcl-vet index d794d3b4f..13c8d28cb 100755 --- a/internal/scripts/cli/kcl-vet +++ b/internal/scripts/cli/kcl-vet @@ -19,7 +19,7 @@ if [ ! -f $pip_install_done_file ]; then # check python3 version $python3_bin -c "import sys; sys.exit(0) if sys.version_info>=(3,7,3) else (print('please install python 3.7.3+') or sys.exit(1))" # kclvm pip install all libs - $python3_bin -m pip install kclvm --user + $python3_bin -m pip install -U kclvm --user echo 'done' > $pip_install_done_file fi diff --git a/internal/scripts/kcllib-install.sh b/internal/scripts/kcllib-install.sh index 93aeee658..cccb58da3 100755 --- a/internal/scripts/kcllib-install.sh +++ b/internal/scripts/kcllib-install.sh @@ -23,5 +23,5 @@ $python3_bin -c "import sys; sys.exit(0) if sys.version_info>=(3,7,3) else (prin # kclvm pip install all libs $python3_bin -m pip install --upgrade pip -$python3_bin -m pip install kclvm +$python3_bin -m pip install -U kclvm echo 'done' > $pip_install_done_file diff --git a/internal/scripts/test_grammar.sh b/internal/scripts/test_grammar.sh index afc75e6c1..fbfd9df81 100755 --- a/internal/scripts/test_grammar.sh +++ b/internal/scripts/test_grammar.sh @@ -18,6 +18,6 @@ export PATH=$PATH:$topdir/_build/dist/$os/kclvm/bin # Grammar test cd $kclvm_source_dir/test/grammar python3 -m pip install --upgrade pip -python3 -m pip install kclvm +python3 -m pip install -U kclvm python3 -m pip install pytest pytest-xdist python3 -m pytest -v -n 10 diff --git a/scripts/build-windows/kcl-doc.go b/scripts/build-windows/kcl-doc.go index a93eaf129..d216f0b87 100644 --- a/scripts/build-windows/kcl-doc.go +++ b/scripts/build-windows/kcl-doc.go @@ -6,10 +6,12 @@ package main import ( + "bytes" "fmt" "os" "os/exec" "path/filepath" + "strconv" ) func main() { @@ -28,9 +30,8 @@ func Py_Main(args []string) int { fmt.Fprintln(os.Stderr, "Input path does not exist") os.Exit(1) } - kclvm_install_dir_bin := filepath.Dir(inputPath) - Install_Kclvm(kclvm_install_dir_bin) - kclvm_install_dir := filepath.Dir(kclvm_install_dir_bin) + Install_Kclvm() + kclvm_install_dir := filepath.Dir(filepath.Dir(inputPath)) cmd := exec.Command("cmd", args...) cmd.Stderr = os.Stderr @@ -46,7 +47,7 @@ func Py_Main(args []string) int { return 0 } -func Install_Kclvm(installed_path string) { +func Install_Kclvm() { // Check if Python3 is installed cmd := exec.Command("cmd", "/C", "where python3") cmd.Stderr = os.Stderr @@ -57,29 +58,29 @@ func Install_Kclvm(installed_path string) { os.Exit(1) } - // Check if "installed" file exists - outputPath := filepath.Join(installed_path, "kclvm_installed") - if _, err := os.Stat(outputPath); err == nil { + cmd = exec.Command("cmd", "/C", "python3", "-c", "import pkgutil; print(bool(pkgutil.find_loader('kclvm')))") + var out bytes.Buffer + cmd.Stdout = &out + + if err := cmd.Run(); err != nil { + fmt.Fprintln(os.Stderr, "Pip install kclvm falied ", err) + os.Exit(1) + } + + is_installed, err := strconv.ParseBool(out.String()) + + // Check if kclvm has been installed. + if err == nil && is_installed { return } // Install kclvm module using pip - cmd = exec.Command("cmd", "/C", "python3", "-m", "pip", "install", "kclvm") - cmd.Stderr = os.Stderr + cmd = exec.Command("cmd", "/C", "python3", "-m", "pip", "install", "-U", "kclvm", "--user") - err = cmd.Run() - if err != nil { + if err := cmd.Run(); err != nil { fmt.Fprintln(os.Stderr, "Pip install kclvm falied ", err) os.Exit(1) } - - // Create "installed" file - f, err := os.Create(outputPath) - if err != nil { - fmt.Fprintln(os.Stderr, "Error creating file: ", err) - os.Exit(1) - } - defer f.Close() } func Set_Env(kclvm_install_dir string, cmd *exec.Cmd) { diff --git a/scripts/build-windows/kcl-fmt.go b/scripts/build-windows/kcl-fmt.go index e0d881ee3..d2df02b7b 100644 --- a/scripts/build-windows/kcl-fmt.go +++ b/scripts/build-windows/kcl-fmt.go @@ -6,10 +6,12 @@ package main import ( + "bytes" "fmt" "os" "os/exec" "path/filepath" + "strconv" ) func main() { @@ -28,9 +30,8 @@ func Py_Main(args []string) int { fmt.Fprintln(os.Stderr, "Input path does not exist") os.Exit(1) } - kclvm_install_dir_bin := filepath.Dir(inputPath) - Install_Kclvm(kclvm_install_dir_bin) - kclvm_install_dir := filepath.Dir(kclvm_install_dir_bin) + Install_Kclvm() + kclvm_install_dir := filepath.Dir(filepath.Dir(inputPath)) cmd := exec.Command("cmd", args...) cmd.Stderr = os.Stderr @@ -46,7 +47,7 @@ func Py_Main(args []string) int { return 0 } -func Install_Kclvm(installed_path string) { +func Install_Kclvm() { // Check if Python3 is installed cmd := exec.Command("cmd", "/C", "where python3") cmd.Stderr = os.Stderr @@ -57,29 +58,29 @@ func Install_Kclvm(installed_path string) { os.Exit(1) } - // Check if "installed" file exists - outputPath := filepath.Join(installed_path, "kclvm_installed") - if _, err := os.Stat(outputPath); err == nil { + cmd = exec.Command("cmd", "/C", "python3", "-c", "import pkgutil; print(bool(pkgutil.find_loader('kclvm')))") + var out bytes.Buffer + cmd.Stdout = &out + + if err := cmd.Run(); err != nil { + fmt.Fprintln(os.Stderr, "Pip install kclvm falied ", err) + os.Exit(1) + } + + is_installed, err := strconv.ParseBool(out.String()) + + // Check if kclvm has been installed. + if err == nil && is_installed { return } // Install kclvm module using pip - cmd = exec.Command("cmd", "/C", "python3", "-m", "pip", "install", "kclvm") - cmd.Stderr = os.Stderr + cmd = exec.Command("cmd", "/C", "python3", "-m", "pip", "install", "-U", "kclvm", "--user") - err = cmd.Run() - if err != nil { + if err := cmd.Run(); err != nil { fmt.Fprintln(os.Stderr, "Pip install kclvm falied ", err) os.Exit(1) } - - // Create "installed" file - f, err := os.Create(outputPath) - if err != nil { - fmt.Fprintln(os.Stderr, "Error creating file: ", err) - os.Exit(1) - } - defer f.Close() } func Set_Env(kclvm_install_dir string, cmd *exec.Cmd) { diff --git a/scripts/build-windows/kcl-lint.go b/scripts/build-windows/kcl-lint.go index 10d3dd438..00b9cf7ab 100644 --- a/scripts/build-windows/kcl-lint.go +++ b/scripts/build-windows/kcl-lint.go @@ -6,10 +6,12 @@ package main import ( + "bytes" "fmt" "os" "os/exec" "path/filepath" + "strconv" ) func main() { @@ -28,9 +30,8 @@ func Py_Main(args []string) int { fmt.Fprintln(os.Stderr, "Input path does not exist") os.Exit(1) } - kclvm_install_dir_bin := filepath.Dir(inputPath) - Install_Kclvm(kclvm_install_dir_bin) - kclvm_install_dir := filepath.Dir(kclvm_install_dir_bin) + Install_Kclvm() + kclvm_install_dir := filepath.Dir(filepath.Dir(inputPath)) cmd := exec.Command("cmd", args...) cmd.Stderr = os.Stderr @@ -46,7 +47,7 @@ func Py_Main(args []string) int { return 0 } -func Install_Kclvm(installed_path string) { +func Install_Kclvm() { // Check if Python3 is installed cmd := exec.Command("cmd", "/C", "where python3") cmd.Stderr = os.Stderr @@ -57,29 +58,29 @@ func Install_Kclvm(installed_path string) { os.Exit(1) } - // Check if "installed" file exists - outputPath := filepath.Join(installed_path, "kclvm_installed") - if _, err := os.Stat(outputPath); err == nil { + cmd = exec.Command("cmd", "/C", "python3", "-c", "import pkgutil; print(bool(pkgutil.find_loader('kclvm')))") + var out bytes.Buffer + cmd.Stdout = &out + + if err := cmd.Run(); err != nil { + fmt.Fprintln(os.Stderr, "Pip install kclvm falied ", err) + os.Exit(1) + } + + is_installed, err := strconv.ParseBool(out.String()) + + // Check if kclvm has been installed. + if err == nil && is_installed { return } // Install kclvm module using pip - cmd = exec.Command("cmd", "/C", "python3", "-m", "pip", "install", "kclvm") - cmd.Stderr = os.Stderr + cmd = exec.Command("cmd", "/C", "python3", "-m", "pip", "install", "-U", "kclvm", "--user") - err = cmd.Run() - if err != nil { + if err := cmd.Run(); err != nil { fmt.Fprintln(os.Stderr, "Pip install kclvm falied ", err) os.Exit(1) } - - // Create "installed" file - f, err := os.Create(outputPath) - if err != nil { - fmt.Fprintln(os.Stderr, "Error creating file: ", err) - os.Exit(1) - } - defer f.Close() } func Set_Env(kclvm_install_dir string, cmd *exec.Cmd) { diff --git a/scripts/build-windows/kcl-plugin.go b/scripts/build-windows/kcl-plugin.go index 56a3e5dcc..810410971 100644 --- a/scripts/build-windows/kcl-plugin.go +++ b/scripts/build-windows/kcl-plugin.go @@ -6,10 +6,12 @@ package main import ( + "bytes" "fmt" "os" "os/exec" "path/filepath" + "strconv" ) func main() { @@ -28,9 +30,8 @@ func Py_Main(args []string) int { fmt.Fprintln(os.Stderr, "Input path does not exist") os.Exit(1) } - kclvm_install_dir_bin := filepath.Dir(inputPath) - Install_Kclvm(kclvm_install_dir_bin) - kclvm_install_dir := filepath.Dir(kclvm_install_dir_bin) + Install_Kclvm() + kclvm_install_dir := filepath.Dir(filepath.Dir(inputPath)) cmd := exec.Command("cmd", args...) cmd.Stderr = os.Stderr @@ -46,7 +47,7 @@ func Py_Main(args []string) int { return 0 } -func Install_Kclvm(installed_path string) { +func Install_Kclvm() { // Check if Python3 is installed cmd := exec.Command("cmd", "/C", "where python3") cmd.Stderr = os.Stderr @@ -57,29 +58,29 @@ func Install_Kclvm(installed_path string) { os.Exit(1) } - // Check if "installed" file exists - outputPath := filepath.Join(installed_path, "kclvm_installed") - if _, err := os.Stat(outputPath); err == nil { + cmd = exec.Command("cmd", "/C", "python3", "-c", "import pkgutil; print(bool(pkgutil.find_loader('kclvm')))") + var out bytes.Buffer + cmd.Stdout = &out + + if err := cmd.Run(); err != nil { + fmt.Fprintln(os.Stderr, "Pip install kclvm falied ", err) + os.Exit(1) + } + + is_installed, err := strconv.ParseBool(out.String()) + + // Check if kclvm has been installed. + if err == nil && is_installed { return } // Install kclvm module using pip - cmd = exec.Command("cmd", "/C", "python3", "-m", "pip", "install", "kclvm") - cmd.Stderr = os.Stderr + cmd = exec.Command("cmd", "/C", "python3", "-m", "pip", "install", "-U", "kclvm", "--user") - err = cmd.Run() - if err != nil { + if err := cmd.Run(); err != nil { fmt.Fprintln(os.Stderr, "Pip install kclvm falied ", err) os.Exit(1) } - - // Create "installed" file - f, err := os.Create(outputPath) - if err != nil { - fmt.Fprintln(os.Stderr, "Error creating file: ", err) - os.Exit(1) - } - defer f.Close() } func Set_Env(kclvm_install_dir string, cmd *exec.Cmd) { diff --git a/scripts/build-windows/kcl-vet.go b/scripts/build-windows/kcl-vet.go index 6c46ad99b..d5148875d 100644 --- a/scripts/build-windows/kcl-vet.go +++ b/scripts/build-windows/kcl-vet.go @@ -6,10 +6,12 @@ package main import ( + "bytes" "fmt" "os" "os/exec" "path/filepath" + "strconv" ) func main() { @@ -28,9 +30,8 @@ func Py_Main(args []string) int { fmt.Fprintln(os.Stderr, "Input path does not exist") os.Exit(1) } - kclvm_install_dir_bin := filepath.Dir(inputPath) - Install_Kclvm(kclvm_install_dir_bin) - kclvm_install_dir := filepath.Dir(kclvm_install_dir_bin) + Install_Kclvm() + kclvm_install_dir := filepath.Dir(filepath.Dir(inputPath)) cmd := exec.Command("cmd", args...) cmd.Stderr = os.Stderr @@ -46,7 +47,7 @@ func Py_Main(args []string) int { return 0 } -func Install_Kclvm(installed_path string) { +func Install_Kclvm() { // Check if Python3 is installed cmd := exec.Command("cmd", "/C", "where python3") cmd.Stderr = os.Stderr @@ -57,29 +58,29 @@ func Install_Kclvm(installed_path string) { os.Exit(1) } - // Check if "installed" file exists - outputPath := filepath.Join(installed_path, "kclvm_installed") - if _, err := os.Stat(outputPath); err == nil { + cmd = exec.Command("cmd", "/C", "python3", "-c", "import pkgutil; print(bool(pkgutil.find_loader('kclvm')))") + var out bytes.Buffer + cmd.Stdout = &out + + if err := cmd.Run(); err != nil { + fmt.Fprintln(os.Stderr, "Pip install kclvm falied ", err) + os.Exit(1) + } + + is_installed, err := strconv.ParseBool(out.String()) + + // Check if kclvm has been installed. + if err == nil && is_installed { return } // Install kclvm module using pip - cmd = exec.Command("cmd", "/C", "python3", "-m", "pip", "install", "kclvm") - cmd.Stderr = os.Stderr + cmd = exec.Command("cmd", "/C", "python3", "-m", "pip", "install", "-U", "kclvm", "--user") - err = cmd.Run() - if err != nil { + if err := cmd.Run(); err != nil { fmt.Fprintln(os.Stderr, "Pip install kclvm falied ", err) os.Exit(1) } - - // Create "installed" file - f, err := os.Create(outputPath) - if err != nil { - fmt.Fprintln(os.Stderr, "Error creating file: ", err) - os.Exit(1) - } - defer f.Close() } func Set_Env(kclvm_install_dir string, cmd *exec.Cmd) { diff --git a/scripts/build-windows/kcl.go b/scripts/build-windows/kcl.go index e0e70f922..03defc65b 100644 --- a/scripts/build-windows/kcl.go +++ b/scripts/build-windows/kcl.go @@ -6,10 +6,12 @@ package main import ( + "bytes" "fmt" "os" "os/exec" "path/filepath" + "strconv" ) func main() { @@ -28,9 +30,8 @@ func Py_Main(args []string) int { fmt.Fprintln(os.Stderr, "Input path does not exist") os.Exit(1) } - kclvm_install_dir_bin := filepath.Dir(inputPath) - Install_Kclvm(kclvm_install_dir_bin) - kclvm_install_dir := filepath.Dir(kclvm_install_dir_bin) + Install_Kclvm() + kclvm_install_dir := filepath.Dir(filepath.Dir(inputPath)) cmd := exec.Command("cmd", args...) cmd.Stderr = os.Stderr @@ -46,7 +47,7 @@ func Py_Main(args []string) int { return 0 } -func Install_Kclvm(installed_path string) { +func Install_Kclvm() { // Check if Python3 is installed cmd := exec.Command("cmd", "/C", "where python3") cmd.Stderr = os.Stderr @@ -57,29 +58,29 @@ func Install_Kclvm(installed_path string) { os.Exit(1) } - // Check if "installed" file exists - outputPath := filepath.Join(installed_path, "kclvm_installed") - if _, err := os.Stat(outputPath); err == nil { + cmd = exec.Command("cmd", "/C", "python3", "-c", "import pkgutil; print(bool(pkgutil.find_loader('kclvm')))") + var out bytes.Buffer + cmd.Stdout = &out + + if err := cmd.Run(); err != nil { + fmt.Fprintln(os.Stderr, "Pip install kclvm falied ", err) + os.Exit(1) + } + + is_installed, err := strconv.ParseBool(out.String()) + + // Check if kclvm has been installed. + if err == nil && is_installed { return } // Install kclvm module using pip - cmd = exec.Command("cmd", "/C", "python3", "-m", "pip", "install", "kclvm") - cmd.Stderr = os.Stderr + cmd = exec.Command("cmd", "/C", "python3", "-m", "pip", "install", "-U", "kclvm", "--user") - err = cmd.Run() - if err != nil { + if err := cmd.Run(); err != nil { fmt.Fprintln(os.Stderr, "Pip install kclvm falied ", err) os.Exit(1) } - - // Create "installed" file - f, err := os.Create(outputPath) - if err != nil { - fmt.Fprintln(os.Stderr, "Error creating file: ", err) - os.Exit(1) - } - defer f.Close() } func Set_Env(kclvm_install_dir string, cmd *exec.Cmd) { diff --git a/scripts/docker/kclvm/Dockerfile b/scripts/docker/kclvm/Dockerfile index 3bad0fe8d..9c8e360c6 100644 --- a/scripts/docker/kclvm/Dockerfile +++ b/scripts/docker/kclvm/Dockerfile @@ -6,7 +6,7 @@ FROM ubuntu:22.04 RUN apt-get update RUN apt-get install python3 python3-pip -y -RUN python3 -m pip install kclvm +RUN python3 -m pip install -U kclvm # Copy the kclvm artifact.