Skip to content

Commit 9cea339

Browse files
mikeland73gcurtis
andauthored
[pip] Add pip support (via venv) DEV-1146 (#147)
## Summary This is stacked on #105. Please review that one first. Adds basic pip support. * Uses requirements.txt for detection. * Uses venv for shell * Uses venv + pex for build Does not yet libraries with native extensions like `pandas` but there's a plan for that. ## How was it tested? * `devbox shell`. * `devbox build` * Unit tests Co-authored-by: Greg Curtis <[email protected]>
1 parent 3a3a4fd commit 9cea339

File tree

23 files changed

+219
-34
lines changed

23 files changed

+219
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Devbox makes it easy to package your application into an OCI-compliant container
142142
Devbox currently detects the following languages/stacks:
143143

144144
- Go
145-
- Python (Poetry)
145+
- Python ([See notes](planner/languages/python/))
146146
- NodeJS
147147
- PHP
148148
- static nginx (Experimental - [see notes](planner/languages/nginx))

devbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (d *Devbox) Shell() error {
140140
return errors.WithStack(err)
141141
}
142142
nixDir := filepath.Join(d.srcDir, ".devbox/gen/shell.nix")
143-
sh, err := nix.DetectShell(nix.WithWelcomeMessage(plan.ShellWelcomeMessage))
143+
sh, err := nix.DetectShell(nix.WithPlanInitHook(plan.ShellInitHook))
144144
if err != nil {
145145
// Fall back to using a plain Nix shell.
146146
sh = &nix.Shell{}

devbox_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
func TestDevbox(t *testing.T) {
15+
t.Setenv("TMPDIR", "/tmp")
1516
testPaths, err := doublestar.FilepathGlob("./testdata/**/devbox.json")
1617
assert.NoError(t, err, "Reading testdata/ should not fail")
1718

@@ -89,7 +90,7 @@ func assertPlansMatch(t *testing.T, expected *plansdk.Plan, actual *plansdk.Plan
8990
)
9091

9192
assert.ElementsMatch(expected.Definitions, actual.Definitions, "Definitions should match")
92-
assert.Equal(expected.ShellWelcomeMessage, actual.ShellWelcomeMessage, "ShellWelcomeMessage should match")
93+
assert.Equal(expected.ShellInitHook, actual.ShellInitHook, "ShellInitHook should match")
9394
if expected.GeneratedFiles != nil {
9495
assert.Equal(expected.GeneratedFiles, actual.GeneratedFiles, "GeneratedFiles should match")
9596
}

nix/shell.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ type Shell struct {
3737
name name
3838
binPath string
3939
userShellrcPath string
40+
planInitHook string
4041

4142
// UserInitHook contains commands that will run at shell startup.
42-
UserInitHook string
43-
welcomeMessage string
43+
UserInitHook string
4444
}
4545

4646
type ShellOption func(*Shell)
@@ -91,9 +91,9 @@ func DetectShell(opts ...ShellOption) (*Shell, error) {
9191
return sh, nil
9292
}
9393

94-
func WithWelcomeMessage(message string) ShellOption {
94+
func WithPlanInitHook(hook string) ShellOption {
9595
return func(s *Shell) {
96-
s.welcomeMessage = message
96+
s.planInitHook = hook
9797
}
9898
}
9999

@@ -249,12 +249,12 @@ func (s *Shell) writeDevboxShellrc() (path string, err error) {
249249
OriginalInit string
250250
OriginalInitPath string
251251
UserHook string
252-
WelcomeMessage string
252+
PlanInitHook string
253253
}{
254254
OriginalInit: string(bytes.TrimSpace(userShellrc)),
255255
OriginalInitPath: filepath.Clean(s.userShellrcPath),
256256
UserHook: strings.TrimSpace(s.UserInitHook),
257-
WelcomeMessage: strings.TrimSpace(s.welcomeMessage),
257+
PlanInitHook: strings.TrimSpace(s.planInitHook),
258258
})
259259
if err != nil {
260260
return "", fmt.Errorf("execute shellrc template: %v", err)

nix/shell_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestWriteDevboxShellrc(t *testing.T) {
5151
s := &Shell{
5252
userShellrcPath: test.shellrcPath,
5353
UserInitHook: test.hook,
54-
welcomeMessage: "Welcome to the devbox!",
54+
planInitHook: `echo "Welcome to the devbox!"`,
5555
}
5656
gotPath, err := s.writeDevboxShellrc()
5757
if err != nil {

nix/shellrc.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ export PS1="(devbox) $PS1"
7575

7676
{{- end }}
7777

78-
# Begin Shell Welcome Message
78+
# Begin Plan Init Hook
7979

80-
{{- if .WelcomeMessage }}
80+
{{- if .PlanInitHook }}
8181

82-
echo "{{ .WelcomeMessage }}"
82+
{{ .PlanInitHook }}
8383

8484
{{- end }}
8585

86-
# End Shell Welcome Message
86+
# End Plan Init Hook

nix/testdata/shellrc/basic/shellrc.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ echo "Hello from a devbox shell hook!"
8585

8686
# End Devbox User Hook
8787

88-
# Begin Shell Welcome Message
88+
# Begin Plan Init Hook
8989

9090
echo "Welcome to the devbox!"
9191

92-
# End Shell Welcome Message
92+
# End Plan Init Hook

nix/testdata/shellrc/nohook/shellrc.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export PS1="(devbox) $PS1"
7979

8080
# End Devbox Post-init Hook
8181

82-
# Begin Shell Welcome Message
82+
# Begin Plan Init Hook
8383

8484
echo "Welcome to the devbox!"
8585

86-
# End Shell Welcome Message
86+
# End Plan Init Hook

nix/testdata/shellrc/noshellrc/shellrc.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ echo "Hello from a devbox shell hook!"
4343

4444
# End Devbox User Hook
4545

46-
# Begin Shell Welcome Message
46+
# Begin Plan Init Hook
4747

4848
echo "Welcome to the devbox!"
4949

50-
# End Shell Welcome Message
50+
# End Plan Init Hook

planner/languages/nginx/nginx_planner.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ func (p *Planner) IsRelevant(srcDir string) bool {
2929

3030
func (p *Planner) GetPlan(srcDir string) *plansdk.Plan {
3131
return &plansdk.Plan{
32-
ShellWelcomeMessage: fmt.Sprintf(welcomeMessage, p.shellConfig(srcDir)),
32+
ShellInitHook: plansdk.WelcomeMessage(
33+
fmt.Sprintf(welcomeMessage, p.shellConfig(srcDir)),
34+
),
3335
DevPackages: []string{
3436
"nginx",
3537
"shell-nginx",

0 commit comments

Comments
 (0)