Skip to content

Commit 2712306

Browse files
authored
Remove potential leading colon from PYTHONPATH (#356)
* Remove potential leading colon from PYTHONPATH * Create `io.py` module in test directory as a regression test
1 parent 0124040 commit 2712306

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ COPY --from=build /go/pkg/mod/github.com/mwitkow/go-proto-validators@v${go_mwitk
190190
# Copy mypy
191191
COPY --from=build /opt/mypy-protobuf/ /opt/mypy-protobuf/
192192
RUN mv /opt/mypy-protobuf/bin/* /usr/local/bin/
193-
ENV PYTHONPATH="${PYTHONPATH}:/opt/mypy-protobuf/"
193+
ENV PYTHONPATH="${PYTHONPATH:+$PYTHONPATH:}/opt/mypy-protobuf/"
194194

195195
ADD all/entrypoint.sh /usr/local/bin
196196
RUN chmod +x /usr/local/bin/entrypoint.sh

all/test/all_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,17 @@ func (s *TestSuite) TestAllCases() {
688688
defer os.RemoveAll(dir)
689689
s.Require().NoError(err)
690690
err = copy.Copy(src, path.Join(dir, "all"), opt)
691+
692+
// We previously had a buggy PYTHONPATH which would search the working directory for
693+
// modules when running the Python generator.
694+
//
695+
// Let's add something that with the same name as a standard library module to the test
696+
// directory as a regression test.
697+
//
698+
// Further context: https://github.com/namely/docker-protoc/pull/356
699+
_, err = os.OpenFile(path.Join(dir, "io.py"), os.O_RDONLY|os.O_CREATE, 0666)
700+
s.Require().NoError(err)
701+
691702
argsStr := fmt.Sprintf(DockerCmd,
692703
dir,
693704
container,

0 commit comments

Comments
 (0)