From d8f6c0894da4276c9f8beffee2f940a5d6a20e1f Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Fri, 1 Apr 2016 21:36:31 +0900 Subject: [PATCH 1/3] pep8 cleanup --- simplesqlite/core.py | 8 +++++--- test/test_simplesqlite.py | 10 ++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/simplesqlite/core.py b/simplesqlite/core.py index 87845d2..40ed9e7 100644 --- a/simplesqlite/core.py +++ b/simplesqlite/core.py @@ -157,7 +157,8 @@ def connect(self, database_path, mode="a"): Path to the SQLite database file to be connected. :param str mode: ``"r"``: Open for read only. - ``"w"``: Open for read/write. Delete existing tables when connecting. + ``"w"``: Open for read/write. + Delete existing tables when connecting. ``"a"``: Open for read/write. Append to the existing tables. :raises ValueError: If ``database_path`` is invalid or ``mode`` is invalid. @@ -887,7 +888,8 @@ def create_table(self, table_name, attribute_description_list): def create_index(self, table_name, attribute_name): """ - :param str table_name: Table name that contains the attribute to be indexed. + :param str table_name: + Table name that contains the attribute to be indexed. :param str attribute_name: Attribute name to create index. :raises ValueError: If the database connection is invalid. :raises IOError: If open mode is neither ``"w"`` nor ``"a"``. @@ -1109,7 +1111,7 @@ def __verify_value_matrix(field_list, value_matrix): """ :param list/tuple field_list: :param list/tuple value_matrix: the list to test. - :raises ValueError: + :raises ValueError: """ miss_match_idx_list = [] diff --git a/test/test_simplesqlite.py b/test/test_simplesqlite.py index 459e824..b502890 100644 --- a/test/test_simplesqlite.py +++ b/test/test_simplesqlite.py @@ -5,14 +5,11 @@ ''' import itertools -import os -import re import sqlite3 from collections import namedtuple import dataproperty import pytest -from six.moves import range from simplesqlite import * from simplesqlite.sqlquery import SqlQuery @@ -152,7 +149,8 @@ def test_normal(self, con_mix, con_empty): def test_exception_0(self, con_mix, con_profile): with pytest.raises(ValueError): append_table( - con_src=con_mix, con_dst=con_profile, table_name=TEST_TABLE_NAME) + con_src=con_mix, con_dst=con_profile, + table_name=TEST_TABLE_NAME) def test_exception_1(self, con_mix, con_null): with pytest.raises(NullDatabaseConnectionError): @@ -719,8 +717,8 @@ class Test_SimpleSQLite_create_table_from_csv: ]) def test_normal( self, tmpdir, csv_text, csv_filename, - table_name, attr_name_list, - expected_table_name, expected_attr_name_list, expected_data_matrix): + table_name, attr_name_list, expected_table_name, + expected_attr_name_list, expected_data_matrix): p_db = tmpdir.join("tmp.db") p_csv = tmpdir.join(csv_filename) From 2fe6c58856c2be0157fef2b39b46a0e073db14f8 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Sat, 2 Apr 2016 11:03:21 +0900 Subject: [PATCH 2/3] [ci skip] Update docstring --- simplesqlite/__init__.py | 17 ++- simplesqlite/core.py | 228 ++++++++++++++++++--------------------- simplesqlite/sqlquery.py | 30 ++---- 3 files changed, 126 insertions(+), 149 deletions(-) diff --git a/simplesqlite/__init__.py b/simplesqlite/__init__.py index eead062..9a1dd8e 100644 --- a/simplesqlite/__init__.py +++ b/simplesqlite/__init__.py @@ -18,7 +18,7 @@ def validate_table_name(name): """ :param str name: Table name to validate. - :raises ValueError: If ``name`` is invalid for a table name. + :raises ValueError: |raises_validate_table_name| """ if dataproperty.is_empty_string(name): @@ -32,13 +32,14 @@ def append_table(con_src, con_dst, table_name): :param SimpleSQLite con_src: Source of the database. :param SimpleSQLite con_dst: Destination of the database. :param str table_name: Table name to copy. - :return: ``True`` if success. + :return: |True| if success. :rtype: bool + :raises simplesqlite.TableNotFoundError: + |raises_verify_table_existence| :raises ValueError: If attribute of the table is different from each other. .. seealso:: - :py:meth:`simplesqlite.core.SimpleSQLite.verify_table_existence` :py:meth:`simplesqlite.core.SimpleSQLite.create_table_with_data` """ @@ -70,7 +71,7 @@ def append_table(con_src, con_dst, table_name): def connect_sqlite_db_mem(): """ - :return: Instance of a in memory database + :return: Instance of a in memory database. :rtype: SimpleSQLite :Examples: @@ -97,8 +98,16 @@ class NullDatabaseConnectionError(Exception): class TableNotFoundError(Exception): + """ + Raised when accessed the table that not exists in the database. + """ + pass class AttributeNotFoundError(Exception): + """ + Raised when accessed the attribute that not exists in the table. + """ + pass diff --git a/simplesqlite/core.py b/simplesqlite/core.py index 40ed9e7..eb389b4 100644 --- a/simplesqlite/core.py +++ b/simplesqlite/core.py @@ -22,12 +22,12 @@ class SimpleSQLite(object): """ - Wrapper class of ``sqlite3`` module. + Wrapper class of |sqlite3| module. :param str database_path: File path of the database to be connected. :param str mode: Open mode. :param bool profile: - Recording SQL query execution time profile, if the value is ``True``. + Recording SQL query execution time profile, if the value is |True|. .. seealso:: @@ -57,7 +57,7 @@ def database_path(self): @property def connection(self): """ - :return: ``Connection`` instance of the connected database. + :return: |Connection| instance of the connected database. :rtype: sqlite3.Connection """ @@ -69,9 +69,7 @@ def mode(self): :return: Connection mode: ``"r"``/``"w"``/``"a"``. :rtype: str - .. seealso:: - - :py:meth:`.connect` + .. seealso:: :py:meth:`.connect` """ return self.__mode @@ -93,7 +91,7 @@ def __exit__(self, exc_type, exc_value, traceback): def is_connected(self): """ - :return: ``True`` if the connection to a database is valid. + :return: |True| if the connection to a database is valid. :rtype: bool :Examples: @@ -116,8 +114,8 @@ def is_connected(self): def check_connection(self): """ - :raises NullDatabaseConnectionError: - If not connected to a SQLite database file. + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| :Examples: @@ -161,7 +159,7 @@ def connect(self, database_path, mode="a"): Delete existing tables when connecting. ``"a"``: Open for read/write. Append to the existing tables. :raises ValueError: - If ``database_path`` is invalid or ``mode`` is invalid. + If ``database_path`` is invalid or |attr_mode| is invalid. :raises sqlite3.OperationalError: If unable to open the database file. """ @@ -195,19 +193,17 @@ def execute_query(self, query, caller=None): :param str query: Query to be executed. :param tuple caller: Caller information. - Expects the return value of Logger.findCaller() method. + Expects the return value of :py:meth:`logging.Logger.findCaller`. :return: Result of the query execution. :rtype: sqlite3.Cursor - :raises sqlite3.OperationalError: If failed to execute query. + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| + :raises sqlite3.OperationalError: |raises_operational_error| .. warning:: This method can execute an arbitrary query. - i.e. No access permissions check by :py:attr:`.mode`. - - .. seealso:: - - :py:meth:`.check_connection` + i.e. No access permissions check by |attr_mode|. """ import time @@ -253,12 +249,15 @@ def select(self, select, table_name, where=None, extra=None): :param str table_name: Table name of executing the query. :return: Result of the query execution. :rtype: sqlite3.Cursor + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| + :raises simplesqlite.TableNotFoundError: + |raises_verify_table_existence| + :raises sqlite3.OperationalError: |raises_operational_error| .. seealso:: - :py:meth:`.verify_table_existence` :py:meth:`.sqlquery.SqlQuery.make_select` - :py:meth:`.execute_query` """ self.verify_table_existence(table_name) @@ -271,15 +270,14 @@ def insert(self, table_name, insert_record): Execute INSERT query. :param str table_name: Table name of executing the query. - :param dict/namedtuple/list/tuple insert_record: Record to be inserted - :raises ValueError: If the database connection is invalid. - :raises IOError: If open mode is neither ``"w"`` nor ``"a"``. - - .. seealso:: + :param insert_record: Record to be inserted. + :type insert_record: |dict|/|namedtuple|/|list|/|tuple| + :raises IOError: |raises_write_permission| + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| + :raises sqlite3.OperationalError: |raises_operational_error| - :py:meth:`.check_connection` - :py:meth:`.sqlquery.SqlQuery.make_insert` - :py:meth:`.execute_query` + .. seealso:: :py:meth:`.sqlquery.SqlQuery.make_insert` """ self.validate_access_permission(["w", "a"]) @@ -294,17 +292,16 @@ def insert_many(self, table_name, insert_record_list): Execute INSERT query for multiple records. :param str table: Table name of executing the query. - :param dict/namedtuple/list/tuple insert_record: - Records to be inserted. - :raises ValueError: If the database connection is invalid. - :raises IOError: If open mode is neither ``"w"`` nor ``"a"``. - :raises sqlite3.OperationalError: If failed to execute query. + :param insert_record: Records to be inserted. + :type insert_record: |dict|/|namedtuple|/|list|/|tuple| + :raises IOError: |raises_write_permission| + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| + :raises simplesqlite.TableNotFoundError: + |raises_verify_table_existence| + :raises sqlite3.OperationalError: |raises_operational_error| - .. seealso:: - - :py:meth:`.check_connection` - :py:meth:`.verify_table_existence` - :py:meth:`.sqlquery.SqlQuery.make_insert` + .. seealso:: :py:meth:`.sqlquery.SqlQuery.make_insert` """ self.validate_access_permission(["w", "a"]) @@ -340,16 +337,16 @@ def update(self, table_name, set_query, where=None): :param str table_name: Table name of executing the query. :param str set_query: - :raises ValueError: If the database connection is invalid. - :raises IOError: If open mode is neither ``"w"`` nor ``"a"``. - :raises sqlite3.OperationalError: If failed to execute query. + :raises IOError: |raises_write_permission| + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| + :raises simplesqlite.TableNotFoundError: + |raises_verify_table_existence| + :raises sqlite3.OperationalError: |raises_operational_error| .. seealso:: - :py:meth:`.check_connection` - :py:meth:`.verify_table_existence` :py:meth:`.sqlquery.SqlQuery.make_update` - :py:meth:`.execute_query` """ self.validate_access_permission(["w", "a"]) @@ -363,7 +360,7 @@ def get_total_changes(self): """ .. seealso:: - :py:meth:`sqlite3.Connection.total_changes` + :py:attr:`sqlite3.Connection.total_changes` """ self.check_connection() @@ -377,11 +374,13 @@ def get_value(self, select, table_name, where=None, extra=None): :param str select: Attribute for SELECT query :param str table_name: Table name of executing the query. :return: Result of execution of the query. + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| + :raises sqlite3.OperationalError: |raises_operational_error| .. seealso:: :py:meth:`.sqlquery.SqlQuery.make_select` - :py:meth:`.execute_query` """ self.verify_table_existence(table_name) @@ -401,6 +400,9 @@ def get_table_name_list(self): """ :return: List of table names in the database. :rtype: list + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| + :raises sqlite3.OperationalError: |raises_operational_error| :Examples: @@ -420,11 +422,6 @@ def get_table_name_list(self): .. parsed-literal:: [u'hoge'] - - .. seealso:: - - :py:meth:`.check_connection` - :py:meth:`.execute_query` """ self.check_connection() @@ -440,8 +437,11 @@ def get_attribute_name_list(self, table_name): """ :return: List of attribute names in the table. :rtype: list - :raises TableNotFoundError: - If ``tablename`` table not found in the database. + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| + :raises simplesqlite.TableNotFoundError: + |raises_verify_table_existence| + :raises sqlite3.OperationalError: |raises_operational_error| :Examples: @@ -467,11 +467,6 @@ def get_attribute_name_list(self, table_name): ['attr_a', 'attr_b'] 'not_existing' table not found in /tmp/sample.sqlite - - .. seealso:: - - :py:meth:`.verify_table_existence` - :py:meth:`.execute_query` """ self.verify_table_existence(table_name) @@ -485,13 +480,11 @@ def get_attribute_type_list(self, table_name): """ :return: List of attribute names in the table. :rtype: list - :raises TableNotFoundError: - If ``tablename`` table not found in the database. - - .. seealso:: - - :py:meth:`.verify_table_existence` - :py:meth:`.execute_query` + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| + :raises simplesqlite.TableNotFoundError: + |raises_verify_table_existence| + :raises sqlite3.OperationalError: |raises_operational_error| """ self.verify_table_existence(table_name) @@ -515,11 +508,10 @@ def get_profile(self, profile_count=50): counted from the top query in descending order by the cumulative execution time. :return: Profile information for each query. - :rtype: list of namedtuple - - .. seealso:: - - :py:meth:`.execute_query` + :rtype: list of |namedtuple| + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| + :raises sqlite3.OperationalError: |raises_operational_error| """ from collections import namedtuple @@ -563,6 +555,8 @@ def get_sqlite_master(self): :return: sqlite_master table information. :rtype: list + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| :Examples: @@ -602,10 +596,6 @@ def get_sqlite_master(self): "rootpage": 3 } ] - - .. seealso:: - - :py:meth:`.check_connection` """ self.check_connection() @@ -626,7 +616,7 @@ def get_sqlite_master(self): def has_table(self, table_name): """ :param str table_name: Table name to be tested. - :return: ``True`` if the database has the table. + :return: |True| if the database has the table. :rtype: bool :Examples: @@ -661,8 +651,10 @@ def has_attribute(self, table_name, attribute_name): """ :param str table_name: Table name that exists attribute. :param str attribute_name: Attribute name to be tested. - :return: ``True`` if the table has the attribute. + :return: |True| if the table has the attribute. :rtype: bool + :raises simplesqlite.TableNotFoundError: + |raises_verify_table_existence| :Examples: @@ -690,10 +682,6 @@ def has_attribute(self, table_name, attribute_name): True False 'not_existing' table not found in /tmp/sample.sqlite - - .. seealso:: - - :py:meth:`.verify_table_existence` """ self.verify_table_existence(table_name) @@ -707,8 +695,10 @@ def has_attribute_list(self, table_name, attribute_name_list): """ :param str table_name: Table name that exists attribute. :param str attribute_name_list: Attribute names to be tested. - :return: ``True`` if the table has all of the attribute. + :return: |True| if the table has all of the attribute. :rtype: bool + :raises simplesqlite.TableNotFoundError: + |raises_verify_table_existence| :Examples: @@ -740,10 +730,6 @@ def has_attribute_list(self, table_name, attribute_name_list): True False 'not_existing' table not found in /tmp/sample.sqlite - - .. seealso:: - - :py:meth:`.has_attribute` """ if dataproperty.is_empty_list_or_tuple(attribute_name_list): @@ -763,7 +749,9 @@ def has_attribute_list(self, table_name, attribute_name_list): def verify_table_existence(self, table_name): """ :param str table_name: Table name to be tested. - :raises TableNotFoundError: If the table not found in the database + :raises simplesqlite.TableNotFoundError: + |raises_verify_table_existence| + :raises ValueError: |raises_validate_table_name| :Examples: @@ -788,10 +776,6 @@ def verify_table_existence(self, table_name): .. parsed-literal:: 'not_existing' table not found in /tmp/sample.sqlite - - .. seealso:: - - :py:func:`simplesqlite.validate_table_name` """ simplesqlite.validate_table_name(table_name) @@ -806,7 +790,10 @@ def verify_attribute_existence(self, table_name, attribute_name): """ :param str table_name: Table name that exists attribute. :param str attribute_name: Attribute name to be tested. - :raises AttributeNotFoundError: If attribute not found in the table + :raises simplesqlite.AttributeNotFoundError: + If attribute not found in the table + :raises simplesqlite.TableNotFoundError: + |raises_verify_table_existence| :Examples: @@ -836,10 +823,6 @@ def verify_attribute_existence(self, table_name, attribute_name): 'not_existing' attribute not found in 'sample_table' table 'not_existing' table not found in /tmp/sample.sqlite - - .. seealso:: - - :py:meth:`.verify_table_existence` """ self.verify_table_existence(table_name) @@ -854,8 +837,9 @@ def verify_attribute_existence(self, table_name, attribute_name): def drop_table(self, table_name): """ :param str table_name: Table name to drop. - :raises ValueError: If the database connection is invalid. - :raises IOError: If open mode is neither ``"w"`` nor ``"a"``. + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| + :raises IOError: |raises_write_permission| """ self.validate_access_permission(["w", "a"]) @@ -869,8 +853,9 @@ def create_table(self, table_name, attribute_description_list): """ :param str table_name: Table name to create. :param list attribute_description_list: List of table description. - :raises ValueError: If the database connection is invalid. - :raises IOError: If open mode is neither ``"w"`` nor ``"a"``. + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| + :raises IOError: |raises_write_permission| """ self.validate_access_permission(["w", "a"]) @@ -891,12 +876,11 @@ def create_index(self, table_name, attribute_name): :param str table_name: Table name that contains the attribute to be indexed. :param str attribute_name: Attribute name to create index. - :raises ValueError: If the database connection is invalid. - :raises IOError: If open mode is neither ``"w"`` nor ``"a"``. - - .. seealso:: - - :py:meth:`.verify_table_existence` + :raises IOError: |raises_write_permission| + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| + :raises simplesqlite.TableNotFoundError: + |raises_verify_table_existence| """ self.verify_table_existence(table_name) @@ -914,9 +898,7 @@ def create_index_list(self, table_name, attribute_name_list): :param list attribute_name_list: List of attribute names to create indices. - .. seealso:: - - :py:meth:`.create_index` + .. seealso:: :py:meth:`.create_index` """ self.validate_access_permission(["w", "a"]) @@ -936,10 +918,10 @@ def create_table_with_data( :param str table_name: Table name to create. :param list attribute_name_list: List of attribute names of the table. :param data_matrix: Data to be inserted into the table. - :type data_matrix: List of dict/namedtuple/list/tuple + :type data_matrix: List of |dict|/|namedtuple|/|list|/|tuple| :param tuple index_attribute_list: List of attribute names of create indices. - :raises ValueError: If ``data_matrix`` is empty. + :raises ValueError: If the ``data_matrix`` is empty. .. seealso:: @@ -1001,7 +983,7 @@ def create_table_from_csv( .. seealso:: :py:meth:`.create_table_with_data` - :py:meth:`csv.reader` + :py:func:`csv.reader` """ import csv @@ -1040,9 +1022,7 @@ def create_table_from_csv( def rollback(self): """ - .. seealso:: - - :py:meth:`sqlite3.Connection.rollback` + .. seealso:: :py:meth:`sqlite3.Connection.rollback` """ try: @@ -1054,9 +1034,7 @@ def rollback(self): def commit(self): """ - .. seealso:: - - :py:meth:`sqlite3.Connection.commit` + .. seealso:: :py:meth:`sqlite3.Connection.commit` """ try: @@ -1070,9 +1048,7 @@ def close(self): """ Commit and close the connection. - .. seealso:: - - :py:meth:`sqlite3.Connection.close` + .. seealso:: :py:meth:`sqlite3.Connection.close` """ try: @@ -1157,14 +1133,14 @@ def __initialize_connection(self): def validate_access_permission(self, valid_permission_list): """ - :param list/tuple valid_permission_list: + :param valid_permission_list: List of permissions that access is allowed. - :raises ValueError: If database connection is invalid. - :raises IOError: If invalid permission. - - .. seealso:: - - :py:meth:`.check_connection` + :type valid_permission_list: |list|/|tuple| + :raises ValueError: If the |attr_mode| is invalid. + :raises IOError: + If the |attr_mode| not in the ``valid_permission_list``. + :raises simplesqlite.NullDatabaseConnectionError: + |raises_check_connection| """ self.check_connection() diff --git a/simplesqlite/sqlquery.py b/simplesqlite/sqlquery.py index 70258b9..21cb275 100644 --- a/simplesqlite/sqlquery.py +++ b/simplesqlite/sqlquery.py @@ -118,7 +118,8 @@ def to_attr_str_list(cls, name_list, operation_query=""): :param str operation_query: Used as a SQLite function if the value is not empty. :return: - List of strings that suitable for attribute names of a SQLite query. + List of strings that suitable for + attribute names of a SQLite query. :rtype: list/itertools.imap :Examples: @@ -148,7 +149,7 @@ def to_value_str(cls, value): :param str value: Value associated with a key. :return: String that suitable for a value of a key. - Return ``"NULL"`` if the value is ``None`` + Return ``"NULL"`` if the value is |None|. :rtype: str :Examples: @@ -200,13 +201,14 @@ def make_select(cls, select, table, where=None, extra=None): :param str table: Table name of executing the query. :param str where: Add a WHERE clause to execute query, - if the value is not ``None``. + if the value is not |None|. :param extra extra: Add additional clause to execute query, - if the value is not ``None``. + if the value is not |None|. :return: Query of SQLite. :rtype: str :raises ValueError: ``select`` is empty string. + :raises ValueError: |raises_validate_table_name| :Examples: @@ -217,10 +219,6 @@ def make_select(cls, select, table, where=None, extra=None): 'SELECT value FROM example WHERE key = 1' >>> SqlQuery.make_select(select="value", table="example", where=SqlQuery.make_where("key", 1), extra="ORDER BY value") 'SELECT value FROM example WHERE key = 1 ORDER BY value' - - .. seealso:: - - :py:func:`simplesqlite.validate_table_name` """ sql.validate_table_name(table) @@ -247,14 +245,11 @@ def make_insert(cls, table, insert_tuple, is_insert_many=False): :param list/tuple insert_tuple: Insertion data. :param bool is_insert_many: Make query that insert multiple data at once, - if the value is ``True``. + if the value is |True|. :return: Query of SQLite. :rtype: str - :raises ValueError: If ``insert_tuple`` is empty list/tuple. - - .. seealso:: - - :py:func:`simplesqlite.validate_table_name` + :raises ValueError: If ``insert_tuple`` is empty |list|/|tuple|. + :raises ValueError: |raises_validate_table_name| """ sql.validate_table_name(table) @@ -286,14 +281,11 @@ def make_update(cls, table, set_query, where=None): :param str set_query: SET part of the UPDATE query. :param str where: Add a WHERE clause to execute query, - if the value is not ``None``. + if the value is not |None|. :return: Query of SQLite. :rtype: str :raises ValueError: If ``set_query`` is empty string. - - .. seealso:: - - :py:func:`simplesqlite.validate_table_name` + :raises ValueError: |raises_validate_table_name| """ sql.validate_table_name(table) From 51303eb62ebc51bf08f8ddc5a5a22dbf4a258b74 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Sat, 2 Apr 2016 11:06:10 +0900 Subject: [PATCH 3/3] [ci skip] Update docs --- docs/conf.py | 77 +++++++++++++++++++++++---- docs/index.rst | 7 +-- docs/pages/examples/create_table.rst | 2 +- docs/pages/examples/insert_record.rst | 2 +- docs/pages/links.rst | 9 ++++ 5 files changed, 78 insertions(+), 19 deletions(-) create mode 100644 docs/pages/links.rst diff --git a/docs/conf.py b/docs/conf.py index 5f43e10..c4903f3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,8 +12,9 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys import os +import pkg_resources +import sys import sphinx_rtd_theme @@ -34,8 +35,10 @@ 'sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.viewcode', + 'sphinx.ext.intersphinx', ] +intersphinx_mapping = {'python': ('http://docs.python.org/', None)} # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -61,9 +64,9 @@ # built documents. # # The short X.Y version. -version = u'0.2.1' +version = pkg_resources.get_distribution("SimpleSQLite").version # The full version, including alpha/beta/rc tags. -release = u'0.2.1' +release = version # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -211,17 +214,17 @@ # -- Options for LaTeX output --------------------------------------------- latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', + # The paper size ('letterpaper' or 'a4paper'). + #'papersize': 'letterpaper', -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', + # The font size ('10pt', '11pt' or '12pt'). + #'pointsize': '10pt', -# Additional stuff for the LaTeX preamble. -#'preamble': '', + # Additional stuff for the LaTeX preamble. + #'preamble': '', -# Latex figure (float) alignment -#'figure_align': 'htbp', + # Latex figure (float) alignment + #'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples @@ -288,3 +291,55 @@ # If true, do not generate a @detailmenu in the "Top" node's menu. #texinfo_no_detailmenu = False + + +# ------------------------------------------------ + +rp_builtin = u""" +.. |False| replace:: :py:obj:`False` +.. |True| replace:: :py:obj:`True` +.. |None| replace:: :py:obj:`None` + +.. |bool| replace:: :py:class:`bool` +.. |dict| replace:: :py:class:`dict` +.. |int| replace:: :py:class:`int` +.. |list| replace:: :py:class:`list` +.. |float| replace:: :py:class:`float` +.. |str| replace:: :py:class:`str` +.. |tuple| replace:: :py:obj:`tuple` +""" + +rp_func = u""" +.. |namedtuple| replace:: :py:func:`~collections.namedtuple` +""" + +rp_class = u""" +.. |Connection| replace:: :py:class:`sqlite3.Connection` +.. |datetime| replace:: :py:class:`datetime.datetime` +.. |timedelta| replace:: :py:class:`datetime.timedelta` +""" + +rp_module = u""" +.. |sqlite3| replace:: :py:mod:`sqlite3` +""" + +rp_raises = u""" +.. |raises_check_connection| replace:: + If not connected to a SQLite database file. + +.. |raises_verify_table_existence| replace:: + If the table not found in the database. + +.. |raises_operational_error| replace:: + If failed to execute query. + +.. |raises_validate_table_name| replace:: + If the name is invalid for a SQLite table name. + +.. |raises_write_permission| replace:: + If the open |attr_mode| is neither ``"w"`` nor ``"a"``. +""" + +rst_prolog = rp_builtin + rp_func + rp_class + rp_module + rp_raises + u""" +.. |attr_mode| replace:: :py:attr:`.mode` +""" diff --git a/docs/index.rst b/docs/index.rst index 65698f6..ddc7f95 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -6,12 +6,6 @@ Welcome to SimpleSQLite's documentation! ======================================== -GitHub repository -================= - -https://github.com/thombashi/SimpleSQLite - - .. toctree:: :caption: Table of Contents :maxdepth: 3 @@ -22,6 +16,7 @@ https://github.com/thombashi/SimpleSQLite pages/examples/index pages/reference/index pages/genindex + pages/links Indices and tables diff --git a/docs/pages/examples/create_table.rst b/docs/pages/examples/create_table.rst index 7647ab4..a79e40b 100644 --- a/docs/pages/examples/create_table.rst +++ b/docs/pages/examples/create_table.rst @@ -6,7 +6,7 @@ Create a table from data matrix :py:meth:`~simplesqlite.core.SimpleSQLite.create_table_with_data` method can get create a table from data matrix. -Data matrix is a list of ``dictionary``/``namedtuple``/``list``/``tuple``. +Data matrix is a list of |dict|/|namedtuple|/|list|/|tuple|. .. include:: create_table_from_data_matrix.rst diff --git a/docs/pages/examples/insert_record.rst b/docs/pages/examples/insert_record.rst index 2e79090..ebf7cc6 100644 --- a/docs/pages/examples/insert_record.rst +++ b/docs/pages/examples/insert_record.rst @@ -3,6 +3,6 @@ Insert records into a table :py:meth:`~simplesqlite.core.SimpleSQLite.insert`/:py:meth:`~simplesqlite.core.SimpleSQLite.insert_many` method can insert record(s) into a table. -Record is one of the ``dictionary``/``namedtuple``/``list``/``tuple``. +Record is one of the |dict|/|namedtuple|/|list|/|tuple|. .. include:: insert_record_example.rst diff --git a/docs/pages/links.rst b/docs/pages/links.rst new file mode 100644 index 0000000..d2ee595 --- /dev/null +++ b/docs/pages/links.rst @@ -0,0 +1,9 @@ +Links +===== + +- pip: tool for installing python packages + - https://pip.pypa.io/en/stable/ +- GitHub repository + - https://github.com/thombashi/SimpleSQLite +- PyPI + - https://pypi.python.org/pypi/SimpleSQLite