diff --git a/projects/anosql-migrations/src/python/anosql_migrations.py b/projects/anosql-migrations/src/python/anosql_migrations.py index f37e415..b7828e5 100644 --- a/projects/anosql-migrations/src/python/anosql_migrations.py +++ b/projects/anosql-migrations/src/python/anosql_migrations.py @@ -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())) diff --git a/projects/anosql-migrations/test/python/test_migrations.py b/projects/anosql-migrations/test/python/test_migrations.py index 7d9c55b..b4c6bae 100644 --- a/projects/anosql-migrations/test/python/test_migrations.py +++ b/projects/anosql-migrations/test/python/test_migrations.py @@ -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): diff --git a/projects/anosql/doc/conf.py b/projects/anosql/doc/conf.py index 1109268..490f820 100644 --- a/projects/anosql/doc/conf.py +++ b/projects/anosql/doc/conf.py @@ -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. diff --git a/projects/anosql/src/python/anosql/__init__.py b/projects/anosql/src/python/anosql/__init__.py index 6d24ca7..2e73a7f 100644 --- a/projects/anosql/src/python/anosql/__init__.py +++ b/projects/anosql/src/python/anosql/__init__.py @@ -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"] diff --git a/projects/anosql/src/python/anosql/adapters/psycopg2.py b/projects/anosql/src/python/anosql/adapters/psycopg2.py index 28346e0..fee36ea 100644 --- a/projects/anosql/src/python/anosql/adapters/psycopg2.py +++ b/projects/anosql/src/python/anosql/adapters/psycopg2.py @@ -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"], ) diff --git a/projects/anosql/src/python/anosql/adapters/sqlite3.py b/projects/anosql/src/python/anosql/adapters/sqlite3.py index d2e43dd..ea8cb06 100644 --- a/projects/anosql/src/python/anosql/adapters/sqlite3.py +++ b/projects/anosql/src/python/anosql/adapters/sqlite3.py @@ -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) diff --git a/projects/anosql/src/python/anosql/core.py b/projects/anosql/src/python/anosql/core.py index 954eda8..ecb4a78 100644 --- a/projects/anosql/src/python/anosql/core.py +++ b/projects/anosql/src/python/anosql/core.py @@ -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 ) diff --git a/projects/anosql/src/python/anosql/patterns.py b/projects/anosql/src/python/anosql/patterns.py index 0b8bedf..70c1288 100644 --- a/projects/anosql/src/python/anosql/patterns.py +++ b/projects/anosql/src/python/anosql/patterns.py @@ -1,5 +1,6 @@ import re + query_name_definition_pattern = re.compile(r"--\s*name\s*:\s*") """ Pattern: Identifies name definition comments. diff --git a/projects/anosql/test/python/conftest.py b/projects/anosql/test/python/conftest.py index b883854..df31a25 100644 --- a/projects/anosql/test/python/conftest.py +++ b/projects/anosql/test/python/conftest.py @@ -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") diff --git a/projects/anosql/test/python/test_psycopg2.py b/projects/anosql/test/python/test_psycopg2.py index 3fa5540..03f4ce3 100644 --- a/projects/anosql/test/python/test_psycopg2.py +++ b/projects/anosql/test/python/test_psycopg2.py @@ -1,5 +1,5 @@ -import os from datetime import date +import os import anosql import psycopg2 diff --git a/projects/anosql/test/python/test_simple.py b/projects/anosql/test/python/test_simple.py index 89a0ad8..d7afe37 100644 --- a/projects/anosql/test/python/test_simple.py +++ b/projects/anosql/test/python/test_simple.py @@ -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 diff --git a/projects/anosql/test/python/test_sqlite3.py b/projects/anosql/test/python/test_sqlite3.py index 8f89f71..677c33a 100644 --- a/projects/anosql/test/python/test_sqlite3.py +++ b/projects/anosql/test/python/test_sqlite3.py @@ -3,6 +3,7 @@ import os import anosql import pytest + def dict_factory(cursor, row): d = {} for idx, col in enumerate(cursor.description): diff --git a/projects/jobq/benchmark.py b/projects/jobq/benchmark.py index 63ae800..3646715 100644 --- a/projects/jobq/benchmark.py +++ b/projects/jobq/benchmark.py @@ -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: diff --git a/projects/jobq/src/python/jobq/__init__.py b/projects/jobq/src/python/jobq/__init__.py index 9da3116..9752f55 100644 --- a/projects/jobq/src/python/jobq/__init__.py +++ b/projects/jobq/src/python/jobq/__init__.py @@ -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 diff --git a/projects/jobq/test/python/test_jobq.py b/projects/jobq/test/python/test_jobq.py index 6026467..5779ff1 100644 --- a/projects/jobq/test/python/test_jobq.py +++ b/projects/jobq/test/python/test_jobq.py @@ -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 diff --git a/projects/jobqd/src/python/jobqd/__main__.py b/projects/jobqd/src/python/jobqd/__main__.py index 57e2d15..fbd99f8 100644 --- a/projects/jobqd/src/python/jobqd/__main__.py +++ b/projects/jobqd/src/python/jobqd/__main__.py @@ -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__) diff --git a/projects/lilith/setup.py b/projects/lilith/setup.py index 9644aa9..4c5f494 100644 --- a/projects/lilith/setup.py +++ b/projects/lilith/setup.py @@ -1,5 +1,6 @@ from setuptools import setup + with open("requirements.txt") as fp: requirements = [l.strip() for l in fp.readlines()] diff --git a/projects/lilith/src/python/lilith/__main__.py b/projects/lilith/src/python/lilith/__main__.py index 50ac271..cca9ade 100644 --- a/projects/lilith/src/python/lilith/__main__.py +++ b/projects/lilith/src/python/lilith/__main__.py @@ -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 diff --git a/projects/lilith/src/python/lilith/interpreter.py b/projects/lilith/src/python/lilith/interpreter.py index b0d4f43..91095e3 100644 --- a/projects/lilith/src/python/lilith/interpreter.py +++ b/projects/lilith/src/python/lilith/interpreter.py @@ -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__) diff --git a/projects/lilith/src/python/lilith/parser.py b/projects/lilith/src/python/lilith/parser.py index c6d2e97..4b00add 100644 --- a/projects/lilith/src/python/lilith/parser.py +++ b/projects/lilith/src/python/lilith/parser.py @@ -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") diff --git a/projects/public-dns/src/python/arrdem/updater/__main__.py b/projects/public-dns/src/python/arrdem/updater/__main__.py index 2d03421..b7b90c4 100644 --- a/projects/public-dns/src/python/arrdem/updater/__main__.py +++ b/projects/public-dns/src/python/arrdem/updater/__main__.py @@ -6,8 +6,6 @@ import argparse import os from pprint import pprint import re -import sys - from gandi.client import GandiAPI import jinja2