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

Enhancement: The feature renaming dependency is incomplete #420

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

Manoramsharma
Copy link
Contributor

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

Fixes #397

2. What is the scope of this PR (e.g. component or file name):

/package/toml.go
/downloader/toml.go
/downloader/toml_test.go
/downloader/test_data/test_data_toml

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • [y] Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

Manoramsharma and others added 4 commits July 31, 2024 00:56
Signed-off-by: Manoramsharma <[email protected]>
Signed-off-by: Manoramsharma <[email protected]>
Signed-off-by: Manoramsharma <[email protected]>
Signed-off-by: Manoramsharma <[email protected]>
@coveralls
Copy link

coveralls commented Jul 31, 2024

Pull Request Test Coverage Report for Build 10278727053

Details

  • 6 of 18 (33.33%) changed or added relevant lines in 2 files are covered.
  • 7 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.3%) to 40.541%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/downloader/toml.go 5 17 29.41%
Files with Coverage Reduction New Missed Lines %
pkg/client/client.go 3 56.2%
pkg/downloader/toml.go 4 15.98%
Totals Coverage Status
Change from base Build 10278694661: 0.3%
Covered Lines: 3148
Relevant Lines: 7765

💛 - Coveralls

@Manoramsharma
Copy link
Contributor Author

@zong-zhe I have implemented the asked subtask and also changed test according to the implementation need. PTAL !!!

_ = os.Remove(filepath.Join(pkgPath, "kcl.mod.lock"))
}()
}
// func TestUpdateWithNoSumCheck(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this test ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not working and this is not due to my changes.

