Skip to content

Commit 3aec427

Browse files
authored
Add special case for CFLAGS dir when using Python 3.7 (#703)
1 parent 52e9767 commit 3aec427

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/python/supply/supply.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,16 @@ func (s *Supplier) InstallPython() error {
284284
}
285285

286286
version := regexp.MustCompile(`\d+\.\d+`).FindString(dep.Version)
287-
if err := os.Setenv("CFLAGS", fmt.Sprintf("-I%s", filepath.Join(s.Stager.DepDir(), "python", "include", fmt.Sprintf("python%s", version)))); err != nil {
288-
return err
287+
288+
//Remove once Python 3.7 is out of support (June 2023)
289+
if version == "3.7" {
290+
if err := os.Setenv("CFLAGS", fmt.Sprintf("-I%s", filepath.Join(s.Stager.DepDir(), "python", "include", fmt.Sprintf("python%sm", version)))); err != nil {
291+
return err
292+
}
293+
} else {
294+
if err := os.Setenv("CFLAGS", fmt.Sprintf("-I%s", filepath.Join(s.Stager.DepDir(), "python", "include", fmt.Sprintf("python%s", version)))); err != nil {
295+
return err
296+
}
289297
}
290298

291299
return nil

src/python/supply/supply_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ var _ = Describe("Supply", func() {
9595
pythonInstallDir = filepath.Join(depDir, "python")
9696
Expect(os.WriteFile(filepath.Join(depDir, "runtime.txt"), []byte("\n\n\npython-3.4.2\n\n\n"), 0644)).To(Succeed())
9797

98-
versions = []string{"3.4.2"}
98+
versions = []string{"3.4.2", "3.7.13"}
9999
originalPath = os.Getenv("PATH")
100100
})
101101

@@ -116,6 +116,24 @@ var _ = Describe("Supply", func() {
116116
})
117117
})
118118

119+
//Remove once Python 3.7 is out of support (June 2023)
120+
Context("runtime.txt sets Python version 3.7", func() {
121+
BeforeEach(func() {
122+
Expect(os.RemoveAll(filepath.Join(depDir, "runtime.txt"))).To(Succeed())
123+
Expect(os.WriteFile(filepath.Join(depDir, "runtime.txt"), []byte("\n\n\npython-3.7.13\n\n\n"), 0644)).To(Succeed())
124+
})
125+
It("installs Python version 3.7", func() {
126+
mockManifest.EXPECT().AllDependencyVersions("python").Return(versions)
127+
mockInstaller.EXPECT().InstallDependency(libbuildpack.Dependency{Name: "python", Version: "3.7.13"}, pythonInstallDir)
128+
mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(pythonInstallDir, "bin"), "bin")
129+
mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(pythonInstallDir, "lib"), "lib")
130+
Expect(supplier.InstallPython()).To(Succeed())
131+
Expect(os.Getenv("PATH")).To(Equal(fmt.Sprintf("%s:%s", filepath.Join(depDir, "bin"), originalPath)))
132+
Expect(os.Getenv("PYTHONPATH")).To(Equal(depDir))
133+
Expect(os.Getenv("CFLAGS")).To(Equal(fmt.Sprintf("-I%s", filepath.Join(depDir, "python", "include", "python3.7m"))))
134+
})
135+
})
136+
119137
Context("no runtime.txt is provided", func() {
120138
BeforeEach(func() {
121139
Expect(os.RemoveAll(filepath.Join(depDir, "runtime.txt"))).To(Succeed())

0 commit comments

Comments
 (0)