From 630231ab63d5dec87c27ba528c8abc6bcdfa2bee Mon Sep 17 00:00:00 2001 From: Jacob Hinkle Date: Wed, 28 Sep 2022 13:51:22 -0400 Subject: [PATCH] Fix all linting errors --- src/nancy/cli/__init__.py | 2 +- src/nancy/cli/diff.py | 12 ++++++------ src/nancy/cli/record.py | 2 +- src/nancy/db.py | 4 ++-- src/nancy/environment.py | 1 - src/nancy/fs.py | 18 +++++------------- src/nancy/store.py | 7 +++---- src/nancy/user.py | 2 +- src/nancy/version.py | 2 +- 9 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/nancy/cli/__init__.py b/src/nancy/cli/__init__.py index 9a755fb..da6eaf0 100644 --- a/src/nancy/cli/__init__.py +++ b/src/nancy/cli/__init__.py @@ -29,7 +29,7 @@ def version(): @click.group( - cls=AliasedGroup, help=f"Composable provenance tracking for scientific data" + cls=AliasedGroup, help="Composable provenance tracking for scientific data" ) @click.option( "-L", diff --git a/src/nancy/cli/diff.py b/src/nancy/cli/diff.py index 02a15d3..6678dd9 100644 --- a/src/nancy/cli/diff.py +++ b/src/nancy/cli/diff.py @@ -1,7 +1,7 @@ import click from loguru import logger -from .. import db, fs +from .. import fs from ..store import find_store, Store import os @@ -15,7 +15,7 @@ def print_diff( """Pretty print an FSDiff object""" if use_color: try: - from colorama import init, Fore, Back, Style + from colorama import init, Fore, Back, Style # NOQA except ImportError: warnings.warn("Could not import colorama library. Color output disabled.") use_color = False @@ -63,14 +63,14 @@ def print_diff( relpath, ) - for l, d in ABdiff.flatten_tree(): + for lev, d in ABdiff.flatten_tree(): if d.A is None: assert d.B is not None - _print_row("NEW", d.B, l) + _print_row("NEW", d.B, lev) elif d.B is None: - _print_row("DEL", d.A, l) + _print_row("DEL", d.A, lev) elif d.A.sha256 != d.B.sha256: - _print_row("MOD", d.B, l) + _print_row("MOD", d.B, lev) @click.command() diff --git a/src/nancy/cli/record.py b/src/nancy/cli/record.py index 7426c8f..a4a4bd5 100644 --- a/src/nancy/cli/record.py +++ b/src/nancy/cli/record.py @@ -1,7 +1,7 @@ import click from loguru import logger -from .. import fs, store +from .. import store from .common import confirm from .diff import print_diff diff --git a/src/nancy/db.py b/src/nancy/db.py index a7f258a..d48c65c 100644 --- a/src/nancy/db.py +++ b/src/nancy/db.py @@ -1,6 +1,6 @@ import importlib.resources -import os import sqlite3 +import warnings # This will match the user_version in any nancy.db initialized by this process @@ -19,7 +19,7 @@ if ( or sub < min_sqlite_version[1] or minor < min_sqlite_version[2] ): - warning.warn( + warnings.warn( f"Minimum sqlite version is {min_sqlite_verstr}. Found {sqlite_verstr}" ) diff --git a/src/nancy/environment.py b/src/nancy/environment.py index 7bce5f3..429c9d9 100644 --- a/src/nancy/environment.py +++ b/src/nancy/environment.py @@ -5,7 +5,6 @@ import json import os import platform import sys -import time class Environment(NamedTuple): diff --git a/src/nancy/fs.py b/src/nancy/fs.py index 319b9cd..6e22c5c 100644 --- a/src/nancy/fs.py +++ b/src/nancy/fs.py @@ -2,12 +2,11 @@ from loguru import logger -from dataclasses import asdict, dataclass +from dataclasses import dataclass from datetime import datetime import hashlib import operator import os -from pathlib import Path import stat from typing import List import warnings @@ -295,22 +294,15 @@ class FSEntry: ) cursor.execute( - f""" - SELECT id, name, frozen - FROM filedir - WHERE parent=? - """, + "SELECT id, name, frozen FROM filedir WHERE parent=?", (root_id,), ) rows = cursor.fetchall() ob.children = [cls.from_db_index(cursor, root_row=r, parent=ob) for r in rows] # get all versions - fields = "" cursor.execute( - f""" - SELECT * FROM filedir_version WHERE filedir=? ORDER BY recorded_time - """, + "SELECT * FROM filedir_version WHERE filedir=? ORDER BY recorded_time", (root_id,), ) matches = cursor.fetchall() @@ -349,8 +341,8 @@ class FSEntry: # versions: [FSEntryVersion] = [] return "\n".join( - (" " * level) + l - for l in f"""id: {self.id} + (" " * level) + line + for line in f"""id: {self.id} filename: {self.filename} relpath: {self.relpath} parent (relpath): {'None' if self.parent is None else self.parent.relpath} diff --git a/src/nancy/store.py b/src/nancy/store.py index d0764ed..09dfd10 100644 --- a/src/nancy/store.py +++ b/src/nancy/store.py @@ -42,7 +42,7 @@ class Program: None, # end_time REAL, os.getpid(), # process_id INTEGER, -- host PID of python process on host OS env.id, # environment INTEGER NOT NULL, - self.message, # message TEXT, -- user-defined message to help distinguish similar runs + self.message, # user-defined message to help distinguish similar runs ), ) self.id = cur.lastrowid @@ -81,7 +81,8 @@ class Program: self._evaluated = True # prevent re-running elapsed = end_time - self.start_time logger.success( - f"Program [{self.id}] {self.name} (message:{self.message}) ran in {elapsed} seconds." + f"Program [{self.id}] {self.name} " + f"(message:{self.message}) ran in {elapsed} seconds." ) @@ -153,8 +154,6 @@ class Store: """Get the database id for the table entry in this store having name '.'""" if cur is None: cur = self.conn.cursor() - cur.execute("SELECT * FROM filedir") - allfiledir = cur.fetchall() cur.execute("SELECT id FROM filedir WHERE store=1 AND parent is NULL") (root_id,) = cur.fetchone() return root_id diff --git a/src/nancy/user.py b/src/nancy/user.py index f723883..cdb026e 100644 --- a/src/nancy/user.py +++ b/src/nancy/user.py @@ -1,4 +1,4 @@ -from . import machine, store +from . import machine import getpass import os diff --git a/src/nancy/version.py b/src/nancy/version.py index b739593..4913370 100644 --- a/src/nancy/version.py +++ b/src/nancy/version.py @@ -1,3 +1,3 @@ -from .db import schema_version +from .db import schema_version # NOQA __version__ = "0.1.0"