Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move 'kcl mod graph' to api Graph() #169

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 13 additions & 22 deletions cmd/kcl/commands/mod_graph.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package cmd

import (
"fmt"
"os"

"github.com/dominikbraun/graph"
"github.com/spf13/cobra"
"golang.org/x/mod/module"
"kcl-lang.io/kpm/pkg/client"
Expand Down Expand Up @@ -65,7 +63,10 @@ func ModGraph(cli *client.KpmClient, args []string) error {
return err
}

kclPkg, err := pkg.LoadKclPkg(pwd)
kclPkg, err := pkg.LoadKclPkgWithOpts(
pkg.WithPath(pwd),
pkg.WithSettings(cli.GetSettings()),
)
if err != nil {
return err
}
Expand All @@ -75,30 +76,20 @@ func ModGraph(cli *client.KpmClient, args []string) error {
return err
}

_, depGraph, err := cli.InitGraphAndDownloadDeps(kclPkg)
if err != nil {
return err
}
gra, err := cli.Graph(
client.WithGraphMod(kclPkg),
)

adjMap, err := depGraph.AdjacencyMap()
if err != nil {
return err
}
graStr, err := gra.DisplayGraphFromVertex(
module.Version{Path: kclPkg.GetPkgName(), Version: kclPkg.GetPkgVersion()},
)

// Print the dependency graph to stdout.
root := module.Version{Path: kclPkg.GetPkgName(), Version: kclPkg.GetPkgVersion()}
err = graph.BFS(depGraph, root, func(source module.Version) bool {
for target := range adjMap[source] {
reporter.ReportMsgTo(
fmt.Sprint(format(source), " ", format(target)),
cli.GetLogWriter(),
)
}
return false
})
if err != nil {
return err
}

reporter.ReportMsgTo(graStr, cli.GetLogWriter())

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
kcl-lang.io/kcl-go v0.10.8
kcl-lang.io/kcl-openapi v0.10.0
kcl-lang.io/kcl-plugin v0.6.0
kcl-lang.io/kpm v0.10.1-0.20241112023306-e41835e686a8
kcl-lang.io/kpm v0.10.1-0.20241112112118-8cf5a37c7c35
)

require (
Expand Down Expand Up @@ -103,7 +103,7 @@ require (
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dominikbraun/graph v0.23.0
github.com/dominikbraun/graph v0.23.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.18.0
github.com/getkin/kin-openapi v0.128.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1707,8 +1707,8 @@ kcl-lang.io/kcl-openapi v0.10.0 h1:yetZMSnn/HHaMcfiLt1P2zhCF06O33jxkjtHrm08VR8=
kcl-lang.io/kcl-openapi v0.10.0/go.mod h1:kGCf0AZygrZyB+xpmMtiC3FYoiV/1rCLXuAq2QtuLf8=
kcl-lang.io/kcl-plugin v0.6.0 h1:rBdoqKDPdOtojeOHCFnXoB/I7ltFjV61r0KkfOcL5sE=
kcl-lang.io/kcl-plugin v0.6.0/go.mod h1:LoIouleHYRKAvFcdW30yUlhsMYH2W9zD5Ji1XHfbht4=
kcl-lang.io/kpm v0.10.1-0.20241112023306-e41835e686a8 h1:H4H6TEyre+dMzcHHWt6gkxqY+ENACrapl1oSmuHro2w=
kcl-lang.io/kpm v0.10.1-0.20241112023306-e41835e686a8/go.mod h1:/G40SABMTuPEVaD1lp0nvPx4v1TIvxIuDwNCV6N9YSU=
kcl-lang.io/kpm v0.10.1-0.20241112112118-8cf5a37c7c35 h1:8Z4QrdeJWx00TMw09r/UwbA1vvV2ej/M2MAfBpPEzUU=
kcl-lang.io/kpm v0.10.1-0.20241112112118-8cf5a37c7c35/go.mod h1:/G40SABMTuPEVaD1lp0nvPx4v1TIvxIuDwNCV6N9YSU=
kcl-lang.io/lib v0.10.8 h1:/Mhko6fngIstvdx9dAS3H6N1utogkWfoARVj643l5nU=
kcl-lang.io/lib v0.10.8/go.mod h1:0Dw/MQwRMjLDksxl4JerGBn/ueaxRyCCKBCCwQwJ1MI=
oras.land/oras-go v1.2.6 h1:z8cmxQXBU8yZ4mkytWqXfo6tZcamPwjsuxYU81xJ8Lk=
Expand Down
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/e2e/test_suites/test_mod_graph/stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[email protected] [email protected]
7 changes: 7 additions & 0 deletions test/e2e/test_suites/test_mod_graph/test_space/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "test_space"
edition = "v0.10.0"
version = "0.0.1"

[dependencies]
helloworld = "0.1.4"
8 changes: 8 additions & 0 deletions test/e2e/test_suites/test_mod_graph/test_space/kcl.mod.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[dependencies]
[dependencies.helloworld]
name = "helloworld"
full_name = "helloworld_0.1.4"
version = "0.1.4"
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.4"
1 change: 1 addition & 0 deletions test/e2e/test_suites/test_mod_graph/test_space/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'
Loading