Skip to content

Commit

Permalink
Added /-/versions and /-/versions.json, closes #244
Browse files Browse the repository at this point in the history
Sample output:

    {
      "python": {
        "version": "3.6.3",
        "full": "3.6.3 (default, Oct  4 2017, 06:09:38) \n[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]"
      },
      "datasette": {
        "version": "0.20"
      },
      "sqlite": {
        "version": "3.23.1",
        "extensions": {
          "json1": null,
          "spatialite": "4.3.0a"
        }
      }
    }
  • Loading branch information
simonw committed May 3, 2018
1 parent 6907364 commit bb87cf8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
39 changes: 39 additions & 0 deletions datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import json
import jinja2
import hashlib
import sys
import time
import pint
import pluggy
Expand All @@ -42,6 +43,7 @@
urlsafe_components,
validate_sql_select,
)
from . import __version__
from . import hookspecs
from .version import __version__

Expand Down Expand Up @@ -1341,6 +1343,39 @@ def register_custom_units(self):
for unit in self.metadata.get('custom_units', []):
ureg.define(unit)

def versions(self):
conn = sqlite3.connect(':memory:')
self.prepare_connection(conn)
sqlite_version = conn.execute(
'select sqlite_version()'
).fetchone()[0]
sqlite_extensions = {}
for extension, testsql, hasversion in (
('json1', "SELECT json('{}')", False),
('spatialite', "SELECT spatialite_version()", True),
):
try:
result = conn.execute(testsql)
if hasversion:
sqlite_extensions[extension] = result.fetchone()[0]
else:
sqlite_extensions[extension] = None
except Exception as e:
pass
return {
'python': {
'version': '.'.join(map(str, sys.version_info[:3])),
'full': sys.version,
},
'datasette': {
'version': __version__,
},
'sqlite': {
'version': sqlite_version,
'extensions': sqlite_extensions,
}
}

def app(self):
app = Sanic(__name__)
default_templates = str(app_root / 'datasette' / 'templates')
Expand Down Expand Up @@ -1388,6 +1423,10 @@ def app(self):
JsonDataView.as_view(self, 'metadata.json', lambda: self.metadata),
'/-/metadata<as_json:(\.json)?$>'
)
app.add_route(
JsonDataView.as_view(self, 'versions.json', self.versions),
'/-/versions<as_json:(\.json)?$>'
)
app.add_route(
JsonDataView.as_view(self, 'plugins.json', lambda: [{
'name': p['name'],
Expand Down
14 changes: 14 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,20 @@ def test_plugins_json(app_client):
} in response.json


def test_versions_json(app_client):
response = app_client.get(
"/-/versions.json",
gather_request=False
)
assert 'python' in response.json
assert 'version' in response.json['python']
assert 'full' in response.json['python']
assert 'datasette' in response.json
assert 'version' in response.json['datasette']
assert 'sqlite' in response.json
assert 'version' in response.json['sqlite']


def test_page_size_matching_max_returned_rows(app_client_returend_rows_matches_page_size):
fetched = []
path = '/test_tables/no_primary_key.json'
Expand Down

0 comments on commit bb87cf8

Please sign in to comment.