From 743e2fce071bd2f5794fe071a78a32885350e15c Mon Sep 17 00:00:00 2001 From: Jelle Besseling Date: Sun, 2 Feb 2020 21:56:25 +0100 Subject: [PATCH] Add --with-upstream-urllib3 option to remove vendored version (#1725) Co-authored-by: Noam Meltzer --- setup.py | 12 +++++++++++- telegram/utils/request.py | 17 ++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 0381bf4ef..63e0468d2 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,8 @@ import codecs import os +import sys + from setuptools import setup, find_packages @@ -18,6 +20,14 @@ def requirements(): packages = find_packages(exclude=['tests*']) +requirements = requirements() + +# Allow for a package install to not use the vendored urllib3 +UPSTREAM_URLLIB3_FLAG = '--with-upstream-urllib3' +if UPSTREAM_URLLIB3_FLAG in sys.argv: + sys.argv.remove(UPSTREAM_URLLIB3_FLAG) + requirements.append('urllib3 >= 1.19.1') + packages = [x for x in packages if not x.startswith('telegram.vendor.ptb_urllib3')] with codecs.open('README.rst', 'r', 'utf-8') as fd: fn = os.path.join('telegram', 'version.py') @@ -35,7 +45,7 @@ with codecs.open('README.rst', 'r', 'utf-8') as fd: description="We have made you a wrapper you can't refuse", long_description=fd.read(), packages=packages, - install_requires=requirements(), + install_requires=requirements, extras_require={ 'json': 'ujson', 'socks': 'PySocks' diff --git a/telegram/utils/request.py b/telegram/utils/request.py index ca3a7731e..4c9a86dcc 100644 --- a/telegram/utils/request.py +++ b/telegram/utils/request.py @@ -38,9 +38,20 @@ try: from telegram.vendor.ptb_urllib3.urllib3.util.timeout import Timeout from telegram.vendor.ptb_urllib3.urllib3.fields import RequestField except ImportError: # pragma: no cover - warnings.warn("python-telegram-bot wasn't properly installed. Please refer to README.rst on " - "how to properly install.") - raise + try: + import urllib3 + import urllib3.contrib.appengine as appengine + from urllib3.connection import HTTPConnection + from urllib3.util.timeout import Timeout + from urllib3.fields import RequestField + warnings.warn('python-telegram-bot is using upstream urllib3. This is allowed but not ' + 'supported by python-telegram-bot maintainers.') + except ImportError: + warnings.warn( + "python-telegram-bot wasn't properly installed. Please refer to README.rst on " + "how to properly install.") + raise + from telegram import (InputFile, TelegramError, InputMedia) from telegram.error import (Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated,