Skip to content

Commit

Permalink
Uses PYTHONPYCACHEPREFIX to control where __pycache__ goes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Moran authored and robdimsdale committed May 9, 2022
1 parent fb81f17 commit 22d754f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ func Build(dependencies DependencyManager, sbomGenerator SBOMGenerator, logger s
DepKey: dependency.SHA256,
}

cpythonLayer.SharedEnv.Override("PYTHONPATH", cpythonLayer.Path)
cpythonLayer.SharedEnv.Default("PYTHONPATH", cpythonLayer.Path)
cpythonLayer.SharedEnv.Default("PYTHONPYCACHEPREFIX", "$HOME/.pycache")

logger.Break()
logger.Process("Configuring environment")
Expand Down
3 changes: 2 additions & 1 deletion build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
Expect(layer.Path).To(Equal(filepath.Join(layersDir, "cpython")))

Expect(layer.SharedEnv).To(Equal(packit.Environment{
"PYTHONPATH.override": filepath.Join(layersDir, "cpython"),
"PYTHONPATH.default": filepath.Join(layersDir, "cpython"),
"PYTHONPYCACHEPREFIX.default": "$HOME/.pycache",
}))
Expect(layer.BuildEnv).To(BeEmpty())
Expect(layer.LaunchEnv).To(BeEmpty())
Expand Down
3 changes: 2 additions & 1 deletion integration/buildpack_yml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func testBuildpackYAML(t *testing.T, context spec.G, it spec.S) {
))
Expect(logs).To(ContainLines(
" Configuring environment",
MatchRegexp(fmt.Sprintf(` PYTHONPATH -> "/layers/%s/cpython"`, strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"))),
fmt.Sprintf(` PYTHONPATH -> "/layers/%s/cpython"`, strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
` PYTHONPYCACHEPREFIX -> "$HOME/.pycache"`,
))
})
})
Expand Down
6 changes: 4 additions & 2 deletions integration/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {
))
Expect(logs).To(ContainLines(
" Configuring environment",
MatchRegexp(fmt.Sprintf(` PYTHONPATH -> "/layers/%s/cpython"`, strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"))),
fmt.Sprintf(` PYTHONPATH -> "/layers/%s/cpython"`, strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
` PYTHONPYCACHEPREFIX -> "$HOME/.pycache"`,
))
})

Expand Down Expand Up @@ -217,7 +218,8 @@ func testDefault(t *testing.T, context spec.G, it spec.S) {

Expect(logs).To(ContainLines(
" Configuring environment",
MatchRegexp(fmt.Sprintf(` PYTHONPATH -> "/layers/%s/cpython"`, strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_"))),
fmt.Sprintf(` PYTHONPATH -> "/layers/%s/cpython"`, strings.ReplaceAll(buildpackInfo.Buildpack.ID, "/", "_")),
` PYTHONPYCACHEPREFIX -> "$HOME/.pycache"`,
))
})
})
Expand Down

0 comments on commit 22d754f

Please sign in to comment.