Skip to content

Commit

Permalink
Delete the sample file that gets created on uv init
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Sep 27, 2024
1 parent 2c1176c commit f734b16
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/backends/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package python
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -776,13 +777,25 @@ func makePythonUvBackend() api.LanguageBackend {
defer span.Finish()
// Initalize the specfile if it doesnt exist
if !util.Exists("pyproject.toml") {
// uv (currently?) creates a "hello.py" on uv init. Ensure it gets deleted before control returns to the user.
sampleFileName := "hello.py"
if _, err := os.Stat(sampleFileName); errors.Is(err, os.ErrNotExist) {
// Turns out it didn't exist after all!
sampleFileName = ""
}

cmd := []string{"uv", "init", "--no-progress", "--no-readme", "--no-pin-python"}

if projectName != "" {
cmd = append(cmd, "--name", projectName)
}

util.RunCmd(cmd)
if sampleFileName != "" {
if _, err := os.Stat(sampleFileName); errors.Is(err, os.ErrNotExist) {
os.Remove(sampleFileName)
}
}
}

cmd := []string{"uv", "add"}
Expand Down

0 comments on commit f734b16

Please sign in to comment.