@@ -82,7 +82,7 @@ func (dep *Dependencies) MarshalTOML() string {
const DEP_PATTERN = "%s = %s"

func (dep *Dependency) MarshalTOML() string {
source := dep.Source.MarshalTOML()
source := dep.Source.MarshalTOML(dep.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not go this way, because the purpose of adding the package field is to support renaming dependency, you need to add a field on the Dependency structure to hold the package name and use this field when serializing to kcl.mod. Instead of simply using dep.Name, the value of package will not be the same as dep.Name when the rename function is implemented later.

@zong-zhe
Copy link
Contributor

zong-zhe commented Aug 6, 2024

Hi @Manoramsharma 😃

Is this work still moving forward ?

@Manoramsharma
Copy link
Contributor Author

Hi @Manoramsharma 😃

Is this work still moving forward ?

Hi @zong-zhe ,
Yes I am working on it and will soon come up with a PR.

@zong-zhe
Copy link
Contributor

zong-zhe commented Aug 8, 2024

Hi @Manoramsharma 😊

Is this PR finished? You can ping me if it's done or if there's any trouble.

@Manoramsharma
Copy link
Contributor Author

Hi @Manoramsharma 😊

Is this PR finished? You can ping me if it's done or if there's any trouble.

Hi @zong-zhe
I will look into it today and update you accordingly.

@Manoramsharma
Copy link
Contributor Author

Manoramsharma commented Aug 8, 2024

Hey @zong-zhe, I have added a field named package in the dependency. Now, I am confused because this package is also printed in kcl.lock.mod file. Can you please provide me some guidance on how to add this in packages/toml?

see here,

	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-[dependencies]  [dependencies.flask-demo-kcl-manifests]    name = "flask-demo-kcl-manifests"    full_name = "flask_manifests_0.0.1"    version = "0.0.1"    package = "flask-demo-kcl-manifests"    url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git"    commit = "ade147b"
        	            	+[dependencies]  [dependencies.flask-demo-kcl-manifests]    name = "flask-demo-kcl-manifests"    full_name = "flask_manifests_0.0.1"    version = "0.0.1"    url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git"    commit = "ade147b"

@@ -0,0 +1 @@
{ git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", version = "v0.1.0", package = "flask-demo-kcl-manifests" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changed here ?

@@ -193,6 +193,7 @@ type Dependency struct {
FullName string `json:"-" toml:"full_name,omitempty"`
Version string `json:"-" toml:"version,omitempty"`
Sum string `json:"-" toml:"sum,omitempty"`
Package string `json:"package" toml:"package,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At present, we do not need to serialize json when the output of this field Package, do not output first, to prevent users from relying on it, causing difficulties for our subsequent changes and updates. So set json:"-"

@zong-zhe
Copy link
Contributor

zong-zhe commented Aug 9, 2024

Hey @zong-zhe, I have added a field named package in the dependency. Now, I am confused because this package is also printed in kcl.lock.mod file. Can you please provide me some guidance on how to add this in packages/toml?

see here,

	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-[dependencies]  [dependencies.flask-demo-kcl-manifests]    name = "flask-demo-kcl-manifests"    full_name = "flask_manifests_0.0.1"    version = "0.0.1"    package = "flask-demo-kcl-manifests"    url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git"    commit = "ade147b"
        	            	+[dependencies]  [dependencies.flask-demo-kcl-manifests]    name = "flask-demo-kcl-manifests"    full_name = "flask_manifests_0.0.1"    version = "0.0.1"    url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git"    commit = "ade147b"

This part of the situation is normal, and it makes sense to specify the package's original name through the package field in kcl.mod.lock. You can change the test cases to make them pass.

@Manoramsharma
Copy link
Contributor Author

Manoramsharma commented Aug 9, 2024

const DEP_PATTERN = "%s = %s"

func (dep *Dependency) MarshalTOML() string {
	source := dep.Source.MarshalTOML()
	var sb strings.Builder
	if len(source) != 0 {
		sb.WriteString(fmt.Sprintf(DEP_PATTERN, dep.Name, source))
	}
	return sb.String()
}

"Hey @zong-zhe, I have one last confusion. How can I add a package in source? Can I change the layout of source so that I can print the package in DEP_PATTERN, or can I somehow manage to pass the package or the entire dependency to MARSHALTOML() of downloader to print the package name there and add it to source?"

@zong-zhe
Copy link
Contributor

zong-zhe commented Aug 9, 2024

const DEP_PATTERN = "%s = %s"

func (dep *Dependency) MarshalTOML() string {
	source := dep.Source.MarshalTOML()
	var sb strings.Builder
	if len(source) != 0 {
		sb.WriteString(fmt.Sprintf(DEP_PATTERN, dep.Name, source))
	}
	return sb.String()
}

"Hey @zong-zhe, I have one last confusion. How can I add a package in source? Can I change the layout of source so that I can print the package in DEP_PATTERN, or can I somehow manage to pass the package or the entire dependency to MARSHALTOML() of downloader to print the package name there and add it to source?"

Hi @Manoramsharma 😃

You can adjust the entire rendering toml flow to suit this process. Raises the generation "{}" to top level.

For example :

const DEP_PATTERN = "%s = %s"

func (dep *Dependency) MarshalTOML() string {
	source := dep.Source.MarshalTOML()
	var sb strings.Builder

        # Here is just a example, you need to implement this according to the actual situation
        source := "{"+ source + "package =" + dep.package   "}"

	if len(source) != 0 {
		sb.WriteString(fmt.Sprintf(DEP_PATTERN, dep.Name, source))
	}
	return sb.String()
}

Signed-off-by: Manoramsharma <[email protected]>
@Manoramsharma
Copy link
Contributor Author

@zong-zhe Please review this one i have done the suggested changes.

@Manoramsharma
Copy link
Contributor Author

@zong-zhe I have implemented the required changes. Previously, when encountering the opt.NewPkgName option, we only updated the dependency name (d.Name = newPkgName) to the new package name. Now, in addition to setting the dependency name, I have also configured the package field to use the old dependency name (package=d.Name).

@Peefy
Copy link
Contributor

Peefy commented Aug 20, 2024

cc @zong-zhe Could you help review it again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants