You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by tv...@apache.org on 2022/07/26 17:00:49 UTC

[beam] 01/01: Revert "Replace distutils with supported modules. (#21968)"

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

tvalentyn pushed a commit to branch revert-21968-replace-distutils
in repository https://gitbox.apache.org/repos/asf/beam.git

commit 8ac2214a555e90a0c2343e34c7a38e3b71b25283
Author: tvalentyn <tv...@users.noreply.github.com>
AuthorDate: Tue Jul 26 10:00:43 2022 -0700

    Revert "Replace distutils with supported modules. (#21968)"
    
    This reverts commit 485f9afe675a694857441dadd44e395f682dbc1f.
---
 .github/workflows/build_wheels.yml                           |  2 +-
 .../apache/beam/sdk/extensions/python/bootstrap_beam_venv.py |  6 +++---
 sdks/python/apache_beam/examples/complete/juliaset/setup.py  |  2 +-
 sdks/python/apache_beam/runners/portability/stager.py        |  4 ++--
 sdks/python/container/Dockerfile                             |  2 --
 sdks/python/setup.py                                         | 12 ++++--------
 .../en/documentation/sdks/python-pipeline-dependencies.md    |  2 +-
 7 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml
index 520b97bcd9f..f2066b14e18 100644
--- a/.github/workflows/build_wheels.yml
+++ b/.github/workflows/build_wheels.yml
@@ -240,7 +240,7 @@ jobs:
       working-directory: apache-beam-source
       env:
         CIBW_BUILD: ${{ matrix.os_python.python }}
-        CIBW_BEFORE_BUILD: pip install cython && pip install --upgrade setuptools
+        CIBW_BEFORE_BUILD: pip install cython
       run: cibuildwheel --print-build-identifiers && cibuildwheel --output-dir wheelhouse
       shell: bash
     - name: install sha512sum on MacOS
