paulfitz / daff

align and compare tables
https://paulfitz.github.io/daff
MIT License
800 stars 67 forks source link

Python: Defer import of sqlite3 to allow usage on platforms without sqlite #143

Closed DerrickRice closed 4 years ago

DerrickRice commented 4 years ago

daff imports sqlite3, but only needs it if the import format is sqlite.

This means that daff fails when sqlite isn't found:

Traceback (most recent call last):                                                                                                                                                            
  File "/SNIPPED/python3/lib/python3.7/runpy.py", line 183, in _run_module_as_main                                                          
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)                                                                                                                          
  File "/SNIPPED/python3/lib/python3.7/runpy.py", line 142, in _get_module_details                                                          
    return _get_module_details(pkg_main_name, error)                                                                                                                                          
  File "/SNIPPED/python3/lib/python3.7/runpy.py", line 109, in _get_module_details                                                          
    __import__(pkg_name)                                                                                                                                                                      
  File "/SNIPPED/python3.7/site-packages/daff/__init__.py", line 11800, in <module>                                                                                                                                                                                                                             
    import sqlite3                                                                                                                                                                            
  File "/SNIPPED/python3/lib/python3.7/sqlite3/__init__.py", line 23, in <module>                                                           
    from sqlite3.dbapi2 import *                                                                                                                                                              
  File "/SNIPPED/python3/lib/python3.7/sqlite3/dbapi2.py", line 27, in <module>                                                             
    from _sqlite3 import *                                                                                                                                                                    
ModuleNotFoundError: No module named '_sqlite3'    

Simply move the import statement here:

10321 ᚛---def openSqliteDatabase(self,path):                                                                                                                                                                                                                                                                                                                                                
10322 ᚛---᚛---import sqlite3                                                                                                                                                                                                                                                                                                                                                                
10323 ᚛---᚛---return SqliteDatabase(sqlite3.connect(path),path)                                                                                                                                                                                                                                                                                                                             
10324 ᚛---᚛---return None   
paulfitz commented 4 years ago

This has been released in daff 1.3.43.