Skip to content

Commit

Permalink
Revert "added the version field in kcl.mod"
Browse files Browse the repository at this point in the history
This reverts commit 9b57736.
  • Loading branch information
Gmin2 committed Jul 29, 2024
1 parent 9b57736 commit b49f130
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 34 deletions.
9 changes: 0 additions & 9 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,15 +829,6 @@ func (c *KpmClient) AddDepToPkg(kclPkg *pkg.KclPkg, d *pkg.Dependency) error {
return err
}

// After downloading, extract the version from the kcl.mod file
downloadedPkg, err := c.LoadPkgFromPath(c.getDepStorePath(c.homePath, d, false))
if err != nil {
return fmt.Errorf("failed to load downloaded package: %w", err)
}
d.Version = downloadedPkg.GetPkgVersion()
kclPkg.ModFile.Dependencies.Deps.Set(d.Name, *d)


return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/package/modfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ func (deps *Dependencies) CheckForLocalDeps() bool {
type Dependency struct {
Name string `json:"name" toml:"name,omitempty"`
FullName string `json:"-" toml:"full_name,omitempty"`
Version string `json:"-" toml:"version,omitempty"`
Sum string `json:"-" toml:"sum,omitempty"`
// The actual local path of the package.
// In vendor mode is "current_kcl_package/vendor"
// In non-vendor mode is "$KCL_PKG_PATH"
LocalFullPath string `json:"manifest_path" toml:"-"`
downloader.Source `json:"-"`
Version string `json:"version,omitempty" toml:"version,omitempty"`
}

func (d *Dependency) FromKclPkg(pkg *KclPkg) {
Expand Down
25 changes: 1 addition & 24 deletions pkg/package/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,7 @@ func (dep *Dependency) MarshalTOML() string {
source := dep.Source.MarshalTOML()
var sb strings.Builder
if len(source) != 0 {
sourceWithoutBrace := strings.TrimSuffix(source, "}")

// Add the version if it exists
if dep.Version != "" {
sourceWithoutBrace += fmt.Sprintf(`, version = "%s"`, dep.Version)
}

// Add the closing brace back
sourceWithoutBrace += "}"

sb.WriteString(fmt.Sprintf(DEP_PATTERN, dep.Name, sourceWithoutBrace))
sb.WriteString(fmt.Sprintf(DEP_PATTERN, dep.Name, source))
}
return sb.String()
}
Expand Down Expand Up @@ -245,14 +235,6 @@ func (dep *Dependency) UnmarshalModTOML(data interface{}) error {
}

dep.Source = source

// Try to extract version from the data
if meta, ok := data.(map[string]interface{}); ok {
if v, ok := meta["version"].(string); ok {
dep.Version = v
}
}

var version string
if source.Git != nil {
version, err = source.Git.GetValidGitReference()
Expand All @@ -267,11 +249,6 @@ func (dep *Dependency) UnmarshalModTOML(data interface{}) error {
version = source.Registry.Version
}

// If version is not set explicitly, use the one from the source
if dep.Version == "" {
dep.Version = version
}

dep.FullName = fmt.Sprintf(PKG_NAME_PATTERN, dep.Name, version)
dep.Version = version
return nil
Expand Down

0 comments on commit b49f130

Please sign in to comment.