Skip to content
This repository was archived by the owner on May 14, 2023. It is now read-only.

Commit 4e0ad96

Browse files
committed
feat: Add jinja2 dependencies
1 parent fb30e64 commit 4e0ad96

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

Diff for: pkg/generate/main.go

+17-8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ var removePatterns = []glob.Glob{
6464
glob.MustCompile("**.pdb"),
6565
glob.MustCompile("**.pyc"),
6666
glob.MustCompile("**/test_*.py"),
67+
glob.MustCompile("**/*.dist-info"),
6768
}
6869

6970
var keepNixPatterns = []glob.Glob{
@@ -124,23 +125,31 @@ func downloadAndCopy(osName string, arch string, out string, keepPatterns []glob
124125

125126
extract(downloadPath, extractPath)
126127

128+
installPath := filepath.Join(extractPath, "python", "install")
129+
130+
var libPath string
131+
if osName == "windows" {
132+
libPath = filepath.Join(installPath, "Lib")
133+
} else {
134+
libPath = filepath.Join(installPath, "lib", fmt.Sprintf("python%s", pythonVersionBase))
135+
}
136+
137+
pipInstallRequirements(libPath, "requirements.txt")
138+
127139
var removes []string
128140

129141
for _, lib := range removeLibs {
130-
removes = append(removes, filepath.Join("lib", fmt.Sprintf("python%s", pythonVersionBase), lib))
131-
removes = append(removes, filepath.Join("Lib", lib))
142+
removes = append(removes, filepath.Join(libPath, lib))
132143
}
133144

134-
installPath := filepath.Join(extractPath, "python", "install")
135-
136145
err = filepath.Walk(installPath, func(path string, info fs.FileInfo, err error) error {
137146
relPath, err := filepath.Rel(installPath, path)
138147
if err != nil {
139148
log.Panic(err)
140149
}
141150
for _, p := range removePatterns {
142-
if p.Match(path) {
143-
removes = append(removes, relPath)
151+
if p.Match(relPath) {
152+
removes = append(removes, path)
144153
}
145154
}
146155
if !info.Mode().IsDir() {
@@ -152,7 +161,7 @@ func downloadAndCopy(osName string, arch string, out string, keepPatterns []glob
152161
}
153162
}
154163
if !keep {
155-
removes = append(removes, relPath)
164+
removes = append(removes, path)
156165
}
157166
}
158167
return nil
@@ -162,7 +171,7 @@ func downloadAndCopy(osName string, arch string, out string, keepPatterns []glob
162171
}
163172

164173
for _, r := range removes {
165-
_ = os.RemoveAll(filepath.Join(installPath, r))
174+
_ = os.RemoveAll(r)
166175
}
167176

168177
err = removeEmptyDirs(installPath)

Diff for: pkg/generate/pip.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"os/exec"
6+
)
7+
8+
func pipInstallRequirements(libDir string, requirementsFile string) {
9+
cmd := exec.Command("pip3", "install", "-r", requirementsFile, "-t", libDir)
10+
cmd.Stdout = os.Stdout
11+
cmd.Stderr = os.Stderr
12+
err := cmd.Run()
13+
if err != nil {
14+
panic(err)
15+
}
16+
}

Diff for: requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
jinja2==3.1.2
2+
click==8.1.3
3+
jsonpath-ng==1.5.3
4+
pyyaml==6.0

0 commit comments

Comments
 (0)