Merge pull request #99 from jsonnet-bundler/single

feat(install): skip dependencies
This commit is contained in:
Frederic Branczyk 2020-04-23 07:41:09 +02:00 committed by GitHub
commit ccd60c13eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 5 deletions

View file

@ -100,7 +100,7 @@ Commands:
init init
Initialize a new empty jsonnetfile Initialize a new empty jsonnetfile
install [<uris>...] install [<flags>] [<uris>...]
Install new dependencies. Existing ones are silently skipped Install new dependencies. Existing ones are silently skipped
update [<uris>...] update [<uris>...]

View file

@ -30,7 +30,7 @@ import (
"github.com/jsonnet-bundler/jsonnet-bundler/spec/v1/deps" "github.com/jsonnet-bundler/jsonnet-bundler/spec/v1/deps"
) )
func installCommand(dir, jsonnetHome string, uris []string) int { func installCommand(dir, jsonnetHome string, uris []string, single bool) int {
if dir == "" { if dir == "" {
dir = "." dir = "."
} }
@ -59,6 +59,10 @@ func installCommand(dir, jsonnetHome string, uris []string) int {
kingpin.Fatalf("Unable to parse package URI `%s`", u) kingpin.Fatalf("Unable to parse package URI `%s`", u)
} }
if single {
d.Single = true
}
if !depEqual(jsonnetFile.Dependencies[d.Name()], *d) { if !depEqual(jsonnetFile.Dependencies[d.Name()], *d) {
// the dep passed on the cli is different from the jsonnetFile // the dep passed on the cli is different from the jsonnetFile
jsonnetFile.Dependencies[d.Name()] = *d jsonnetFile.Dependencies[d.Name()] = *d

View file

@ -49,6 +49,7 @@ func testInstallCommandWithJsonnetHome(t *testing.T, jsonnetHome string) {
ExpectedCode int ExpectedCode int
ExpectedJsonnetFile []byte ExpectedJsonnetFile []byte
ExpectedJsonnetLockFile []byte ExpectedJsonnetLockFile []byte
single bool
}{ }{
{ {
Name: "NoURLs", Name: "NoURLs",
@ -69,6 +70,14 @@ func testInstallCommandWithJsonnetHome(t *testing.T, jsonnetHome string) {
ExpectedJsonnetFile: []byte(`{"version": 1, "dependencies": [{"source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}], "legacyImports": true}`), ExpectedJsonnetFile: []byte(`{"version": 1, "dependencies": [{"source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}], "legacyImports": true}`),
ExpectedJsonnetLockFile: []byte(`{"version": 1, "dependencies": [{"source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}], "legacyImports": false}`), ExpectedJsonnetLockFile: []byte(`{"version": 1, "dependencies": [{"source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}], "legacyImports": false}`),
}, },
{
Name: "single",
URIs: []string{"github.com/grafana/loki/production/ksonnet/loki@bd4d516262c107a0bde7a962fa2b1e567a2c21e5"},
ExpectedCode: 0,
ExpectedJsonnetFile: []byte(`{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/loki","subdir":"production/ksonnet/loki"}},"version":"bd4d516262c107a0bde7a962fa2b1e567a2c21e5","single":true}],"legacyImports":true}`),
ExpectedJsonnetLockFile: []byte(`{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/loki","subdir":"production/ksonnet/loki"}},"version":"bd4d516262c107a0bde7a962fa2b1e567a2c21e5","sum":"ExovUKXmZ4KwJAv/q8ZwNW9BdIZlrxmoGrne7aR64wo=","single":true}],"legacyImports":false}`),
single: true,
},
} }
localDependency := "jsonnet/foobar" localDependency := "jsonnet/foobar"
@ -92,7 +101,7 @@ func testInstallCommandWithJsonnetHome(t *testing.T, jsonnetHome string) {
jsonnetFileContent(t, jsonnetfile.File, []byte(initContents)) jsonnetFileContent(t, jsonnetfile.File, []byte(initContents))
// install something, check it writes only if required, etc. // install something, check it writes only if required, etc.
installCommand("", jsonnetHome, tc.URIs) installCommand("", jsonnetHome, tc.URIs, tc.single)
jsonnetFileContent(t, jsonnetfile.File, tc.ExpectedJsonnetFile) jsonnetFileContent(t, jsonnetfile.File, tc.ExpectedJsonnetFile)
if tc.ExpectedJsonnetLockFile != nil { if tc.ExpectedJsonnetLockFile != nil {
jsonnetFileContent(t, jsonnetfile.LockFile, tc.ExpectedJsonnetLockFile) jsonnetFileContent(t, jsonnetfile.LockFile, tc.ExpectedJsonnetLockFile)

View file

@ -54,6 +54,7 @@ func Main() int {
installCmd := a.Command(installActionName, "Install new dependencies. Existing ones are silently skipped") installCmd := a.Command(installActionName, "Install new dependencies. Existing ones are silently skipped")
installCmdURIs := installCmd.Arg("uris", "URIs to packages to install, URLs or file paths").Strings() installCmdURIs := installCmd.Arg("uris", "URIs to packages to install, URLs or file paths").Strings()
installCmdSingle := installCmd.Flag("single", "install package without dependencies").Short('1').Bool()
updateCmd := a.Command(updateActionName, "Update all or specific dependencies.") updateCmd := a.Command(updateActionName, "Update all or specific dependencies.")
updateCmdURIs := updateCmd.Arg("uris", "URIs to packages to update, URLs or file paths").Strings() updateCmdURIs := updateCmd.Arg("uris", "URIs to packages to update, URLs or file paths").Strings()
@ -78,13 +79,13 @@ func Main() int {
case initCmd.FullCommand(): case initCmd.FullCommand():
return initCommand(workdir) return initCommand(workdir)
case installCmd.FullCommand(): case installCmd.FullCommand():
return installCommand(workdir, cfg.JsonnetHome, *installCmdURIs) return installCommand(workdir, cfg.JsonnetHome, *installCmdURIs, *installCmdSingle)
case updateCmd.FullCommand(): case updateCmd.FullCommand():
return updateCommand(workdir, cfg.JsonnetHome, *updateCmdURIs) return updateCommand(workdir, cfg.JsonnetHome, *updateCmdURIs)
case rewriteCmd.FullCommand(): case rewriteCmd.FullCommand():
return rewriteCommand(workdir, cfg.JsonnetHome) return rewriteCommand(workdir, cfg.JsonnetHome)
default: default:
installCommand(workdir, cfg.JsonnetHome, []string{}) installCommand(workdir, cfg.JsonnetHome, []string{}, false)
} }
return 0 return 0

View file

@ -243,6 +243,11 @@ func ensure(direct map[string]deps.Dependency, vendorDir string, locks map[strin
} }
for _, d := range deps { for _, d := range deps {
if d.Single {
// skip dependencies that explicitely don't want nested ones installed
continue
}
f, err := jsonnetfile.Load(filepath.Join(vendorDir, d.Name(), jsonnetfile.File)) f, err := jsonnetfile.Load(filepath.Join(vendorDir, d.Name(), jsonnetfile.File))
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {

View file

@ -22,6 +22,7 @@ type Dependency struct {
Source Source `json:"source"` Source Source `json:"source"`
Version string `json:"version"` Version string `json:"version"`
Sum string `json:"sum,omitempty"` Sum string `json:"sum,omitempty"`
Single bool `json:"single,omitempty"`
// older schema used to have `name`. We still need that data for // older schema used to have `name`. We still need that data for
// `LegacyName` // `LegacyName`