From 271230654708f3398159645fd1436e7bdfb1b3e5 Mon Sep 17 00:00:00 2001 From: Alex Cameron Date: Sat, 17 Dec 2022 00:34:48 +1100 Subject: [PATCH] Remove potential leading colon from PYTHONPATH (#356) * Remove potential leading colon from PYTHONPATH * Create `io.py` module in test directory as a regression test --- Dockerfile | 2 +- all/test/all_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 047c1ac9..bef68d00 100644 --- a/Dockerfile +++ b/Dockerfile @@ -190,7 +190,7 @@ COPY --from=build /go/pkg/mod/github.com/mwitkow/go-proto-validators@v${go_mwitk # Copy mypy COPY --from=build /opt/mypy-protobuf/ /opt/mypy-protobuf/ RUN mv /opt/mypy-protobuf/bin/* /usr/local/bin/ -ENV PYTHONPATH="${PYTHONPATH}:/opt/mypy-protobuf/" +ENV PYTHONPATH="${PYTHONPATH:+$PYTHONPATH:}/opt/mypy-protobuf/" ADD all/entrypoint.sh /usr/local/bin RUN chmod +x /usr/local/bin/entrypoint.sh diff --git a/all/test/all_test.go b/all/test/all_test.go index 11212b2f..a3fcce3a 100644 --- a/all/test/all_test.go +++ b/all/test/all_test.go @@ -688,6 +688,17 @@ func (s *TestSuite) TestAllCases() { defer os.RemoveAll(dir) s.Require().NoError(err) err = copy.Copy(src, path.Join(dir, "all"), opt) + + // We previously had a buggy PYTHONPATH which would search the working directory for + // modules when running the Python generator. + // + // Let's add something that with the same name as a standard library module to the test + // directory as a regression test. + // + // Further context: https://github.com/namely/docker-protoc/pull/356 + _, err = os.OpenFile(path.Join(dir, "io.py"), os.O_RDONLY|os.O_CREATE, 0666) + s.Require().NoError(err) + argsStr := fmt.Sprintf(DockerCmd, dir, container,