Skip to content

Commit 38313c4

Browse files
committed
[Renaming] ComputeNixEnv -> ComputeDevboxEnv; ensurePackagesAreInstalled -> ensureProjectStateIsCurrent
1 parent 1eb5988 commit 38313c4

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

internal/impl/devbox.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func (d *Devbox) Install(ctx context.Context) error {
247247
ctx, task := trace.NewTask(ctx, "devboxInstall")
248248
defer task.End()
249249

250-
return d.ensurePackagesAreInstalled(ctx, ensure)
250+
return d.ensureProjectStateIsCurrent(ctx, ensure)
251251
}
252252

253253
func (d *Devbox) ListScripts() []string {
@@ -282,7 +282,7 @@ func (d *Devbox) NixEnv(ctx context.Context, opts devopt.NixEnvOpts) (string, er
282282
)
283283
}
284284

285-
envs, err = d.computeNixEnv(ctx, true /*usePrintDevEnvCache*/)
285+
envs, err = d.computeDevboxEnv(ctx, true /*usePrintDevEnvCache*/)
286286
} else {
287287
envs, err = d.ensurePackagesAreInstalledAndComputeEnv(ctx)
288288
}
@@ -469,7 +469,7 @@ func (d *Devbox) GenerateEnvrcFile(ctx context.Context, force bool, envFlags dev
469469
}
470470

471471
// generate all shell files to ensure we can refer to them in the .envrc script
472-
if err := d.ensurePackagesAreInstalled(ctx, ensure); err != nil {
472+
if err := d.ensureProjectStateIsCurrent(ctx, ensure); err != nil {
473473
return err
474474
}
475475

@@ -741,7 +741,7 @@ func (d *Devbox) StartProcessManager(
741741
)
742742
}
743743