diff --git a/sdks/java/extensions/python/src/main/resources/org/apache/beam/sdk/extensions/python/bootstrap_beam_venv.py b/sdks/java/extensions/python/src/main/resources/org/apache/beam/sdk/extensions/python/bootstrap_beam_venv.py
index cff15a97aac..cb5870adb66 100644
--- a/sdks/java/extensions/python/src/main/resources/org/apache/beam/sdk/extensions/python/bootstrap_beam_venv.py
+++ b/sdks/java/extensions/python/src/main/resources/org/apache/beam/sdk/extensions/python/bootstrap_beam_venv.py
@@ -24,13 +24,13 @@ suitable python executable.
 """
 
 import argparse
+import distutils.version
 import hashlib
 import json
 import os
 import shutil
 import subprocess
 import sys
-from pkg_resources import parse_version
 
 
 def main():
@@ -66,9 +66,9 @@ def main():
 
         def maybe_strict_version(s):
             try:
-                return parse_version(s)
+                return distutils.version.StrictVersion(s)
             except:
-                return parse_version('0.0')
+                return distutils.version.StrictVersion('0.0')
 
         beam_version = max(info['releases'], key=maybe_strict_version)
         beam_package = 'apache_beam[gcp,aws,asure,dataframe]==' + beam_version
diff --git a/sdks/python/apache_beam/examples/complete/juliaset/setup.py b/sdks/python/apache_beam/examples/complete/juliaset/setup.py
index b65eb15a3f2..c4dcbe12113 100644
--- a/sdks/python/apache_beam/examples/complete/juliaset/setup.py
+++ b/sdks/python/apache_beam/examples/complete/juliaset/setup.py
@@ -28,9 +28,9 @@ when running the workflow for remote execution.
 # pytype: skip-file
 
 import subprocess
+from distutils.command.build import build as _build  # type: ignore
 
 import setuptools
-from setuptools.command.build import build as _build  # type: ignore
 
 
 # This class handles the pip install mechanism.
diff --git a/sdks/python/apache_beam/runners/portability/stager.py b/sdks/python/apache_beam/runners/portability/stager.py
index e06c71c917d..743beb490ed 100644
--- a/sdks/python/apache_beam/runners/portability/stager.py
+++ b/sdks/python/apache_beam/runners/portability/stager.py
@@ -54,6 +54,7 @@ import os
 import shutil
 import sys
 import tempfile
+from distutils.version import StrictVersion
 from typing import Callable
 from typing import List
 from typing import Optional
@@ -61,7 +62,6 @@ from typing import Tuple
 from urllib.parse import urlparse
 
 import pkg_resources
-from pkg_resources import parse_version
 
 from apache_beam.internal import pickler
 from apache_beam.internal.http_client import get_new_http
@@ -698,7 +698,7 @@ class Stager(object):
     # addressed, download wheel based on glibc version in Beam's Python
     # Base image
     pip_version = pkg_resources.get_distribution('pip').version
-    if parse_version(pip_version) >= parse_version('19.3'):
+    if StrictVersion(pip_version) >= StrictVersion('19.3'):
       return 'manylinux2014_x86_64'
     else:
       return 'manylinux2010_x86_64'
diff --git a/sdks/python/container/Dockerfile b/sdks/python/container/Dockerfile
index a301db74ee0..b40eac647b4 100644
--- a/sdks/python/container/Dockerfile
+++ b/sdks/python/container/Dockerfile
@@ -48,8 +48,6 @@ RUN \
     rm -rf /root/.cache/pip && \
     rm -rf /tmp/base_image_requirements.txt
 
-RUN pip install --upgrade pip setuptools
-
 # Install Google Cloud SDK.
 ENV CLOUDSDK_CORE_DISABLE_PROMPTS yes
 ENV PATH $PATH:/usr/local/gcloud/google-cloud-sdk/bin
diff --git a/sdks/python/setup.py b/sdks/python/setup.py
index 56d2573620a..ef8f73a0477 100644
--- a/sdks/python/setup.py
+++ b/sdks/python/setup.py
@@ -20,6 +20,8 @@
 import os
 import sys
 import warnings
+from distutils.errors import DistutilsError
+from distutils.version import StrictVersion
 from pathlib import Path
 
 # Pylint and isort disagree here.
@@ -28,15 +30,9 @@ import setuptools
 from pkg_resources import DistributionNotFound
 from pkg_resources import get_distribution
 from pkg_resources import normalize_path
-from pkg_resources import parse_version
 from pkg_resources import to_filename
 from setuptools import Command
 
-# It is recommended to import setuptools prior to importing distutils to avoid
-# using legacy behavior from distutils.
-# https://setuptools.readthedocs.io/en/latest/history.html#v48-0-0
-from distutils.errors import DistutilsError # pylint: disable=wrong-import-order
-
 
 class mypy(Command):
   user_options = []
@@ -96,7 +92,7 @@ different technologies and user communities.
 
 REQUIRED_PIP_VERSION = '7.0.0'
 _PIP_VERSION = get_distribution('pip').version
-if parse_version(_PIP_VERSION) < parse_version(REQUIRED_PIP_VERSION):
+if StrictVersion(_PIP_VERSION) < StrictVersion(REQUIRED_PIP_VERSION):
   warnings.warn(
       "You are using version {0} of pip. " \
       "However, version {1} is recommended.".format(
@@ -107,7 +103,7 @@ if parse_version(_PIP_VERSION) < parse_version(REQUIRED_PIP_VERSION):
 REQUIRED_CYTHON_VERSION = '0.28.1'
 try:
   _CYTHON_VERSION = get_distribution('cython').version
-  if parse_version(_CYTHON_VERSION) < parse_version(REQUIRED_CYTHON_VERSION):
+  if StrictVersion(_CYTHON_VERSION) < StrictVersion(REQUIRED_CYTHON_VERSION):
     warnings.warn(
         "You are using version {0} of cython. " \
         "However, version {1} is recommended.".format(
diff --git a/website/www/site/content/en/documentation/sdks/python-pipeline-dependencies.md b/website/www/site/content/en/documentation/sdks/python-pipeline-dependencies.md
index bf2e44e5586..ca91194c533 100644
--- a/website/www/site/content/en/documentation/sdks/python-pipeline-dependencies.md
+++ b/website/www/site/content/en/documentation/sdks/python-pipeline-dependencies.md
@@ -77,7 +77,7 @@ If your pipeline uses packages that are not available publicly (e.g. packages th
 
         python setup.py sdist
 
-   See the [sdist documentation](https://docs.python.org/3/distutils/sourcedist.html) for more details on this command.
+   See the [sdist documentation](https://docs.python.org/2/distutils/sourcedist.html) for more details on this command.
 
 ## Multiple File Dependencies