From d3139266c8748890b5965b866957a900365c6f2f Mon Sep 17 00:00:00 2001 From: rht Date: Mon, 17 Dec 2018 21:04:18 +0000 Subject: [PATCH] setup_venv: Uninstall typing on Python >3.4. Otherwise this causes an error ``` AttributeError: type object 'Callable' has no attribute '_abc_registry' ``` on 3.7. While the error is specific to 3.7, it is safer to uninstall typing for all the versions that don't require a pip-provided typing library. --- docs/development/setup-advanced.md | 2 +- scripts/lib/setup_venv.py | 17 ++++++++++++++--- tools/lib/provision.py | 4 ++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/development/setup-advanced.md b/docs/development/setup-advanced.md index 022fd24682..32ac047130 100644 --- a/docs/development/setup-advanced.md +++ b/docs/development/setup-advanced.md @@ -39,7 +39,7 @@ git remote add -f upstream https://github.com/zulip/zulip.git ``` ``` -# On CentOS/RHEL, you must first install epel-release, and then python34 +# On CentOS/RHEL, you must first install epel-release, and then python36 # On Fedora, you must first install python3 # From a clone of zulip.git ./tools/provision diff --git a/scripts/lib/setup_venv.py b/scripts/lib/setup_venv.py index b183bffdab..ac1931c4a3 100644 --- a/scripts/lib/setup_venv.py +++ b/scripts/lib/setup_venv.py @@ -2,6 +2,7 @@ import os import shutil import subprocess +import sys from scripts.lib.zulip_tools import run, ENDC, WARNING, parse_lsb_release from scripts.lib.hash_reqs import expand_reqs @@ -63,9 +64,8 @@ COMMON_YUM_VENV_DEPENDENCIES = [ ] REDHAT_VENV_DEPENDENCIES = COMMON_YUM_VENV_DEPENDENCIES + [ - "python34-devel", - "python34-pip", - "python34-six", + "python36-devel", + "python36-six", "python-virtualenv", ] @@ -352,4 +352,15 @@ def do_setup_virtualenv(venv_path, requirements_file, virtualenv_args): # Might be a failure due to network connection issues. Retrying... print(WARNING + "`pip install` failed; retrying..." + ENDC) install_venv_deps(requirements_file) + + # The typing module has been included in stdlib since 3.5. + # Installing a pypi version of it has been harmless until a bug + # "AttributeError: type object 'Callable' has no attribute + # '_abc_registry'" happens in 3.7. And so just to be safe, it is + # disabled from now on for all >= 3.5 versions. + # Remove this once 3.4 is no longer supported. + at_least_35 = (sys.version_info.major == 3) and (sys.version_info.minor >= 5) + if at_least_35 and ('python2.7' not in virtualenv_args): + run(["pip", "uninstall", "-y", "typing"]) + run(["sudo", "chmod", "-R", "a+rX", venv_path]) diff --git a/tools/lib/provision.py b/tools/lib/provision.py index 104b44f063..3299cffcc5 100755 --- a/tools/lib/provision.py +++ b/tools/lib/provision.py @@ -290,6 +290,10 @@ def install_yum_deps(deps_to_install, retry=False): print("Unrecognized output. `subscription-manager` might not be available") run(["sudo", "yum", "install", "-y"] + yum_extra_flags + deps_to_install) + if vendor in ["CentOS", "RedHat"]: + # This is how a pip3 is installed to /usr/bin in CentOS/RHEL + # for python35 and later. + run(["sudo", "python36", "-m", "ensurepip"]) postgres_dir = 'pgsql-%s' % (POSTGRES_VERSION,) for cmd in ['pg_config', 'pg_isready', 'psql']: # Our tooling expects these postgres scripts to be at