From a6f32439ce7af8e7644fc0991130d8def412b972 Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Fri, 12 May 2017 18:31:26 +1000 Subject: [PATCH] Only import sqlite3 if it's about to be used Still a single import, but this way it's only attempted if you're actually using a sqlite example database. --- docs/changes.rst | 8 ++++++++ docs/supported.rst | 6 ++---- src/hypothesis/_settings.py | 4 ++-- src/hypothesis/database.py | 4 +++- src/hypothesis/version.py | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 0111003d2c..35b6e4eb07 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -22,6 +22,14 @@ You should generally assume that an API is internal unless you have specific information to the contrary. +------------------ +3.8.4 - 2017-05-12 +------------------ + +Instead of unconditionally importing ``sqlite3``, Hypothesis now imports it +when a SQLite database is first used. This was the major blocker for BSD +support with default settings. + ------------------ 3.8.3 - 2017-05-09 ------------------ diff --git a/docs/supported.rst b/docs/supported.rst index 94b651aa40..cc1dcdb7d9 100644 --- a/docs/supported.rst +++ b/docs/supported.rst @@ -22,7 +22,7 @@ Hypothesis also supports PyPy (PyPy3 does not work because it only runs 3.2 comp code, but if and when there's a 3.3 compatible version it will be supported), and should support 32-bit and narrow builds, though this is currently only tested on Windows. -Hypothesis does not currently work on Jython (it requires sqlite), though could feasibly +Hypothesis does not currently work on Jython, though could feasibly be made to do so. IronPython might work but hasn't been tested. In general Hypothesis does not officially support anything except the latest @@ -36,9 +36,7 @@ Operating systems In theory Hypothesis should work anywhere that Python does. In practice it is only known to work and regularly tested on OS X, Windows and Linux, and you may -experience issues running it elsewhere. For example a known issue is that FreeBSD -splits out the python-sqlite package from the main python package, and you will -need to install that in order for it to work. +experience issues running it elsewhere. If you're using something else and it doesn't work, do get in touch and I'll try to help, but unless you can come up with a way for me to run a CI server on that diff --git a/src/hypothesis/_settings.py b/src/hypothesis/_settings.py index 11d9e9418b..a3d720b174 100644 --- a/src/hypothesis/_settings.py +++ b/src/hypothesis/_settings.py @@ -246,8 +246,8 @@ def database(self): If this was explicitly set at settings instantiation then that value will be used (even if it was None). If not and the database_file setting is not None this will be lazily loaded as - an SQLite backed ExampleDatabase using that file the first time - this property is accessed on a particular thread. + an ExampleDatabase using that file the first time this property + is accessed on a particular thread. """ if self._database is not_set and self.database_file is not None: diff --git a/src/hypothesis/database.py b/src/hypothesis/database.py index 53659ba306..fc1a902287 100644 --- a/src/hypothesis/database.py +++ b/src/hypothesis/database.py @@ -19,7 +19,6 @@ import os import re -import sqlite3 import binascii import threading from contextlib import contextmanager @@ -27,6 +26,7 @@ from hypothesis.internal.compat import FileNotFoundError, sha1, \ b64decode, b64encode +sqlite3 = None SQLITE_PATH = re.compile(r"\.\(db|sqlite|sqlite3\)$") @@ -115,6 +115,8 @@ def __init__(self, path=u':memory:'): self.path = path self.db_created = False self.current_connection = threading.local() + global sqlite3 + import sqlite3 def connection(self): if not hasattr(self.current_connection, 'connection'): diff --git a/src/hypothesis/version.py b/src/hypothesis/version.py index 78ab14103b..c5db2b7da5 100644 --- a/src/hypothesis/version.py +++ b/src/hypothesis/version.py @@ -17,5 +17,5 @@ from __future__ import division, print_function, absolute_import -__version_info__ = (3, 8, 3) +__version_info__ = (3, 8, 4) __version__ = '.'.join(map(str, __version_info__))