Skip to content

Commit

Permalink
Feat(kclvm-win): remove the "kclvm.requirements.done.txt" on windows. (
Browse files Browse the repository at this point in the history
…#392)

* Feat(kclvm-win): remove the "kclvm.requirements.done.txt" on windows.
issue #379.

* fix typo

* fix comments
  • Loading branch information
zong-zhe committed Jan 31, 2023
1 parent 00e207b commit 8ed4c5e
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 124 deletions.
2 changes: 1 addition & 1 deletion internal/scripts/build-kclvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion internal/scripts/cli/kcl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion internal/scripts/cli/kcl-doc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion internal/scripts/cli/kcl-fmt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion internal/scripts/cli/kcl-lint
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion internal/scripts/cli/kcl-plugin
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion internal/scripts/cli/kcl-vet
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion internal/scripts/kcllib-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion internal/scripts/test_grammar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 20 additions & 19 deletions scripts/build-windows/kcl-doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
package main

import (
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
)

func main() {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down
39 changes: 20 additions & 19 deletions scripts/build-windows/kcl-fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
package main

import (
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
)

func main() {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down
39 changes: 20 additions & 19 deletions scripts/build-windows/kcl-lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
package main

import (
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
)

func main() {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down
39 changes: 20 additions & 19 deletions scripts/build-windows/kcl-plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
package main

import (
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
)

func main() {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down
Loading

0 comments on commit 8ed4c5e

Please sign in to comment.