And lint
This commit is contained in:
parent
bc06fc01ff
commit
54ab71f19c
21 changed files with 80 additions and 81 deletions
|
@ -1,13 +1,13 @@
|
|||
"""Quick and dirty migrations for AnoSQL."""
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from hashlib import sha256
|
||||
import logging
|
||||
import re
|
||||
import typing as t
|
||||
|
||||
import anosql
|
||||
from anosql.core import Queries, from_str
|
||||
from anosql.core import from_str, Queries
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -103,7 +103,7 @@ def create_tables(queries: Queries, conn) -> None:
|
|||
# Insert the bootstrap 'fixup' record
|
||||
execute_migration(queries, conn,
|
||||
MigrationDescriptor(
|
||||
name='anosql_migrations_create_table',
|
||||
name="anosql_migrations_create_table",
|
||||
sha256sum=sha256(queries.anosql_migrations_create_table.sql.encode("utf-8")).hexdigest()))
|
||||
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ from anosql.core import Queries
|
|||
import anosql_migrations
|
||||
import pytest
|
||||
|
||||
|
||||
_SQL = """\
|
||||
-- name: migration_0000_create_kv
|
||||
CREATE TABLE kv (`id` INT, `key` TEXT, `value` TEXT);
|
||||
|
@ -49,9 +50,9 @@ def test_queries(queries):
|
|||
"""Assert that we can construct a queries instance with migrations features."""
|
||||
|
||||
assert isinstance(queries, Queries)
|
||||
assert hasattr(queries, 'anosql_migrations_create_table')
|
||||
assert hasattr(queries, 'anosql_migrations_list')
|
||||
assert hasattr(queries, 'anosql_migrations_create')
|
||||
assert hasattr(queries, "anosql_migrations_create_table")
|
||||
assert hasattr(queries, "anosql_migrations_list")
|
||||
assert hasattr(queries, "anosql_migrations_create")
|
||||
|
||||
|
||||
def test_migrations_create_table(conn, queries):
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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"],
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import re
|
||||
|
||||
|
||||
query_name_definition_pattern = re.compile(r"--\s*name\s*:\s*")
|
||||
"""
|
||||
Pattern: Identifies name definition comments.
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import os
|
||||
from datetime import date
|
||||
import os
|
||||
|
||||
import anosql
|
||||
import psycopg2
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import os
|
|||
import anosql
|
||||
import pytest
|
||||
|
||||
|
||||
def dict_factory(cursor, row):
|
||||
d = {}
|
||||
for idx, col in enumerate(cursor.description):
|
||||
|
|
|
@ -3,21 +3,20 @@ Benchmarking the jobq.
|
|||
"""
|
||||
|
||||
from contextlib import contextmanager
|
||||
from time import perf_counter_ns
|
||||
from abc import abstractclassmethod
|
||||
import os
|
||||
from random import randint, choice
|
||||
import string
|
||||
from statistics import mean, median, stdev
|
||||
import tempfile
|
||||
import logging
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from random import choice, randint
|
||||
from statistics import mean, median, stdev
|
||||
import string
|
||||
import tempfile
|
||||
from time import perf_counter_ns
|
||||
|
||||
from jobq import JobQueue
|
||||
|
||||
|
||||
def randstr(len):
|
||||
return ''.join(choice(string.ascii_uppercase + string.digits) for _ in range(len))
|
||||
return "".join(choice(string.ascii_uppercase + string.digits) for _ in range(len))
|
||||
|
||||
|
||||
class Timing(object):
|
||||
|
@ -44,10 +43,10 @@ def timer(val: float) -> str:
|
|||
"""Given a time in NS, convert it to integral NS/MS/S such that the non-decimal part is integral."""
|
||||
|
||||
for factor, unit in [
|
||||
(1e9, 's'),
|
||||
(1e6, 'ms'),
|
||||
(1e3, 'us'),
|
||||
(1, 'ns'),
|
||||
(1e9, "s"),
|
||||
(1e6, "ms"),
|
||||
(1e3, "us"),
|
||||
(1, "ns"),
|
||||
]:
|
||||
scaled_val = val / factor
|
||||
if 1e4 > scaled_val > 1.0:
|
||||
|
|
|
@ -2,13 +2,11 @@
|
|||
A job queue library teetering atop sqlite3.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import sqlite3
|
||||
import json
|
||||
from typing import NamedTuple, Optional as Maybe
|
||||
from datetime import datetime
|
||||
import json
|
||||
import logging
|
||||
import sqlite3
|
||||
from typing import NamedTuple, Optional as Maybe
|
||||
|
||||
import anosql
|
||||
from anosql_migrations import run_migrations, with_migrations
|
||||
|
|
|
@ -8,6 +8,7 @@ from time import sleep
|
|||
from jobq import Job, JobQueue
|
||||
import pytest
|
||||
|
||||
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
|
@ -49,7 +50,7 @@ def test_poll(db):
|
|||
sleep(1) # And a side-effect for the third one
|
||||
j3 = db.create("payload 3")
|
||||
|
||||
j = db.poll('true', ["assigned"])
|
||||
j = db.poll("true", ["assigned"])
|
||||
|
||||
assert isinstance(j, Job)
|
||||
assert j.id == j1.id, "j1 is the oldest in the system and should poll first."
|
||||
|
@ -60,7 +61,7 @@ def test_poll_not_found(db):
|
|||
"""Test that poll can return nothing."""
|
||||
|
||||
j1 = db.create("payload 1")
|
||||
j = db.poll('false', ["assigned"])
|
||||
j = db.poll("false", ["assigned"])
|
||||
assert j is None
|
||||
|
||||
|
||||
|
|
|
@ -3,16 +3,11 @@ A job queue over HTTP.
|
|||
"""
|
||||
|
||||
import argparse
|
||||
from functools import wraps
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import sqlite3
|
||||
|
||||
from jobq import Job, JobQueue
|
||||
|
||||
from flask import abort, current_app, Flask, jsonify, request
|
||||
from jobq import Job, JobQueue
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from setuptools import setup
|
||||
|
||||
|
||||
with open("requirements.txt") as fp:
|
||||
requirements = [l.strip() for l in fp.readlines()]
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
"""The Lilith runner."""
|
||||
|
||||
import logging
|
||||
import argparse
|
||||
from importlib.resources import read_text as resource_text
|
||||
import logging
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ A quick and dirty recursive interpreter for Lilith.
|
|||
import logging
|
||||
import typing as t
|
||||
|
||||
from lilith.parser import Apply, Block, Symbol, Args
|
||||
from lilith.reader import Def, Module, Import
|
||||
from lilith.parser import Apply, Args, Block, Symbol
|
||||
from lilith.reader import Def, Import, Module
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
Variously poor parsing for Lilith.
|
||||
"""
|
||||
|
||||
import typing as t
|
||||
from importlib.resources import read_text
|
||||
import typing as t
|
||||
|
||||
from lark import Lark, Transformer, v_args
|
||||
|
||||
from lark import Lark, v_args, Transformer
|
||||
|
||||
GRAMMAR = read_text("lilith", "grammar.lark")
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@ import argparse
|
|||
import os
|
||||
from pprint import pprint
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
from gandi.client import GandiAPI
|
||||
import jinja2
|
||||
|
|
Loading…
Reference in a new issue