Skip to content

Commit 614a9e2

Browse files
Merge pull request #31 from vmapetr/v-mapetr/build-with-loadable-sqlite-extensions
Build Python3 for nix and darwin with enabled loadable sqlite extensions
2 parents d0bb429 + 22860d0 commit 614a9e2

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

builders/macos-python-builder.psm1

+15-3
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,31 @@ class macOSPythonBuilder : NixPythonBuilder {
2929
#>
3030

3131
$pythonBinariesLocation = $this.GetFullPythonToolcacheLocation()
32-
$configureString = "./configure --prefix=$pythonBinariesLocation --enable-optimizations --enable-shared --with-lto"
32+
$configureString = "./configure"
33+
$configureString += " --prefix=$pythonBinariesLocation"
34+
$configureString += " --enable-optimizations"
35+
$configureString += " --enable-shared"
36+
$configureString += " --with-lto"
3337

3438
### OS X 10.11, Apple no longer provides header files for the deprecated system version of OpenSSL.
3539
### Solution is to install these libraries from a third-party package manager,
3640
### and then add the appropriate paths for the header and library files to configure command.
3741
### Link to documentation (https://cpython-devguide.readthedocs.io/setup/#build-dependencies)
3842
if ($this.Version -lt "3.7.0") {
39-
$env:LDFLAGS="-L$(brew --prefix openssl)/lib"
40-
$env:CFLAGS="-I$(brew --prefix openssl)/include"
43+
$env:LDFLAGS = "-L$(brew --prefix openssl)/lib"
44+
$env:CFLAGS = "-I$(brew --prefix openssl)/include"
4145
} else {
4246
$configureString += " --with-openssl=/usr/local/opt/openssl"
4347
}
4448

49+
### Compile with support of loadable sqlite extensions. Unavailable for Python 2.*
50+
### Link to documentation (https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.enable_load_extension)
51+
if ($this.Version -ge "3.2.0") {
52+
$configureString += " --enable-loadable-sqlite-extensions"
53+
$env:LDFLAGS += " -L$(brew --prefix sqlite3)/lib"
54+
$env:CFLAGS += " -I$(brew --prefix sqlite3)/include"
55+
}
56+
4557
Execute-Command -Command $configureString
4658
}
4759

builders/ubuntu-python-builder.psm1

+11-2
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,22 @@ class UbuntuPythonBuilder : NixPythonBuilder {
3232

3333
### To build Python with SO we must pass full path to lib folder to the linker
3434
$env:LDFLAGS="-Wl,--rpath=${pythonBinariesLocation}/lib"
35-
$configureString = "./configure --prefix=$pythonBinariesLocation --enable-shared --enable-optimizations"
35+
$configureString = "./configure"
36+
$configureString += " --prefix=$pythonBinariesLocation"
37+
$configureString += " --enable-shared"
38+
$configureString += " --enable-optimizations"
3639

40+
### Compile with ucs4 for Python 2.x. On 3.x, ucs4 is enabled by default
3741
if ($this.Version -lt "3.0.0") {
38-
### Compile with ucs4 for Python 2.x. On 3.x, ucs4 is enabled by default
3942
$configureString += " --enable-unicode=ucs4"
4043
}
4144

45+
### Compile with support of loadable sqlite extensions. Unavailable for Python 2.*
46+
### Link to documentation (https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.enable_load_extension)
47+
if ($this.Version -ge "3.2.0") {
48+
$configureString += " --enable-loadable-sqlite-extensions"
49+
}
50+
4251
Execute-Command -Command $configureString
4352
}
4453

tests/python-tests.ps1

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ Describe "Tests" {
4141
"python ./sources/simple-test.py" | Should -ReturnZeroExitCode
4242
}
4343

44+
if ($Version -ge "3.2.0") {
45+
It "Check if sqlite3 module is installed" {
46+
"python ./sources/python-sqlite3.py" | Should -ReturnZeroExitCode
47+
}
48+
}
49+
4450
if (IsNixPlatform $Platform) {
4551

4652
It "Check for failed modules in build_output" {

tests/sources/python-sqlite3.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import sqlite3
2+
from sqlite3 import Error
3+
4+
def create_connection(db_file):
5+
""" create a database connection to a SQLite database """
6+
conn = None
7+
try:
8+
print('Sqlite3 version: ', sqlite3.version)
9+
conn = sqlite3.connect(db_file)
10+
conn.enable_load_extension(True)
11+
except Error as e:
12+
print(e)
13+
exit(1)
14+
finally:
15+
if conn:
16+
conn.close()
17+
18+
if __name__ == '__main__':
19+
create_connection(r"pythonsqlite.db")

0 commit comments

Comments
 (0)