villebro commented on a change in pull request #7643: 7620: Start removing 
dependencies on requests
URL: 
https://github.com/apache/incubator-superset/pull/7643#discussion_r295305007
 
 

 ##########
 File path: superset/connectors/druid/models.py
 ##########
 @@ -31,15 +31,22 @@
 from flask_appbuilder.models.decorators import renders
 from flask_babel import lazy_gettext as _
 import pandas
-from pydruid.client import PyDruid
-from pydruid.utils.aggregators import count
-from pydruid.utils.dimensions import MapLookupExtraction, RegexExtraction
-from pydruid.utils.filters import Dimension, Filter
-from pydruid.utils.having import Aggregation
-from pydruid.utils.postaggregator import (
-    Const, Field, HyperUniqueCardinality, Postaggregator, Quantile, Quantiles,
-)
-import requests
+try:
+    from pydruid.client import PyDruid
+    from pydruid.utils.aggregators import count
+    from pydruid.utils.dimensions import MapLookupExtraction, RegexExtraction
+    from pydruid.utils.filters import Dimension, Filter
+    from pydruid.utils.having import Aggregation
+    from pydruid.utils.postaggregator import (
+        Const, Field, HyperUniqueCardinality, Postaggregator, Quantile, 
Quantiles,
+    )
+    import requests
+except ImportError:
+    print("""pydruid and requests are optional dependencies, and
+          it seems they are not installed on your system. Aborting...
+          """)
+    from sys import exit
+    exit(1)
 
 Review comment:
   A few observations:
   - This code is run at least when `superset load examples` is executed, even 
when not connected to a druid cluster, causing an `exit(1)` every time. I think 
this needs to be refactored so that this code is only called when needed, e.g. 
in the specific code blocks where they are needed.
   - The error message should probably be wrapped in a `_('message')` to make 
it translatable. Furthermore, if the message is wrapped in triple quotes, the 
leading spaces on the next rows will be included in the message. I believe 
linters will prefer single quotes over many rows. So something like this:
   ```python
   try:
       ...
   except Import Error:
       print(_('pydruid and requests are optional dependencies, and '
               'it seems they are not installed on your system. Aborting...'))
   ))
   ```
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to