From 8ecdc16ff8010ea5f2fec6fe812cb38c1cc4f8bb Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Mon, 1 Oct 2018 13:42:29 +0200 Subject: [PATCH 1/1] Initial commit --- VERSION | 1 + datasette_connectors/__init__.py | 16 ++++++++++++++++ datasette_connectors/connectors.py | 22 ++++++++++++++++++++++ setup.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 VERSION create mode 100644 datasette_connectors/__init__.py create mode 100644 datasette_connectors/connectors.py create mode 100644 setup.py diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..2a64fae --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.25 \ No newline at end of file diff --git a/datasette_connectors/__init__.py b/datasette_connectors/__init__.py new file mode 100644 index 0000000..9cecd04 --- /dev/null +++ b/datasette_connectors/__init__.py @@ -0,0 +1,16 @@ +import datasette +from datasette.cli import cli + + +# Monkey patching for original Datasette +def init(self, *args, **kwargs): + print("Test") + self.original_init(*args, **kwargs) + +datasette.app.Datasette.original_init = datasette.app.Datasette.__init__ +datasette.app.Datasette.__init__ = init + + +# Read external database connectors +from . import connectors +connectors.load_connectors() diff --git a/datasette_connectors/connectors.py b/datasette_connectors/connectors.py new file mode 100644 index 0000000..6b09abb --- /dev/null +++ b/datasette_connectors/connectors.py @@ -0,0 +1,22 @@ +import pkg_resources + +db_connectors = {} + +def load_connectors(): + for entry_point in pkg_resources.iter_entry_points('datasette.connectors'): + db_connectors[entry_point.name] = entry_point.load() + +def inspect(path): + for connector in db_connectors.values(): + try: + return connector.inspect(path) + except: + pass + else: + raise Exception("No database connector found for %s" % path) + +def connect(path, dbtype): + try: + return db_connectors[dbtype].Connection(path) + except: + raise Exception("No database connector found for %s" % path) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..764fbf9 --- /dev/null +++ b/setup.py @@ -0,0 +1,30 @@ +from setuptools import setup +import os + +def get_version(): + with open('VERSION') as fd: + return fd.read().strip() + +def get_long_description(): + with open(os.path.join( + os.path.dirname(os.path.abspath(__file__)), 'README.md' + ), encoding='utf8') as fp: + return fp.read() + + +setup( + name='datasette-connectors', + version=get_version(), + description='Datasette support to other database types', + long_description=get_long_description(), + long_description_content_type='text/markdown', + author='Javier Sancho', + url='https://github.com/pytables/datasette-connectors', + license='Apache License, Version 2.0', + packages=['datasette_connectors'], + install_requires=['datasette==0.25'], + entry_points=''' + [console_scripts] + datasette=datasette_connectors:cli + ''' +) -- 2.39.5