Skip to content

Commit

Permalink
Only import sqlite3 if it's about to be used
Browse files Browse the repository at this point in the history
Still a single import, but this way it's only attempted if you're
actually using a sqlite example database.
  • Loading branch information
Zac-HD committed May 12, 2017
1 parent d45c9a5 commit 2f20f98
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
8 changes: 8 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------
Expand Down
12 changes: 5 additions & 7 deletions docs/supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/hypothesis/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion src/hypothesis/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

import os
import re
import sqlite3
import binascii
import threading
from contextlib import contextmanager

from hypothesis.internal.compat import FileNotFoundError, sha1, \
b64decode, b64encode

sqlite3 = None
SQLITE_PATH = re.compile(r"\.\(db|sqlite|sqlite3\)$")


Expand Down Expand Up @@ -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'):
Expand Down
2 changes: 1 addition & 1 deletion src/hypothesis/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))

0 comments on commit 2f20f98

Please sign in to comment.