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

added design doc for sparse checkout #335

Merged
merged 17 commits into from
Aug 27, 2024
Merged
Changes from 16 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
74 changes: 74 additions & 0 deletions research/design-doc/sparse_checkout_asishkumar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# KPM sparse checkout

**Author**: Asish Kumar

## Solution

In order to add the feature of sparse-checkout, kpm will add the package specified in the kcl.mod file and later when running `kcl mod run` it will checkout that destination directory which contains that package recursively.

## User Interface
zong-zhe marked this conversation as resolved.
Show resolved Hide resolved

In order to use a specified package within a repository, the user will have to specify the package during the `kcl mod add` command. For example

```
kcl mod add --git https://github.com/officialasishkumar/check-kcl.git --commit 831fada36e155c8758f07f293c8267c869af69d3 --package k8s
Copy link
Contributor

Choose a reason for hiding this comment

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

Add more details, including what happens if --package is not added, since --package is an option flag, and updates in kcl.mod and kcl.mod.lock after running.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The feature won't work without a package flag. Should i specify that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we can not do an incomplete function for the user. You need to consider the user's various situations, and make corresponding preparations. For example, you should at least design that when he does not give this field or gives this field, kcl mod add works normally or does not work normally, what does kcl.mod, kcl.mod.lock, and the corresponding CLI output should look like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated accordingly. Can you please take a look?

```

This command will recursively search for the package name within all the existing kcl.mod files in the repository and load it by specifying the package name in `kcl.mod` under `dependencies`.

The package flag is optional. If not provided kpm will work normally as before and you will need to have a `kcl.mod` file in the root of the repository.

There is also an option to manually write the package flag in `kcl.mod` file. For example:

```
[dependencies]
agent = { git = "https://github.com/kcl-lang/modules.git", commit = "ee03122b5f45b09eb48694422fc99a0772f6bba8", package = "agent" }
```

This will work the same way as before only thing to note is you need to have a `kcl.mod` file in the root of the repository when running the command:

```
kcl mod add --git <url> --commit <hash>
```

The user can then run `kcl mod run` to run the code:

`kcl mod run`
Copy link
Contributor

Choose a reason for hiding this comment

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

s/kcl mod run/kcl run


This will checkout the destination directory which contains that package within the repository. You can then use the loaded dependencies in your code.

The user can also run the following commands with package in there `kcl.mod` file:

```
kcl mod metadata
```

```
kcl mod metadata --update
```

```
kcl mod metadata --vendor
```

Peefy marked this conversation as resolved.
Show resolved Hide resolved
```
kcl mod graph
```

## Design

In order to use this feature, a new field `package` will be added to the `kcl.mod` file. This field will contain the package name that the user wants to use.

Earlier the download only happens, in case of git, when there is a `kcl.mod` file in the root. Enabling this feature, will allow download of git repository even when there is no `kcl.mod` file in the root but this will only work if a package flag is passed.


# Implementation and conclusion

The idea implemented in the following PR was mentioned in https://github.com/kcl-lang/kpm/pull/335#issuecomment-2151338180.

Here are the merged PRs:

- https://github.com/kcl-lang/kpm/pull/453
- https://github.com/kcl-lang/kpm/pull/457

The changes made are tested by unit tests.