From 9874f9321b1d6bc28f299da624455c7a07832c7f Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Wed, 23 May 2018 23:00:48 -0500 Subject: index: make requests optional, but recommended --- apkkit/base/index.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/apkkit/base/index.py b/apkkit/base/index.py index ee0af9f..3976932 100644 --- a/apkkit/base/index.py +++ b/apkkit/base/index.py @@ -3,13 +3,25 @@ from io import BytesIO import logging import os -import requests import tarfile from apkkit.base.package import Package INDEX_LOGGER = logging.getLogger(__name__) +"""The logger for messages coming from this module.""" + + +try: + # logger needed. pylint: disable=wrong-import-order,wrong-import-position + import requests + HAVE_REQUESTS = True + """Determines if the `requests` module is available.""" +except ImportError: + INDEX_LOGGER.warning("You need install Requests to load indexes over " + "the network.") + HAVE_REQUESTS = False + """Determines if the `requests` module is available.""" class Index: @@ -28,9 +40,11 @@ class Index: :param str url: (Optional) The URL to download the index from. All other parameters are ignored if this is specified. + + .. note:: URL downloading requires the Requests module to be installed. """ - if url is not None: + if HAVE_REQUESTS and url is not None: self._url = url resp = requests.get(url) if resp.status_code != 200: -- cgit v1.2.3-70-g09d2