From 3295552f595b312786c9b0db020a29afaea5a9a7 Mon Sep 17 00:00:00 2001 From: Kousuke Saruta Date: Wed, 16 Aug 2023 06:44:32 +0900 Subject: [PATCH 1/2] AVRO-3832: [Python] Make Python test work with Docker. --- build.sh | 2 +- lang/py/avro/test/gen_interop_data.py | 1 + share/docker/Dockerfile | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 0bd1e1880c4..09b02f8da06 100755 --- a/build.sh +++ b/build.sh @@ -341,7 +341,7 @@ do docker-test) tar -cf- share/docker/Dockerfile $DOCKER_EXTRA_CONTEXT | - docker build -t avro-test -f share/docker/Dockerfile - + DOCKER_BUILDKIT=1 docker build -t avro-test -f share/docker/Dockerfile - docker run --rm -v "${PWD}:/avro${DOCKER_MOUNT_FLAG}" --env "JAVA=${JAVA:-8}" avro-test /avro/share/docker/run-tests.sh ;; diff --git a/lang/py/avro/test/gen_interop_data.py b/lang/py/avro/test/gen_interop_data.py index 1993b012826..80d0bb976c8 100644 --- a/lang/py/avro/test/gen_interop_data.py +++ b/lang/py/avro/test/gen_interop_data.py @@ -73,6 +73,7 @@ def generate(schema_file: TextIO, output_path: IO) -> None: continue base, ext = os.path.splitext(output_path.name) Path(f"{base}_{codec}{ext}").write_bytes(data) + output_path.close() def _parse_args() -> argparse.Namespace: diff --git a/share/docker/Dockerfile b/share/docker/Dockerfile index 2a1cf2b46c2..51e91eab8dd 100644 --- a/share/docker/Dockerfile +++ b/share/docker/Dockerfile @@ -67,7 +67,9 @@ RUN apt-get -qqy update \ python3-wheel \ python3.10 \ python3.11 \ + python3.11-dev \ python3.7 \ + python3.7-distutils \ python3.8 \ python3.9 \ source-highlight \ From 9024ed0945ee6e0c01c8d38866f2becb3f24f30f Mon Sep 17 00:00:00 2001 From: Kousuke Saruta Date: Thu, 17 Aug 2023 11:17:40 +0900 Subject: [PATCH 2/2] Use contextlib.closing. --- lang/py/avro/test/gen_interop_data.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lang/py/avro/test/gen_interop_data.py b/lang/py/avro/test/gen_interop_data.py index 80d0bb976c8..1bde7ff8764 100644 --- a/lang/py/avro/test/gen_interop_data.py +++ b/lang/py/avro/test/gen_interop_data.py @@ -23,6 +23,7 @@ import io import json import os +from contextlib import closing from pathlib import Path from typing import IO, TextIO @@ -73,7 +74,6 @@ def generate(schema_file: TextIO, output_path: IO) -> None: continue base, ext = os.path.splitext(output_path.name) Path(f"{base}_{codec}{ext}").write_bytes(data) - output_path.close() def _parse_args() -> argparse.Namespace: @@ -94,7 +94,8 @@ def _parse_args() -> argparse.Namespace: def main() -> int: args = _parse_args() - generate(args.schema_path, args.output_path) + with closing(args.output_path) as op: + generate(args.schema_path, op) return 0