744-
// computeNixEnv computes the set of environment variables that define a Devbox
744+
// computeDevboxEnv computes the set of environment variables that define a Devbox
745745
// environment. The "devbox run" and "devbox shell" commands source these
746746
// variables into a shell before executing a command or showing an interactive
747747
// prompt.
@@ -765,11 +765,10 @@ func (d *Devbox) StartProcessManager(
765765
// programs.
766766
//
767767
// Note that the shellrc.tmpl template (which sources this environment) does
768-
// some additional processing. The computeNixEnv environment won't necessarily
768+
// some additional processing. The computeDevboxEnv environment won't necessarily
769769
// represent the final "devbox run" or "devbox shell" environments.
770-
// TODO: Rename to computeDevboxEnv?
771-
func (d *Devbox) computeNixEnv(ctx context.Context, usePrintDevEnvCache bool) (map[string]string, error) {
772-
defer trace.StartRegion(ctx, "computeNixEnv").End()
770+
func (d *Devbox) computeDevboxEnv(ctx context.Context, usePrintDevEnvCache bool) (map[string]string, error) {
771+
defer trace.StartRegion(ctx, "computeDevboxEnv").End()
773772

774773
// Append variables from current env if --pure is not passed
775774
currentEnv := os.Environ()
@@ -951,20 +950,20 @@ func (d *Devbox) ensurePackagesAreInstalledAndComputeEnv(
951950
) (map[string]string, error) {
952951
defer debug.FunctionTimer().End()
953952

954-
// We need to check the lockfile status prior to ensurePackagesAreInstalled
953+
// We need to check the lockfile status prior to ensureProjectStateIsCurrent
955954
// since it will update the lockfile to be up-to-date.
956955
upToDate, err := d.lockfile.IsUpToDateAndInstalled()
957956
if err != nil {
958957
return nil, err
959958
}
960959

961-
// When ensurePackagesAreInstalled is called with ensure=true, it always
960+
// When ensureProjectStateIsCurrent is called with ensure=true, it always
962961
// returns early if the lockfile is up to date. So we don't need to check here
963-
if err := d.ensurePackagesAreInstalled(ctx, ensure); err != nil {
962+
if err := d.ensureProjectStateIsCurrent(ctx, ensure); err != nil {
964963
return nil, err
965964
}
966965

967-
return d.computeNixEnv(ctx, upToDate /*usePrintDevEnvCache*/)
966+
return d.computeDevboxEnv(ctx, upToDate /*usePrintDevEnvCache*/)
968967
}
969968

970969
func (d *Devbox) nixPrintDevEnvCachePath() string {

internal/impl/devbox_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,21 @@ func (n *testNix) PrintDevEnv(ctx context.Context, args *nix.PrintDevEnvArgs) (*
6767
}, nil
6868
}
6969

70-
func TestComputeNixEnv(t *testing.T) {
70+
func TestComputeDevboxEnv(t *testing.T) {
7171
d := devboxForTesting(t)
7272
d.nix = &testNix{}
7373
ctx := context.Background()
74-
env, err := d.computeNixEnv(ctx, false /*use cache*/)
75-
require.NoError(t, err, "computeNixEnv should not fail")
76-
assert.NotNil(t, env, "computeNixEnv should return a valid env")
74+
env, err := d.computeDevboxEnv(ctx, false /*use cache*/)
75+
require.NoError(t, err, "computeDevboxEnv should not fail")
76+
assert.NotNil(t, env, "computeDevboxEnv should return a valid env")
7777
}
7878

79-
func TestComputeNixPathIsIdempotent(t *testing.T) {
79+
func TestComputeDevboxPathIsIdempotent(t *testing.T) {
8080
devbox := devboxForTesting(t)
8181
devbox.nix = &testNix{"/tmp/my/path"}
8282
ctx := context.Background()
83-
env, err := devbox.computeNixEnv(ctx, false /*use cache*/)
84-
require.NoError(t, err, "computeNixEnv should not fail")
83+
env, err := devbox.computeDevboxEnv(ctx, false /*use cache*/)
84+
require.NoError(t, err, "computeDevboxEnv should not fail")
8585
path := env["PATH"]
8686
assert.NotEmpty(t, path, "path should not be nil")
8787

@@ -90,19 +90,19 @@ func TestComputeNixPathIsIdempotent(t *testing.T) {
9090
t.Setenv(envpath.PathStackEnv, env[envpath.PathStackEnv])
9191
t.Setenv(envpath.Key(devbox.projectDirHash()), env[envpath.Key(devbox.projectDirHash())])
9292

93-
env, err = devbox.computeNixEnv(ctx, false /*use cache*/)
94-
require.NoError(t, err, "computeNixEnv should not fail")
93+
env, err = devbox.computeDevboxEnv(ctx, false /*use cache*/)
94+
require.NoError(t, err, "computeDevboxEnv should not fail")
9595
path2 := env["PATH"]
9696

9797
assert.Equal(t, path, path2, "path should be the same")
9898
}
9999

100-
func TestComputeNixPathWhenRemoving(t *testing.T) {
100+
func TestComputeDevboxPathWhenRemoving(t *testing.T) {
101101
devbox := devboxForTesting(t)
102102
devbox.nix = &testNix{"/tmp/my/path"}
103103
ctx := context.Background()
104-
env, err := devbox.computeNixEnv(ctx, false /*use cache*/)
105-
require.NoError(t, err, "computeNixEnv should not fail")
104+
env, err := devbox.computeDevboxEnv(ctx, false /*use cache*/)
105+
require.NoError(t, err, "computeDevboxEnv should not fail")
106106
path := env["PATH"]
107107
assert.NotEmpty(t, path, "path should not be nil")
108108
assert.Contains(t, path, "/tmp/my/path", "path should contain /tmp/my/path")
@@ -113,8 +113,8 @@ func TestComputeNixPathWhenRemoving(t *testing.T) {
113113
t.Setenv(envpath.Key(devbox.projectDirHash()), env[envpath.Key(devbox.projectDirHash())])
114114

115115
devbox.nix.(*testNix).path = ""
116-
env, err = devbox.computeNixEnv(ctx, false /*use cache*/)
117-
require.NoError(t, err, "computeNixEnv should not fail")
116+
env, err = devbox.computeDevboxEnv(ctx, false /*use cache*/)
117+
require.NoError(t, err, "computeDevboxEnv should not fail")
118118
path2 := env["PATH"]
119119
assert.NotContains(t, path2, "/tmp/my/path", "path should not contain /tmp/my/path")
120120

internal/impl/packages.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ func (d *Devbox) Add(ctx context.Context, pkgsNames []string, opts devopt.AddOpt
9898
addedPackageNames = append(addedPackageNames, packageNameForConfig)
9999
}
100100

101-
// Options must be set before ensurePackagesAreInstalled. See comment in function
101+
// Options must be set before ensureProjectStateIsCurrent. See comment in function
102102
if err := d.setPackageOptions(addedPackageNames, opts); err != nil {
103103
return err
104104
}
105105

106-
if err := d.ensurePackagesAreInstalled(ctx, install); err != nil {
106+
if err := d.ensureProjectStateIsCurrent(ctx, install); err != nil {
107107
return usererr.WithUserMessage(err, "There was an error installing nix packages")
108108
}
109109

@@ -135,7 +135,7 @@ func (d *Devbox) setPackageOptions(pkgs []string, opts devopt.AddOpts) error {
135135
}
136136
}
137137

138-
// Resolving here ensures we allow insecure before running ensurePackagesAreInstalled
138+
// Resolving here ensures we allow insecure before running ensureProjectStateIsCurrent
139139
// which will call print-dev-env. Resolving does not save the lockfile, we
140140
// save at the end when everything has succeeded.
141141
if opts.AllowInsecure {
@@ -218,14 +218,14 @@ func (d *Devbox) Remove(ctx context.Context, pkgs ...string) error {
218218
}
219219

220220
// this will clean up the now-extra package from nix profile and the lockfile
221-
if err := d.ensurePackagesAreInstalled(ctx, uninstall); err != nil {
221+
if err := d.ensureProjectStateIsCurrent(ctx, uninstall); err != nil {
222222
return err
223223
}
224224

225225
return d.saveCfg()
226226
}
227227

228-
// installMode is an enum for helping with ensurePackagesAreInstalled implementation
228+
// installMode is an enum for helping with ensureProjectStateIsCurrent implementation
229229
type installMode string
230230

231231
const (
@@ -236,19 +236,18 @@ const (
236236
ensure installMode = "ensure"
237237
)
238238

239-
// ensurePackagesAreInstalled ensures:
239+
// ensureProjectStateIsCurrent ensures:
240240
// 1. Packages are installed, in nix-profile or runx.
241241
// Extraneous packages are removed (references purged, not uninstalled).
242-
// 2. Files for devbox shellenv are generated
243-
// 3. Env-vars for shellenv are computed
242+
// 2. Plugins are installed
243+
// 3. Files for devbox shellenv are generated
244244
// 4. Lockfile is synced
245245
//
246246
// The `mode` is used for:
247247
// 1. Skipping certain operations that may not apply.
248248
// 2. User messaging to explain what operations are happening, because this function may take time to execute.
249-
// TODO: Rename method since it does more than just ensure packages are installed.
250-
func (d *Devbox) ensurePackagesAreInstalled(ctx context.Context, mode installMode) error {
251-
defer trace.StartRegion(ctx, "ensurePackages").End()
249+
func (d *Devbox) ensureProjectStateIsCurrent(ctx context.Context, mode installMode) error {
250+
defer trace.StartRegion(ctx, "ensureProjectStateIsCurrent").End()
252251
defer debug.FunctionTimer().End()
253252

254253
// if mode is install or uninstall, then we need to update the nix-profile

internal/impl/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (d *Devbox) Update(ctx context.Context, opts devopt.UpdateOpts) error {
6565
}
6666
}
6767

68-
if err := d.ensurePackagesAreInstalled(ctx, update); err != nil {
68+
if err := d.ensureProjectStateIsCurrent(ctx, update); err != nil {
6969
return err
7070
}
7171

0 commit comments

Comments
 (0)