From b72499c84a3076503cd5fc8916f0d94f1fc7edb6 Mon Sep 17 00:00:00 2001 From: Raymond Berger Date: Wed, 22 May 2024 22:15:28 +0200 Subject: [PATCH] enable ruff rule to check for unused imports (#9182) * enable ruff rule to check for unused imports --- openlibrary/admin/numbers.py | 1 - openlibrary/code.py | 4 ++-- openlibrary/conftest.py | 12 +++++++++--- openlibrary/core/edits.py | 1 - openlibrary/core/follows.py | 3 +-- openlibrary/core/imports.py | 1 - openlibrary/core/lists/model.py | 4 +--- openlibrary/core/models.py | 7 ++----- openlibrary/core/processors/__init__.py | 2 +- openlibrary/core/sponsorships.py | 2 +- openlibrary/core/vendors.py | 1 - openlibrary/core/waitinglist.py | 1 - openlibrary/coverstore/archive.py | 1 - openlibrary/coverstore/code.py | 2 -- openlibrary/data/sitemap.py | 1 - openlibrary/i18n/__init__.py | 2 +- openlibrary/i18n/validators.py | 3 +-- openlibrary/plugins/admin/mem.py | 1 - openlibrary/plugins/books/readlinks.py | 1 - openlibrary/plugins/openlibrary/api.py | 6 +----- openlibrary/plugins/openlibrary/borrow_home.py | 3 +-- openlibrary/plugins/openlibrary/code.py | 10 +++++----- openlibrary/plugins/openlibrary/connection.py | 2 +- openlibrary/plugins/openlibrary/design.py | 3 +-- openlibrary/plugins/openlibrary/home.py | 1 - openlibrary/plugins/openlibrary/lists.py | 2 +- openlibrary/plugins/openlibrary/processors.py | 2 +- openlibrary/plugins/openlibrary/stats.py | 2 +- openlibrary/plugins/openlibrary/utils.py | 1 - openlibrary/plugins/upstream/account.py | 4 +--- openlibrary/plugins/upstream/addbook.py | 1 - openlibrary/plugins/upstream/addtag.py | 3 --- openlibrary/plugins/upstream/borrow.py | 4 ++-- openlibrary/plugins/upstream/checkins.py | 1 - openlibrary/plugins/upstream/code.py | 5 +---- openlibrary/plugins/upstream/covers.py | 1 - openlibrary/plugins/upstream/data.py | 1 - openlibrary/plugins/upstream/jsdef.py | 4 ---- openlibrary/plugins/upstream/models.py | 3 --- openlibrary/plugins/upstream/mybooks.py | 2 -- openlibrary/plugins/upstream/recentchanges.py | 1 - openlibrary/plugins/upstream/utils.py | 3 +-- openlibrary/plugins/worksearch/languages.py | 2 +- openlibrary/plugins/worksearch/publishers.py | 4 ++-- openlibrary/records/__init__.py | 2 -- openlibrary/records/functions.py | 2 -- openlibrary/records/matchers.py | 2 -- openlibrary/solr/data_provider.py | 2 +- openlibrary/solr/query_utils.py | 2 +- openlibrary/utils/sentry.py | 2 +- openlibrary/utils/solr.py | 2 +- pyproject.toml | 1 - scripts/affiliate_server.py | 2 -- scripts/delete_import_items.py | 3 +-- scripts/import_pressbooks.py | 1 - scripts/import_standard_ebooks.py | 1 - scripts/lc_marc_update.py | 1 - scripts/oldump.py | 2 +- scripts/openlibrary-server | 2 +- scripts/partner_batch_imports.py | 1 - scripts/promise_batch_imports.py | 3 +-- scripts/pull-templates.py | 2 +- scripts/solr_updater.py | 3 +-- scripts/store_counts.py | 2 +- scripts/tests/test_affiliate_server.py | 1 - scripts/update_stale_work_references.py | 3 --- 66 files changed, 50 insertions(+), 113 deletions(-) diff --git a/openlibrary/admin/numbers.py b/openlibrary/admin/numbers.py index b11692e696c..0209aa4f0d8 100644 --- a/openlibrary/admin/numbers.py +++ b/openlibrary/admin/numbers.py @@ -22,7 +22,6 @@ import functools import logging -import web logger = logging.getLogger(__name__) diff --git a/openlibrary/code.py b/openlibrary/code.py index 773cff8509e..086cdbcce10 100644 --- a/openlibrary/code.py +++ b/openlibrary/code.py @@ -46,7 +46,7 @@ def setup(): load_views() # load actions - from . import actions + from . import actions # noqa: F401 logger.info("loading complete.") @@ -64,7 +64,7 @@ def setup_logging(): def load_views(): """Registers all views by loading all view modules.""" - from .views import showmarc + from .views import showmarc # noqa: F401 setup() diff --git a/openlibrary/conftest.py b/openlibrary/conftest.py index b97b9ef5985..e0824b08d23 100644 --- a/openlibrary/conftest.py +++ b/openlibrary/conftest.py @@ -10,9 +10,15 @@ from openlibrary.i18n import gettext from openlibrary.core import helpers -from openlibrary.mocks.mock_infobase import mock_site -from openlibrary.mocks.mock_ia import mock_ia -from openlibrary.mocks.mock_memcache import mock_memcache +from openlibrary.mocks.mock_infobase import ( + mock_site, # noqa: F401 needed for tests +) +from openlibrary.mocks.mock_ia import ( + mock_ia, # noqa: F401 needed for tests +) +from openlibrary.mocks.mock_memcache import ( + mock_memcache, # noqa: F401 needed for tests +) @pytest.fixture(autouse=True) diff --git a/openlibrary/core/edits.py b/openlibrary/core/edits.py index 1c9d40603e6..368f3884961 100644 --- a/openlibrary/core/edits.py +++ b/openlibrary/core/edits.py @@ -1,6 +1,5 @@ import datetime import json -import web from sqlite3 import IntegrityError from psycopg2.errors import UniqueViolation diff --git a/openlibrary/core/follows.py b/openlibrary/core/follows.py index 646f009c57e..c021d791ad9 100644 --- a/openlibrary/core/follows.py +++ b/openlibrary/core/follows.py @@ -1,6 +1,5 @@ import logging -import web -from typing import cast, Any +from typing import cast from openlibrary.core.bookshelves import Bookshelves from . import db diff --git a/openlibrary/core/imports.py b/openlibrary/core/imports.py index e34b8a4daed..bb8d4039929 100644 --- a/openlibrary/core/imports.py +++ b/openlibrary/core/imports.py @@ -14,7 +14,6 @@ from psycopg2.errors import UndefinedTable, UniqueViolation from pydantic import ValidationError from web.db import ResultSet -from web.utils import Storage from . import db diff --git a/openlibrary/core/lists/model.py b/openlibrary/core/lists/model.py index 64a93cd7e45..4610e2b8efb 100644 --- a/openlibrary/core/lists/model.py +++ b/openlibrary/core/lists/model.py @@ -8,9 +8,7 @@ import web import logging -from infogami import config -from infogami.infobase import client, common -from infogami.utils import stats +from infogami.infobase import client from openlibrary.core import helpers as h from openlibrary.core import cache diff --git a/openlibrary/core/models.py b/openlibrary/core/models.py index c0d40323818..4dd0436803f 100644 --- a/openlibrary/core/models.py +++ b/openlibrary/core/models.py @@ -19,22 +19,19 @@ # TODO: fix this. openlibrary.core should not import plugins. from openlibrary import accounts from openlibrary.core import lending -from openlibrary.catalog import add_book from openlibrary.core.booknotes import Booknotes from openlibrary.core.bookshelves import Bookshelves -from openlibrary.core.follows import PubSub from openlibrary.core.helpers import private_collection_in from openlibrary.core.imports import ImportItem from openlibrary.core.observations import Observations from openlibrary.core.ratings import Ratings -from openlibrary.utils import extract_numeric_id_from_olid, dateutil +from openlibrary.utils import extract_numeric_id_from_olid from openlibrary.utils.isbn import to_isbn_13, isbn_13_to_isbn_10, canonical from openlibrary.core.wikidata import WikidataEntity, get_wikidata_entity from . import cache, waitinglist from urllib.parse import urlencode -from pydantic import ValidationError from .ia import get_metadata from .waitinglist import WaitingLoan @@ -995,7 +992,7 @@ def get_loan_for(self, ocaid, use_cache=False): Returns None if this user hasn't borrowed the given book. """ - from ..plugins.upstream import borrow + from ..plugins.upstream import borrow # noqa: F401 loans = ( lending.get_cached_loans_of_user(self.key) diff --git a/openlibrary/core/processors/__init__.py b/openlibrary/core/processors/__init__.py index 01fd63f75c2..b3ee5d6a6d9 100644 --- a/openlibrary/core/processors/__init__.py +++ b/openlibrary/core/processors/__init__.py @@ -1 +1 @@ -from openlibrary.core.processors.readableurls import ReadableUrlProcessor +from openlibrary.core.processors.readableurls import ReadableUrlProcessor # noqa: F401 diff --git a/openlibrary/core/sponsorships.py b/openlibrary/core/sponsorships.py index 5aef89b2b0d..5b7cecc7ab5 100644 --- a/openlibrary/core/sponsorships.py +++ b/openlibrary/core/sponsorships.py @@ -10,7 +10,7 @@ from openlibrary.core import lending from openlibrary.core.vendors import get_betterworldbooks_metadata, get_amazon_metadata from openlibrary import accounts -from openlibrary.accounts.model import get_internet_archive_id, sendmail +from openlibrary.accounts.model import get_internet_archive_id from openlibrary.core.civicrm import ( get_contact_id_by_username, get_sponsorships_by_contact_id, diff --git a/openlibrary/core/vendors.py b/openlibrary/core/vendors.py index 743900108fb..fcf3ba89ad1 100644 --- a/openlibrary/core/vendors.py +++ b/openlibrary/core/vendors.py @@ -3,7 +3,6 @@ import re import time -from datetime import date from typing import Any, Literal import requests diff --git a/openlibrary/core/waitinglist.py b/openlibrary/core/waitinglist.py index 6cf941207a7..d68d0798db2 100644 --- a/openlibrary/core/waitinglist.py +++ b/openlibrary/core/waitinglist.py @@ -17,7 +17,6 @@ import logging import web from openlibrary.accounts.model import OpenLibraryAccount -from openlibrary.core import cache from . import helpers as h from .sendmail import sendmail_with_template from . import db diff --git a/openlibrary/coverstore/archive.py b/openlibrary/coverstore/archive.py index f65394f42ef..8fbdcce3abd 100644 --- a/openlibrary/coverstore/archive.py +++ b/openlibrary/coverstore/archive.py @@ -13,7 +13,6 @@ from infogami.infobase import utils from openlibrary.coverstore import config, db -from openlibrary.coverstore.coverlib import find_image_path from scripts.solr_builder.solr_builder.fn_to_cli import FnToCLI diff --git a/openlibrary/coverstore/code.py b/openlibrary/coverstore/code.py index 351be881e56..7ca80db92bb 100644 --- a/openlibrary/coverstore/code.py +++ b/openlibrary/coverstore/code.py @@ -20,8 +20,6 @@ download, ol_get, ol_things, - random_string, - rm_f, safeint, ) from openlibrary.plugins.openlibrary.processors import CORSProcessor diff --git a/openlibrary/data/sitemap.py b/openlibrary/data/sitemap.py index b0f92f17343..9bccb42e1f4 100644 --- a/openlibrary/data/sitemap.py +++ b/openlibrary/data/sitemap.py @@ -19,7 +19,6 @@ import datetime from gzip import open as gzopen -from openlibrary.plugins.openlibrary.processors import urlsafe t = web.template.Template diff --git a/openlibrary/i18n/__init__.py b/openlibrary/i18n/__init__.py index 6274753df76..0471342888c 100644 --- a/openlibrary/i18n/__init__.py +++ b/openlibrary/i18n/__init__.py @@ -14,7 +14,7 @@ from babel.messages import Catalog, Message from babel.messages.pofile import read_po, write_po from babel.messages.mofile import write_mo -from babel.messages.extract import extract_from_file, extract_from_dir, extract_python +from babel.messages.extract import extract_from_dir, extract_python from .validators import validate diff --git a/openlibrary/i18n/validators.py b/openlibrary/i18n/validators.py index d3cb7980d76..7ee559ae53b 100644 --- a/openlibrary/i18n/validators.py +++ b/openlibrary/i18n/validators.py @@ -1,8 +1,7 @@ from itertools import groupby import re -from babel.messages.catalog import TranslationError, Message, Catalog -from babel.messages.checkers import python_format +from babel.messages.catalog import Message, Catalog def validate(message: Message, catalog: Catalog) -> list[str]: diff --git a/openlibrary/plugins/admin/mem.py b/openlibrary/plugins/admin/mem.py index f618da71577..83dee5e1296 100644 --- a/openlibrary/plugins/admin/mem.py +++ b/openlibrary/plugins/admin/mem.py @@ -1,4 +1,3 @@ -from infogami.utils import delegate from infogami.utils.view import render, safeint from openlibrary.plugins.admin import memory import web diff --git a/openlibrary/plugins/books/readlinks.py b/openlibrary/plugins/books/readlinks.py index e66ab6abfc4..d500a156615 100644 --- a/openlibrary/plugins/books/readlinks.py +++ b/openlibrary/plugins/books/readlinks.py @@ -10,7 +10,6 @@ import web from openlibrary.core import ia from openlibrary.core import helpers -from openlibrary.api import OpenLibrary from openlibrary.plugins.books import dynlinks from infogami.utils.delegate import register_exception from infogami.utils import stats diff --git a/openlibrary/plugins/openlibrary/api.py b/openlibrary/plugins/openlibrary/api.py index 4ed5c140cba..14a7c80f0f9 100644 --- a/openlibrary/plugins/openlibrary/api.py +++ b/openlibrary/plugins/openlibrary/api.py @@ -9,18 +9,14 @@ import json from collections import defaultdict from openlibrary.views.loanstats import get_trending_books -from infogami import config from infogami.utils import delegate from infogami.utils.view import render_template # noqa: F401 used for its side effects from infogami.plugins.api.code import jsonapi -from infogami.utils.view import add_flash_message from openlibrary import accounts from openlibrary.plugins.openlibrary.code import can_write from openlibrary.utils import extract_numeric_id_from_olid from openlibrary.utils.isbn import isbn_10_to_isbn_13, normalize_isbn -from openlibrary.plugins.worksearch.subjects import get_subject -from openlibrary.accounts.model import OpenLibraryAccount -from openlibrary.core import ia, db, models, lending, helpers as h +from openlibrary.core import models, lending, helpers as h from openlibrary.core.bookshelves_events import BookshelvesEvents from openlibrary.core.observations import Observations, get_observation_metrics from openlibrary.core.models import Booknotes, Work diff --git a/openlibrary/plugins/openlibrary/borrow_home.py b/openlibrary/plugins/openlibrary/borrow_home.py index f1d02d5504b..afcfc396b3a 100644 --- a/openlibrary/plugins/openlibrary/borrow_home.py +++ b/openlibrary/plugins/openlibrary/borrow_home.py @@ -13,8 +13,7 @@ import eventer from infogami.utils import delegate -from infogami.utils.view import render_template # used for its side effects - +from infogami.utils.view import render_template # noqa: F401 used for its side effects from openlibrary.core import statsdb diff --git a/openlibrary/plugins/openlibrary/code.py b/openlibrary/plugins/openlibrary/code.py index 63cdec5c3e4..d1ca098b581 100644 --- a/openlibrary/plugins/openlibrary/code.py +++ b/openlibrary/plugins/openlibrary/code.py @@ -2,7 +2,7 @@ Open Library Plugin. """ -from urllib.parse import parse_qs, urlparse, urlencode, urlunparse +from urllib.parse import parse_qs, urlencode import requests import web import json @@ -13,7 +13,6 @@ import logging from time import time import math -from pathlib import Path import infogami # make sure infogami.config.features is set @@ -34,7 +33,6 @@ from infogami.core.db import ValidationException from openlibrary.core import cache -from openlibrary.core.vendors import create_edition_from_amazon_metadata from openlibrary.utils.isbn import isbn_13_to_isbn_10, isbn_10_to_isbn_13, canonical from openlibrary.core.models import Edition from openlibrary.core.lending import get_availability @@ -293,7 +291,7 @@ def POST(self): class clonebook(delegate.page): def GET(self): - from infogami.core.code import edit + from infogami.core.code import edit # noqa: F401 not sure why, probably needed i = web.input('key') page = web.ctx.site.get(i.key) @@ -1178,7 +1176,9 @@ def setup(): authors.setup() swagger.setup() - from openlibrary.plugins.openlibrary import api + from openlibrary.plugins.openlibrary import ( + api, # noqa: F401 not sure why but could be needed + ) delegate.app.add_processor(web.unloadhook(stats.stats_hook)) diff --git a/openlibrary/plugins/openlibrary/connection.py b/openlibrary/plugins/openlibrary/connection.py index d05acc3aaf7..5e51cb15170 100644 --- a/openlibrary/plugins/openlibrary/connection.py +++ b/openlibrary/plugins/openlibrary/connection.py @@ -2,7 +2,7 @@ """ from infogami import config -from infogami.infobase import client, lru +from infogami.infobase import client from infogami.utils import stats import web diff --git a/openlibrary/plugins/openlibrary/design.py b/openlibrary/plugins/openlibrary/design.py index 71c67a5aa25..0ccdc6bc01b 100644 --- a/openlibrary/plugins/openlibrary/design.py +++ b/openlibrary/plugins/openlibrary/design.py @@ -1,8 +1,7 @@ -import web import logging from infogami.utils import delegate -from infogami.utils.view import render_template, public +from infogami.utils.view import render_template logger = logging.getLogger("openlibrary.design") diff --git a/openlibrary/plugins/openlibrary/home.py b/openlibrary/plugins/openlibrary/home.py index b2bca58ee28..b805df19967 100644 --- a/openlibrary/plugins/openlibrary/home.py +++ b/openlibrary/plugins/openlibrary/home.py @@ -8,7 +8,6 @@ from infogami.utils import delegate from infogami.utils.view import render_template, public from infogami.infobase.client import storify -from infogami import config from openlibrary.core import admin, cache, ia, lending from openlibrary.i18n import gettext as _ diff --git a/openlibrary/plugins/openlibrary/lists.py b/openlibrary/plugins/openlibrary/lists.py index c2da27a6b9e..a2f8ea4ef14 100644 --- a/openlibrary/plugins/openlibrary/lists.py +++ b/openlibrary/plugins/openlibrary/lists.py @@ -24,7 +24,7 @@ import openlibrary.core.helpers as h from openlibrary.i18n import gettext as _ from openlibrary.plugins.upstream.addbook import safe_seeother -from openlibrary.utils import dateutil, olid_to_key +from openlibrary.utils import olid_to_key from openlibrary.plugins.upstream import spamcheck, utils from openlibrary.plugins.upstream.account import MyBooksTemplate from openlibrary.plugins.worksearch import subjects diff --git a/openlibrary/plugins/openlibrary/processors.py b/openlibrary/plugins/openlibrary/processors.py index 4d6ebd600ce..9cc07418bd4 100644 --- a/openlibrary/plugins/openlibrary/processors.py +++ b/openlibrary/plugins/openlibrary/processors.py @@ -6,7 +6,7 @@ from openlibrary.accounts import get_current_user from openlibrary.core import cache -from openlibrary.core.processors import ReadableUrlProcessor +from openlibrary.core.processors import ReadableUrlProcessor # noqa: F401 from openlibrary.plugins.openlibrary.home import caching_prethread from openlibrary.utils import dateutil diff --git a/openlibrary/plugins/openlibrary/stats.py b/openlibrary/plugins/openlibrary/stats.py index effe7d5e3ac..59e9584cb3f 100644 --- a/openlibrary/plugins/openlibrary/stats.py +++ b/openlibrary/plugins/openlibrary/stats.py @@ -14,7 +14,7 @@ from openlibrary.core import stats as graphite_stats import web from infogami import config -from infogami.utils import delegate, stats +from infogami.utils import stats import openlibrary.plugins.openlibrary.filters as stats_filters diff --git a/openlibrary/plugins/openlibrary/utils.py b/openlibrary/plugins/openlibrary/utils.py index 79be1b0b2dd..e69de29bb2d 100644 --- a/openlibrary/plugins/openlibrary/utils.py +++ b/openlibrary/plugins/openlibrary/utils.py @@ -1 +0,0 @@ -from openlibrary.core.helpers import sanitize diff --git a/openlibrary/plugins/upstream/account.py b/openlibrary/plugins/upstream/account.py index 513dbf50cd7..202280c9bbb 100644 --- a/openlibrary/plugins/upstream/account.py +++ b/openlibrary/plugins/upstream/account.py @@ -18,7 +18,7 @@ add_flash_message, ) from infogami.infobase.client import ClientException -import infogami.core.code as core +import infogami.core.code as core # noqa: F401 definitely needed from openlibrary import accounts from openlibrary.i18n import gettext as _ @@ -39,7 +39,6 @@ from openlibrary.plugins import openlibrary as olib from openlibrary.accounts import ( audit_accounts, - Account, OpenLibraryAccount, InternetArchiveAccount, valid_email, @@ -346,7 +345,6 @@ def POST(self): payload is json. Instead, if login attempted w/ json credentials, requires Archive.org s3 keys. """ - from openlibrary.plugins.openlibrary.code import BadRequest d = json.loads(web.data()) email = d.get('email', "") diff --git a/openlibrary/plugins/upstream/addbook.py b/openlibrary/plugins/upstream/addbook.py index cc70e6dc5c8..d9bdfa8cba9 100644 --- a/openlibrary/plugins/upstream/addbook.py +++ b/openlibrary/plugins/upstream/addbook.py @@ -16,7 +16,6 @@ from openlibrary.plugins.worksearch.search import get_solr from openlibrary.core.helpers import uniq -from openlibrary.i18n import gettext as _ from openlibrary import accounts import logging diff --git a/openlibrary/plugins/upstream/addtag.py b/openlibrary/plugins/upstream/addtag.py index 7b3199e140e..f891ea7e488 100644 --- a/openlibrary/plugins/upstream/addtag.py +++ b/openlibrary/plugins/upstream/addtag.py @@ -1,7 +1,6 @@ """Handlers for adding and editing tags.""" import web -import json from typing import NoReturn @@ -11,8 +10,6 @@ from infogami.infobase.client import ClientException from infogami.utils import delegate -from openlibrary.plugins.openlibrary.processors import urlsafe -from openlibrary.i18n import gettext as _ import logging from openlibrary.plugins.upstream import spamcheck, utils diff --git a/openlibrary/plugins/upstream/borrow.py b/openlibrary/plugins/upstream/borrow.py index 0dbe4408687..6af64976ce4 100644 --- a/openlibrary/plugins/upstream/borrow.py +++ b/openlibrary/plugins/upstream/borrow.py @@ -15,10 +15,10 @@ from infogami import config from infogami.utils import delegate -from infogami.utils.view import public, render_template, add_flash_message +from infogami.utils.view import public, add_flash_message +from infogami.utils.view import render_template # noqa: F401 used for its side effects from infogami.infobase.utils import parse_datetime -from openlibrary.core import models from openlibrary.core import stats from openlibrary.core import lending from openlibrary.core import vendors diff --git a/openlibrary/plugins/upstream/checkins.py b/openlibrary/plugins/upstream/checkins.py index 95fbb766a94..5b74b268de2 100644 --- a/openlibrary/plugins/upstream/checkins.py +++ b/openlibrary/plugins/upstream/checkins.py @@ -15,7 +15,6 @@ from openlibrary.core.yearly_reading_goals import YearlyReadingGoals from openlibrary.utils import extract_numeric_id_from_olid from openlibrary.core.bookshelves_events import BookshelfEvent, BookshelvesEvents -from openlibrary.utils.decorators import authorized_for def make_date_string(year: int, month: int | None, day: int | None) -> str: diff --git a/openlibrary/plugins/upstream/code.py b/openlibrary/plugins/upstream/code.py index 64a5199f188..00d855a875a 100644 --- a/openlibrary/plugins/upstream/code.py +++ b/openlibrary/plugins/upstream/code.py @@ -14,19 +14,16 @@ from infogami.plugins.api.code import request as infogami_request from infogami.infobase import client -from infogami.utils import delegate, app, types +from infogami.utils import delegate from infogami.utils.view import public, safeint, render from infogami.utils.view import render_template # used for its side effects -from infogami.utils.context import context -from openlibrary import accounts from openlibrary.plugins.upstream import addbook, addtag, covers, models, utils from openlibrary.plugins.upstream import spamcheck from openlibrary.plugins.upstream import merge_authors from openlibrary.plugins.upstream import edits from openlibrary.plugins.upstream import checkins -from openlibrary.plugins.upstream import borrow, recentchanges # TODO: unused imports? from openlibrary.plugins.upstream.utils import render_component if not config.get('coverstore_url'): diff --git a/openlibrary/plugins/upstream/covers.py b/openlibrary/plugins/upstream/covers.py index 6f382acc0bc..4dbb3bd07b1 100644 --- a/openlibrary/plugins/upstream/covers.py +++ b/openlibrary/plugins/upstream/covers.py @@ -5,7 +5,6 @@ import requests import web -from io import BytesIO from infogami.utils import delegate from infogami.utils.view import safeint diff --git a/openlibrary/plugins/upstream/data.py b/openlibrary/plugins/upstream/data.py index 46d99ccbd87..f912fa6ba32 100644 --- a/openlibrary/plugins/upstream/data.py +++ b/openlibrary/plugins/upstream/data.py @@ -4,7 +4,6 @@ import web from infogami import config from infogami.utils import delegate -from infogami.utils.view import public import requests diff --git a/openlibrary/plugins/upstream/jsdef.py b/openlibrary/plugins/upstream/jsdef.py index 2c5978b7eff..feb6f873a51 100644 --- a/openlibrary/plugins/upstream/jsdef.py +++ b/openlibrary/plugins/upstream/jsdef.py @@ -57,10 +57,6 @@ import web from web.template import ( - Template, - Parser, - LineNode, - SuiteNode, DefNode, PythonTokenizer, # INDENT, diff --git a/openlibrary/plugins/upstream/models.py b/openlibrary/plugins/upstream/models.py index 671526a7ab9..b0355032ea8 100644 --- a/openlibrary/plugins/upstream/models.py +++ b/openlibrary/plugins/upstream/models.py @@ -8,7 +8,6 @@ from collections import defaultdict from isbnlib import canonical, mask, NotValidISBNError -from infogami import config from infogami.infobase import client from infogami.utils.view import safeint from infogami.utils import stats @@ -18,12 +17,10 @@ from openlibrary.core import lending from openlibrary.plugins.upstream.utils import MultiDict, parse_toc, get_edition_config -from openlibrary.plugins.upstream import account from openlibrary.plugins.upstream import borrow from openlibrary.plugins.worksearch.code import works_by_author from openlibrary.plugins.worksearch.search import get_solr -from openlibrary.utils import dateutil from openlibrary.utils.isbn import isbn_10_to_isbn_13, isbn_13_to_isbn_10 from openlibrary.utils.lccn import normalize_lccn diff --git a/openlibrary/plugins/upstream/mybooks.py b/openlibrary/plugins/upstream/mybooks.py index db241f0dd1f..0df7eaf6383 100644 --- a/openlibrary/plugins/upstream/mybooks.py +++ b/openlibrary/plugins/upstream/mybooks.py @@ -3,14 +3,12 @@ from typing import Final, Literal, cast -from infogami import config from infogami.utils import delegate from infogami.utils.view import public, safeint, render from openlibrary.i18n import gettext as _ from openlibrary import accounts -from openlibrary.accounts.model import OpenLibraryAccount from openlibrary.utils import extract_numeric_id_from_olid from openlibrary.utils.dateutil import current_year from openlibrary.core.booknotes import Booknotes diff --git a/openlibrary/plugins/upstream/recentchanges.py b/openlibrary/plugins/upstream/recentchanges.py index 6db3ff83d9e..83c461c156a 100644 --- a/openlibrary/plugins/upstream/recentchanges.py +++ b/openlibrary/plugins/upstream/recentchanges.py @@ -9,7 +9,6 @@ from infogami.utils import delegate from infogami.utils.view import public, render, render_template, safeint -from infogami.utils.view import add_flash_message # TODO: unused import? from infogami.utils import features from openlibrary.utils import dateutil diff --git a/openlibrary/plugins/upstream/utils.py b/openlibrary/plugins/upstream/utils.py index abc2055539a..01e8e3397f7 100644 --- a/openlibrary/plugins/upstream/utils.py +++ b/openlibrary/plugins/upstream/utils.py @@ -16,7 +16,6 @@ import datetime import logging from html.parser import HTMLParser -from pathlib import Path import requests @@ -32,7 +31,7 @@ from infogami import config from infogami.utils import view, delegate, stats -from infogami.utils.view import render, get_template, public, query_param +from infogami.utils.view import render, get_template, public from infogami.utils.macro import macro from infogami.utils.context import InfogamiContext, context from infogami.infobase.client import Changeset, Nothing, Thing, storify diff --git a/openlibrary/plugins/worksearch/languages.py b/openlibrary/plugins/worksearch/languages.py index 3a5a89dffbc..98489460f85 100644 --- a/openlibrary/plugins/worksearch/languages.py +++ b/openlibrary/plugins/worksearch/languages.py @@ -2,7 +2,7 @@ """ from infogami.plugins.api.code import jsonapi -from infogami.utils import delegate, stats +from infogami.utils import delegate from infogami.utils.view import render_template, safeint import web import json diff --git a/openlibrary/plugins/worksearch/publishers.py b/openlibrary/plugins/worksearch/publishers.py index 44f62a21409..eac1b5c40ac 100644 --- a/openlibrary/plugins/worksearch/publishers.py +++ b/openlibrary/plugins/worksearch/publishers.py @@ -1,8 +1,8 @@ """Publisher pages """ -from infogami.utils import delegate, stats -from infogami.utils.view import render_template, safeint +from infogami.utils import delegate +from infogami.utils.view import render_template import web import logging diff --git a/openlibrary/records/__init__.py b/openlibrary/records/__init__.py index 3b2bc89d01c..e69de29bb2d 100644 --- a/openlibrary/records/__init__.py +++ b/openlibrary/records/__init__.py @@ -1,2 +0,0 @@ -from .driver import search -from .functions import create diff --git a/openlibrary/records/functions.py b/openlibrary/records/functions.py index 395ff52c604..0a9ad660fa4 100644 --- a/openlibrary/records/functions.py +++ b/openlibrary/records/functions.py @@ -7,9 +7,7 @@ import web -from openlibrary.catalog.add_book import normalize from openlibrary.core.models import Thing -import openlibrary.core.helpers as h class NoQueryParam(KeyError): diff --git a/openlibrary/records/matchers.py b/openlibrary/records/matchers.py index 57e544a5855..c9d0598b26f 100644 --- a/openlibrary/records/matchers.py +++ b/openlibrary/records/matchers.py @@ -23,8 +23,6 @@ from collections import defaultdict import logging as Logging -from infogami import config -from openlibrary.utils.solr import Solr import web diff --git a/openlibrary/solr/data_provider.py b/openlibrary/solr/data_provider.py index a718b0b80d7..91e0b61c83c 100644 --- a/openlibrary/solr/data_provider.py +++ b/openlibrary/solr/data_provider.py @@ -10,7 +10,7 @@ import itertools import logging import re -from typing import Optional, TypedDict, cast +from typing import TypedDict, cast from collections.abc import Iterable, Sized import httpx diff --git a/openlibrary/solr/query_utils.py b/openlibrary/solr/query_utils.py index 1d180104e19..b2d9f6f76a5 100644 --- a/openlibrary/solr/query_utils.py +++ b/openlibrary/solr/query_utils.py @@ -1,4 +1,4 @@ -from typing import Literal, Optional +from typing import Literal from collections.abc import Callable from luqum.parser import parser from luqum.tree import Item, SearchField, BaseOperation, Group, Word, Unary diff --git a/openlibrary/utils/sentry.py b/openlibrary/utils/sentry.py index f1f20978cb2..4b6326e542b 100644 --- a/openlibrary/utils/sentry.py +++ b/openlibrary/utils/sentry.py @@ -6,7 +6,7 @@ import web from sentry_sdk.utils import capture_internal_exceptions from sentry_sdk.tracing import Transaction, TRANSACTION_SOURCE_ROUTE -from infogami.utils.app import find_page, find_view, modes +from infogami.utils.app import find_page, modes from infogami.utils.types import type_patterns from openlibrary.utils import get_software_version diff --git a/openlibrary/utils/solr.py b/openlibrary/utils/solr.py index 3f8f06d514b..cda6508d7d0 100644 --- a/openlibrary/utils/solr.py +++ b/openlibrary/utils/solr.py @@ -2,7 +2,7 @@ import logging import re -from typing import Optional, TypeVar +from typing import TypeVar from collections.abc import Callable, Iterable import requests diff --git a/pyproject.toml b/pyproject.toml index 7af3cddcc53..0f3936f5690 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,6 @@ ignore = [ "B904", "B905", "E402", - "F401", "F841", "I", "PERF401", diff --git a/scripts/affiliate_server.py b/scripts/affiliate_server.py index 195ed85e2d8..4659ac9b5f7 100644 --- a/scripts/affiliate_server.py +++ b/scripts/affiliate_server.py @@ -61,8 +61,6 @@ from openlibrary.utils.dateutil import WEEK_SECS from openlibrary.utils.isbn import ( normalize_identifier, - normalize_isbn, - isbn_13_to_isbn_10, isbn_10_to_isbn_13, ) diff --git a/scripts/delete_import_items.py b/scripts/delete_import_items.py index 1a2f3e3563a..52bc6c2a9cb 100644 --- a/scripts/delete_import_items.py +++ b/scripts/delete_import_items.py @@ -21,11 +21,10 @@ from configparser import ConfigParser from pathlib import Path -import _init_path # Imported for its side effect of setting PYTHONPATH +import _init_path # noqa: F401 # Imported for its side effect of setting PYTHONPATH from openlibrary.config import load_config from openlibrary.core.imports import ImportItem -from openlibrary.core.edits import CommunityEditsQueue class DeleteImportItemJob: diff --git a/scripts/import_pressbooks.py b/scripts/import_pressbooks.py index 5316982d102..6f3c2804a97 100644 --- a/scripts/import_pressbooks.py +++ b/scripts/import_pressbooks.py @@ -10,7 +10,6 @@ import requests import html -from infogami import config from openlibrary.config import load_config from openlibrary.core.imports import Batch from scripts.solr_builder.solr_builder.fn_to_cli import FnToCLI diff --git a/scripts/import_standard_ebooks.py b/scripts/import_standard_ebooks.py index ab2dcd53def..8048ac10746 100755 --- a/scripts/import_standard_ebooks.py +++ b/scripts/import_standard_ebooks.py @@ -11,7 +11,6 @@ from openlibrary.core.imports import Batch from scripts.solr_builder.solr_builder.fn_to_cli import FnToCLI from openlibrary.config import load_config -from infogami import config FEED_URL = 'https://standardebooks.org/opds/all' LAST_UPDATED_TIME = './standard_ebooks_last_updated.txt' diff --git a/scripts/lc_marc_update.py b/scripts/lc_marc_update.py index 6a476fd0861..9ed6c18d205 100755 --- a/scripts/lc_marc_update.py +++ b/scripts/lc_marc_update.py @@ -1,7 +1,6 @@ #!/usr/bin/env python from openlibrary.catalog.importer.scribe import BadImport -from openlibrary.catalog.read_rc import read_rc from openlibrary import config from ftplib import FTP from time import sleep diff --git a/scripts/oldump.py b/scripts/oldump.py index b4a9978a2ea..7c17012456e 100755 --- a/scripts/oldump.py +++ b/scripts/oldump.py @@ -5,7 +5,7 @@ import sys from datetime import datetime -import _init_path # Imported for its side effect of setting PYTHONPATH +import _init_path # noqa: F401 # Imported for its side effect of setting PYTHONPATH logger = logging.getLogger(__file__) logger.setLevel(logging.DEBUG) diff --git a/scripts/openlibrary-server b/scripts/openlibrary-server index 14984063848..136736dea3d 100755 --- a/scripts/openlibrary-server +++ b/scripts/openlibrary-server @@ -55,7 +55,7 @@ def start_server(): def load_infogami(config_file): import infogami from infogami import config - from infogami.utils import delegate + from infogami.utils import delegate # noqa: F401 not sure why but could be needed config.plugin_path += ['openlibrary.plugins'] config.site = "openlibrary.org" diff --git a/scripts/partner_batch_imports.py b/scripts/partner_batch_imports.py index f3203c54436..37e577b9d1d 100755 --- a/scripts/partner_batch_imports.py +++ b/scripts/partner_batch_imports.py @@ -19,7 +19,6 @@ import requests -from infogami import config from openlibrary.config import load_config from openlibrary.core.imports import Batch from scripts.solr_builder.solr_builder.fn_to_cli import FnToCLI diff --git a/scripts/promise_batch_imports.py b/scripts/promise_batch_imports.py index 345e7096b79..8a8fbddc9d1 100644 --- a/scripts/promise_batch_imports.py +++ b/scripts/promise_batch_imports.py @@ -22,8 +22,7 @@ import requests import logging -import _init_path # Imported for its side effect of setting PYTHONPATH -from infogami import config +import _init_path # noqa: F401 # Imported for its side effect of setting PYTHONPATH from openlibrary.config import load_config from openlibrary.core.imports import Batch, ImportItem from openlibrary.core.vendors import get_amazon_metadata diff --git a/scripts/pull-templates.py b/scripts/pull-templates.py index 97533ea1f49..d5ef14bec97 100755 --- a/scripts/pull-templates.py +++ b/scripts/pull-templates.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """Script to pull templates and macros from an openlibrary instance to repository. """ -import _init_path # Imported for its side effect of setting PYTHONPATH +import _init_path # noqa: F401 # Imported for its side effect of setting PYTHONPATH import os import web diff --git a/scripts/solr_updater.py b/scripts/solr_updater.py index a8ae54e4693..28b746b9b73 100644 --- a/scripts/solr_updater.py +++ b/scripts/solr_updater.py @@ -17,10 +17,9 @@ import sys import urllib -from typing import Union from collections.abc import Iterator -import _init_path # Imported for its side effect of setting PYTHONPATH +import _init_path # noqa: F401 # Imported for its side effect of setting PYTHONPATH import aiofiles import web diff --git a/scripts/store_counts.py b/scripts/store_counts.py index ea946a2bf83..7c2d7171699 100755 --- a/scripts/store_counts.py +++ b/scripts/store_counts.py @@ -2,7 +2,7 @@ import sys -import _init_path # Imported for its side effect of setting PYTHONPATH +import _init_path # noqa: F401 # Imported for its side effect of setting PYTHONPATH from openlibrary.admin import stats diff --git a/scripts/tests/test_affiliate_server.py b/scripts/tests/test_affiliate_server.py index 1bbc730ebe3..2fc9433607c 100644 --- a/scripts/tests/test_affiliate_server.py +++ b/scripts/tests/test_affiliate_server.py @@ -18,7 +18,6 @@ from scripts.affiliate_server import ( # noqa: E402 PrioritizedIdentifier, Priority, - Submit, get_isbns_from_book, get_isbns_from_books, get_editions_for_books, diff --git a/scripts/update_stale_work_references.py b/scripts/update_stale_work_references.py index bd16f1d7567..6c97808eefe 100644 --- a/scripts/update_stale_work_references.py +++ b/scripts/update_stale_work_references.py @@ -2,13 +2,10 @@ PYTHONPATH=. python ./scripts/update_stale_work_references.py /olsystem/etc/openlibrary.yml """ -import web import infogami -from infogami import config from openlibrary.config import load_config from openlibrary.core.models import Work from scripts.solr_builder.solr_builder.fn_to_cli import FnToCLI -import datetime def main(ol_config: str, days=1, skip=7):