This is an automated email from the ASF dual-hosted git repository.

shunping pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 980c11432a1 Clean up legacy references to apitools in GCS I/O (#39433)
980c11432a1 is described below

commit 980c11432a1f5b068f8732654a7a7af63fbd295e
Author: Jack McCluskey <[email protected]>
AuthorDate: Thu Jul 30 21:20:49 2026 -0400

    Clean up legacy references to apitools in GCS I/O (#39433)
---
 sdks/python/apache_beam/io/filesystemio.py           |  5 ++---
 sdks/python/apache_beam/io/gcp/__init__.py           | 20 --------------------
 sdks/python/apache_beam/io/gcp/gcsfilesystem_test.py |  4 +++-
 3 files changed, 5 insertions(+), 24 deletions(-)

diff --git a/sdks/python/apache_beam/io/filesystemio.py 
b/sdks/python/apache_beam/io/filesystemio.py
index 571d1f2d269..daa02e58601 100644
--- a/sdks/python/apache_beam/io/filesystemio.py
+++ b/sdks/python/apache_beam/io/filesystemio.py
@@ -284,9 +284,8 @@ class PipeStream(object):
     return self.position
 
   def seek(self, offset, whence=os.SEEK_SET):
-    # The apitools library used by the gcsio.Uploader class insists on seeking
-    # to the end of a stream to do a check before completing an upload, so we
-    # must have this no-op method here in that case.
+    # Certain upload stream implementations seek to the end of a stream to 
check
+    # length before completing an upload, so we support a no-op seek(0, 
SEEK_END).
     if whence == os.SEEK_END and offset == 0:
       return
     elif whence == os.SEEK_SET:
diff --git a/sdks/python/apache_beam/io/gcp/__init__.py 
b/sdks/python/apache_beam/io/gcp/__init__.py
index 861a39f5c75..cce3acad34a 100644
--- a/sdks/python/apache_beam/io/gcp/__init__.py
+++ b/sdks/python/apache_beam/io/gcp/__init__.py
@@ -14,23 +14,3 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-
-# Important: the MIME library in the Python 3.x standard library used by
-# apitools causes uploads containing '\r\n' to be corrupted, unless we
-# patch the BytesGenerator class to write contents verbatim.
-try:
-  # pylint: disable=wrong-import-order, wrong-import-position
-  # pylint: disable=ungrouped-imports
-  import email.generator as email_generator
-
-  from apitools.base.py import transfer
-
-  class _WrapperNamespace(object):
-    class BytesGenerator(email_generator.BytesGenerator):
-      def _write_lines(self, lines):
-        self.write(lines)
-
-  transfer.email_generator = _WrapperNamespace
-except ImportError:
-  # We may not have the GCP dependencies installed, so we pass in this case.
-  pass
diff --git a/sdks/python/apache_beam/io/gcp/gcsfilesystem_test.py 
b/sdks/python/apache_beam/io/gcp/gcsfilesystem_test.py
index 08fdd630288..0ab8c4c48f8 100644
--- a/sdks/python/apache_beam/io/gcp/gcsfilesystem_test.py
+++ b/sdks/python/apache_beam/io/gcp/gcsfilesystem_test.py
@@ -29,9 +29,11 @@ from apache_beam.io.filesystem import BeamIOError
 from apache_beam.io.filesystem import FileMetadata
 from apache_beam.options.pipeline_options import PipelineOptions
 
-# Protect against environments where apitools library is not available.
+# Protect against environments where GCP storage library is not available.
 # pylint: disable=wrong-import-order, wrong-import-position
 try:
+  from google.cloud import storage  # pylint: disable=unused-import
+
   from apache_beam.io.gcp import gcsfilesystem
 except ImportError:
   gcsfilesystem = None  # type: ignore

Reply via email to