This commit is contained in:
Reid 'arrdem' McKenzie 2021-08-29 22:18:57 -06:00
commit 54ab71f19c
21 changed files with 80 additions and 81 deletions

View file

@ -21,6 +21,7 @@
# sys.path.insert(0, os.path.abspath('.'))
import pkg_resources
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
@ -33,32 +34,32 @@ import pkg_resources
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon"]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"
# The encoding of source files.
#
# source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
master_doc = "index"
# General information about the project.
project = u'anosql'
copyright = u'2014-2017, Honza Pokorny'
author = u'Honza Pokorny'
project = u"anosql"
copyright = u"2014-2017, Honza Pokorny"
author = u"Honza Pokorny"
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = pkg_resources.get_distribution('anosql').version
version = pkg_resources.get_distribution("anosql").version
# The full version, including alpha/beta/rc tags.
release = version
@ -81,7 +82,7 @@ language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
# The reST default role (used for this markup: `text`) to use for all
# documents.
@ -103,7 +104,7 @@ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"
# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
@ -120,7 +121,7 @@ todo_include_todos = False
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
@ -234,7 +235,7 @@ html_static_path = []
# html_search_scorer = 'scorer.js'
# Output file base name for HTML help builder.
htmlhelp_basename = 'anosqldoc'
htmlhelp_basename = "anosqldoc"
# -- Options for LaTeX output ---------------------------------------------
@ -260,8 +261,8 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'anosql.tex', u'anosql Documentation',
u'Honza Pokorny', 'manual'),
(master_doc, "anosql.tex", u"anosql Documentation",
u"Honza Pokorny", "manual"),
]
# The name of an image file (relative to this directory) to place at the top of
@ -302,7 +303,7 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'anosql', u'anosql Documentation',
(master_doc, "anosql", u"anosql Documentation",
[author], 1)
]
@ -317,9 +318,9 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'anosql', u'anosql Documentation',
author, 'anosql', 'One line description of project.',
'Miscellaneous'),
(master_doc, "anosql", u"anosql Documentation",
author, "anosql", "One line description of project.",
"Miscellaneous"),
]
# Documents to append as an appendix to all manuals.

View file

@ -1,4 +1,5 @@
from .core import from_path, from_str, SQLOperationType
from .exceptions import SQLLoadException, SQLParseException
__all__ = ["from_path", "from_str", "SQLOperationType", "SQLLoadException", "SQLParseException"]

View file

@ -5,15 +5,15 @@ from ..patterns import var_pattern
def replacer(match):
gd = match.groupdict()
if gd['dblquote'] is not None:
return gd['dblquote']
elif gd['quote'] is not None:
if gd["dblquote"] is not None:
return gd["dblquote"]
elif gd["quote"] is not None:
return gd["quote"]
else:
return '{lead}%({var_name})s{trail}'.format(
lead=gd['lead'],
var_name=gd['var_name'],
trail=gd['trail'],
return "{lead}%({var_name})s{trail}".format(
lead=gd["lead"],
var_name=gd["var_name"],
trail=gd["trail"],
)

View file

@ -6,6 +6,7 @@ from contextlib import contextmanager
import logging
import sqlite3
log = logging.getLogger(__name__)
@ -29,7 +30,7 @@ class SQLite3DriverAdapter(object):
@staticmethod
def select(conn, _query_name, sql, parameters):
cur = conn.cursor()
log.debug({'sql': sql, 'parameters': parameters})
log.debug({"sql": sql, "parameters": parameters})
cur.execute(sql, parameters)
results = cur.fetchall()
cur.close()
@ -39,7 +40,7 @@ class SQLite3DriverAdapter(object):
@contextmanager
def select_cursor(conn: sqlite3.Connection, _query_name, sql, parameters):
cur = conn.cursor()
log.debug({'sql': sql, 'parameters': parameters})
log.debug({"sql": sql, "parameters": parameters})
cur.execute(sql, parameters)
try:
yield cur
@ -48,18 +49,18 @@ class SQLite3DriverAdapter(object):
@staticmethod
def insert_update_delete(conn: sqlite3.Connection, _query_name, sql, parameters):
log.debug({'sql': sql, 'parameters': parameters})
log.debug({"sql": sql, "parameters": parameters})
conn.execute(sql, parameters)
@staticmethod
def insert_update_delete_many(conn: sqlite3.Connection, _query_name, sql, parameters):
log.debug({'sql': sql, 'parameters': parameters})
log.debug({"sql": sql, "parameters": parameters})
conn.executemany(sql, parameters)
@staticmethod
def insert_returning(conn: sqlite3.Connection, _query_name, sql, parameters):
cur = conn.cursor()
log.debug({'sql': sql, 'parameters': parameters})
log.debug({"sql": sql, "parameters": parameters})
cur.execute(sql, parameters)
if "returning" not in sql.lower():
@ -75,5 +76,5 @@ class SQLite3DriverAdapter(object):
@staticmethod
def execute_script(conn: sqlite3.Connection, sql):
log.debug({'sql': sql, 'parameters': None})
log.debug({"sql": sql, "parameters": None})
conn.executescript(sql)

View file

@ -4,10 +4,10 @@ from .adapters.psycopg2 import PsycoPG2Adapter
from .adapters.sqlite3 import SQLite3DriverAdapter
from .exceptions import SQLLoadException, SQLParseException
from .patterns import (
query_name_definition_pattern,
empty_pattern,
doc_comment_pattern,
valid_query_name_pattern,
doc_comment_pattern,
empty_pattern,
query_name_definition_pattern,
valid_query_name_pattern
)
@ -340,7 +340,7 @@ def from_path(sql_path, driver_name):
"""
if not os.path.exists(sql_path):
raise SQLLoadException('File does not exist: {}.'.format(sql_path), sql_path)
raise SQLLoadException("File does not exist: {}.".format(sql_path), sql_path)
driver_adapter = get_driver_adapter(driver_name)
@ -350,6 +350,6 @@ def from_path(sql_path, driver_name):
return Queries(load_queries_from_file(sql_path, driver_adapter))
else:
raise SQLLoadException(
'The sql_path must be a directory or file, got {}'.format(sql_path),
"The sql_path must be a directory or file, got {}".format(sql_path),
sql_path
)

View file

@ -1,5 +1,6 @@
import re
query_name_definition_pattern = re.compile(r"--\s*name\s*:\s*")
"""
Pattern: Identifies name definition comments.

View file

@ -4,6 +4,7 @@ import sqlite3
import pytest
BLOGDB_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "blogdb")
USERS_DATA_PATH = os.path.join(BLOGDB_PATH, "data", "users_data.csv")
BLOGS_DATA_PATH = os.path.join(BLOGDB_PATH, "data", "blogs_data.csv")

View file

@ -1,5 +1,5 @@
import os
from datetime import date
import os
import anosql
import psycopg2

View file

@ -1,12 +1,11 @@
import pytest
import anosql
import pytest
@pytest.fixture
def sqlite(request):
import sqlite3
sqlconnection = sqlite3.connect(':memory:')
sqlconnection = sqlite3.connect(":memory:")
def fin():
"teardown"
@ -80,7 +79,7 @@ def test_one_row(sqlite):
"-- name: two-rows?\n"
"SELECT 1 UNION SELECT 2;\n")
q = anosql.from_str(_test_one_row, "sqlite3")
assert q.one_row(sqlite) == (1, 'hello')
assert q.one_row(sqlite) == (1, "hello")
assert q.two_rows(sqlite) is None

View file

@ -3,6 +3,7 @@ import os
import anosql
import pytest
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):