From 2e2597f77d634bdcf826f9ff14ccff6831786601 Mon Sep 17 00:00:00 2001 From: Chris B Date: Sun, 22 Dec 2019 07:03:49 +0000 Subject: [PATCH] Packaging fix: a recent commit made requests and beautifulsoup4 optional dependencies, but did not also make them optional imports. --- nbsmoke/verify.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/nbsmoke/verify.py b/nbsmoke/verify.py index 001dafe..77f5724 100644 --- a/nbsmoke/verify.py +++ b/nbsmoke/verify.py @@ -17,6 +17,18 @@ class VerifyNb(pytest.Item): def runtest(self): + + ################################################### + # quick hacks to handle missing optional modules + _missing = [] + if BeautifulSoup is None: + _missing.append(" * BeautifulSoup not available - please install beautifulsoup4") + if requests is None: + _missing.append(" * requests not available - please install requests") + if _missing: + raise Exception("nbsmoke verify failed to execute because of missing modules:\n"+"\n".join(_missing)) + ################################################### + filename = self.name bad_modules = check_modules(filename) @@ -31,6 +43,17 @@ def runtest(self): warnings.warn("%s:\n***** invalid modules: %s\n\n***** bad links: %s\n\n***** bad images: %s\n\n"%(filename,bad_modules,bad_links,bad_images) + "-"*20) +try: + import requests, requests.exceptions +except: + requests = None + +try: + from bs4 import BeautifulSoup +except: + # TODO: capture or log the error + BeautifulSoup = None + ################################################### ################################################### # rest of this file is quickly copied in code from datashader @@ -42,10 +65,6 @@ def runtest(self): # https://www.earthsystemcog.org/projects/esmf/regridding is a bad # link). - -import requests, requests.exceptions -from bs4 import BeautifulSoup - def export_as_html(filename): html_exporter = nbconvert.HTMLExporter() html_exporter.template_file = 'basic' @@ -123,3 +142,4 @@ def check_urls(notebook, name, attribute): bad_urls.add(url) return bad_urls +