From 2f20f98cdb087cd49999bad05e195b288a3746d0 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 | 12 +++++------- src/hypothesis/_settings.py | 4 ++-- src/hypothesis/database.py | 4 +++- src/hypothesis/version.py | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 4d55c06ceb..8d83d0825f 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 003bdfbec6..7e87452eae 100644 --- a/docs/supported.rst +++ b/docs/supported.rst @@ -14,10 +14,10 @@ Python versions Hypothesis is supported and tested on CPython 2.7 and CPython 3.4+. Hypothesis also supports PyPy2, and will support PyPy3 when there is a stable -release supporting Python 3.4+. Hypothesis does not currently work on Jython -(it requires sqlite), though could feasibly be made to do so. IronPython might -work but hasn't been tested. 32-bit and narrow builds should work, though -this is currently only tested on Windows. +release supporting Python 3.4+. Hypothesis does not currently work on Jython, +though could feasibly be made to do so. IronPython might work but hasn't been +tested. 32-bit and narrow builds should work, though this is currently only +tested on Windows. In general Hypothesis does not officially support anything except the latest patch release of any version of Python it supports. Earlier releases should work @@ -30,9 +30,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__))