From 2ecab3213ce229e604e2180a7ab22413ad127d56 Mon Sep 17 00:00:00 2001 From: antigrav_kids Date: Sat, 27 Apr 2024 23:28:21 -0700 Subject: [PATCH 1/4] tests proposed code for #2198 --- tests/test_loadextension.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/test_loadextension.py diff --git a/tests/test_loadextension.py b/tests/test_loadextension.py new file mode 100644 index 0000000000..c5b3fca44f --- /dev/null +++ b/tests/test_loadextension.py @@ -0,0 +1,28 @@ +from datasette.utils import LoadExtension + +def test_dos_path(): + path_string = "C:\Windows\System32\mod_spatialite.dll" + le = LoadExtension() + path = le.convert(path_string, None, None) + assert path == "C:\Windows\System32\mod_spatialite.dll" + +def test_dos_pathentry(): + path_entry = "C:\Windows\System32\mod_spatialite.dll:testentry" + le = LoadExtension() + pathen, entry = le.convert(path_entry, None, None) + assert pathen == "C:\Windows\System32\mod_spatialite.dll" + assert entry == "testentry" + +def test_linux_path(): + path_string = "/base/test/test2" + le = LoadExtension() + path = le.convert(path_string, None, None) + assert path == path_string + +def test_linux_path_entry(): + path_string = "/base/test/test2:testentry" + le = LoadExtension() + path, entry = le.convert(path_string, None, None) + assert path == "/base/test/test2" + assert entry == "testentry" + \ No newline at end of file From 32fc6e87b19a880e958176d172e61963e922f333 Mon Sep 17 00:00:00 2001 From: antigrav_kids Date: Sat, 27 Apr 2024 23:29:48 -0700 Subject: [PATCH 2/4] proposed code to enable Windows Spatialite --- datasette/utils/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/datasette/utils/__init__.py b/datasette/utils/__init__.py index e110891119..bdeb6e5a3f 100644 --- a/datasette/utils/__init__.py +++ b/datasette/utils/__init__.py @@ -873,6 +873,15 @@ class LoadExtension(click.ParamType): name = "path:entrypoint?" def convert(self, value, param, ctx): + #:\ indicates we're on a Windows machine study the argument a bit more + if ":\\" in r"%r" % value: + path_entry = value.split(":", 2) + if len(path_entry) < 3: + return value + #argument contains a Windows/DOS path and an entry point + path = path_entry[0] + ":" + path_entry[1] + entrypoint = path_entry[-1] + return path, entrypoint if ":" not in value: return value path, entrypoint = value.split(":", 1) From 294be58fb8ef53c1f9b8155391480a233b3544cb Mon Sep 17 00:00:00 2001 From: antigrav_kids Date: Sat, 27 Apr 2024 23:37:18 -0700 Subject: [PATCH 3/4] black format fixes --- datasette/utils/__init__.py | 2 +- tests/test_loadextension.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/datasette/utils/__init__.py b/datasette/utils/__init__.py index bdeb6e5a3f..6eefc2dc5f 100644 --- a/datasette/utils/__init__.py +++ b/datasette/utils/__init__.py @@ -878,7 +878,7 @@ def convert(self, value, param, ctx): path_entry = value.split(":", 2) if len(path_entry) < 3: return value - #argument contains a Windows/DOS path and an entry point + # argument contains a Windows/DOS path and an entry point path = path_entry[0] + ":" + path_entry[1] entrypoint = path_entry[-1] return path, entrypoint diff --git a/tests/test_loadextension.py b/tests/test_loadextension.py index c5b3fca44f..3ceb372e4d 100644 --- a/tests/test_loadextension.py +++ b/tests/test_loadextension.py @@ -1,28 +1,31 @@ from datasette.utils import LoadExtension + def test_dos_path(): path_string = "C:\Windows\System32\mod_spatialite.dll" le = LoadExtension() path = le.convert(path_string, None, None) assert path == "C:\Windows\System32\mod_spatialite.dll" - + + def test_dos_pathentry(): path_entry = "C:\Windows\System32\mod_spatialite.dll:testentry" le = LoadExtension() pathen, entry = le.convert(path_entry, None, None) assert pathen == "C:\Windows\System32\mod_spatialite.dll" assert entry == "testentry" - + + def test_linux_path(): path_string = "/base/test/test2" le = LoadExtension() path = le.convert(path_string, None, None) assert path == path_string + def test_linux_path_entry(): path_string = "/base/test/test2:testentry" le = LoadExtension() path, entry = le.convert(path_string, None, None) assert path == "/base/test/test2" assert entry == "testentry" - \ No newline at end of file From 4265e4b5000b99194d814081442a4b9c12dd644c Mon Sep 17 00:00:00 2001 From: antigrav_kids Date: Sun, 28 Apr 2024 07:02:12 -0700 Subject: [PATCH 4/4] adds link to Windows spatialite install instructions --- docs/spatialite.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/spatialite.rst b/docs/spatialite.rst index fbe0d75f46..61a4a893bd 100644 --- a/docs/spatialite.rst +++ b/docs/spatialite.rst @@ -70,6 +70,11 @@ Depending on your distribution, you should be able to run Datasette something li If you are unsure of the location of the module, try running ``locate mod_spatialite`` and see what comes back. +Installing SpatiaLite on Windows +----------------------------- + +For Windows, you may find binaries on the `Gaia-SINS `_ home page. + Spatial indexing latitude/longitude columns ===========================================