Skip to content

Conversation

@floriaanpost
Copy link

On windows, when pip installing dependencies, the paths in the files.json file are stored with backslashes, for example:
"_distutils_hack\\__init__.py". This causes issues when copying the embedded filesystem to the temp directory. It is not allowed to open an embedded file using a "Windows path", this for example: fs.ReadFile(embedFs, "_distutils_hack\\__init__.py").

A minimal example to reproduce the issue:

generate/main.go

package main

import (
	"log"
	"os"
	"strings"

	"github.com/kluctl/go-embed-python/pip"
)

const deps = `
setuptools==75.8.0
`

func main() {
	platforms := map[string][]string{
		"darwin-arm64":  {"macosx_11_0_arm64", "macosx_12_0_arm64"}, // No problems here
		"windows-amd64": {"win_amd64"},                              // Here the backslashes appear in files.json                                               
	}
	reqs := tempReqs(deps)

	for goPlatform, pipPlatforms := range platforms {
		s := strings.Split(goPlatform, "-")
		goOs, goArch := s[0], s[1]
		err := pip.CreateEmbeddedPipPackages(reqs, goOs, goArch, pipPlatforms, "data")
		if err != nil {
			log.Fatal(err)
		}
	}
}

func tempReqs(data string) string {
	f, err := os.CreateTemp(os.TempDir(), "*-requirements.txt")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	if _, err := f.Write([]byte(data)); err != nil {
		log.Fatal(err)
	}

	return f.Name()
}

main.go

package main

import (
	"log"

	"github.com/kluctl/go-embed-python/embed_util"
	"gitlab.com/floriaanpost/go-embed-bug-reproduce/data"
)

//go:generate go run generate/main.go

func main() {
	_, err := embed_util.NewEmbeddedFiles(data.Data, "testdeps")
	if err != nil {
		log.Fatal(err)
	}
}

Then init, generate and run:

go mod init github.com/floriaanpost/go-embed-bug-reproduce
go mod tidy
go generate
go run main.go

@floriaanpost
Copy link
Author

I just saw there is already a PR open for the same issue (#50). I think this fix is slightly better though since it makes sure the files.json is consistent across Windows/Linux/Mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants