Skip to content

Commit

Permalink
enable ruff rule to check for unused imports (#9182)
Browse files Browse the repository at this point in the history
* enable ruff rule to check for unused imports
  • Loading branch information
RayBB authored May 22, 2024
1 parent 47d6bd6 commit b72499c
Show file tree
Hide file tree
Showing 66 changed files with 50 additions and 113 deletions.
1 change: 0 additions & 1 deletion openlibrary/admin/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import functools
import logging

import web

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions openlibrary/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def setup():
load_views()

# load actions
from . import actions
from . import actions # noqa: F401

logger.info("loading complete.")

Expand All @@ -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()
12 changes: 9 additions & 3 deletions openlibrary/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion openlibrary/core/edits.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import json
import web
from sqlite3 import IntegrityError
from psycopg2.errors import UniqueViolation

Expand Down
3 changes: 1 addition & 2 deletions openlibrary/core/follows.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion openlibrary/core/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions openlibrary/core/lists/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions openlibrary/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/core/processors/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from openlibrary.core.processors.readableurls import ReadableUrlProcessor
from openlibrary.core.processors.readableurls import ReadableUrlProcessor # noqa: F401
2 changes: 1 addition & 1 deletion openlibrary/core/sponsorships.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion openlibrary/core/vendors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import re
import time

from datetime import date
from typing import Any, Literal

import requests
Expand Down
1 change: 0 additions & 1 deletion openlibrary/core/waitinglist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion openlibrary/coverstore/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 0 additions & 2 deletions openlibrary/coverstore/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
download,
ol_get,
ol_things,
random_string,
rm_f,
safeint,
)
from openlibrary.plugins.openlibrary.processors import CORSProcessor
Expand Down
1 change: 0 additions & 1 deletion openlibrary/data/sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import datetime
from gzip import open as gzopen

from openlibrary.plugins.openlibrary.processors import urlsafe

t = web.template.Template

Expand Down
2 changes: 1 addition & 1 deletion openlibrary/i18n/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions openlibrary/i18n/validators.py
Original file line number Diff line number Diff line change
@@ -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]:
Expand Down
1 change: 0 additions & 1 deletion openlibrary/plugins/admin/mem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from infogami.utils import delegate
from infogami.utils.view import render, safeint
from openlibrary.plugins.admin import memory
import web
Expand Down
1 change: 0 additions & 1 deletion openlibrary/plugins/books/readlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions openlibrary/plugins/openlibrary/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions openlibrary/plugins/openlibrary/borrow_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
10 changes: 5 additions & 5 deletions openlibrary/plugins/openlibrary/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion openlibrary/plugins/openlibrary/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions openlibrary/plugins/openlibrary/design.py
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
1 change: 0 additions & 1 deletion openlibrary/plugins/openlibrary/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/plugins/openlibrary/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/plugins/openlibrary/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion openlibrary/plugins/openlibrary/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion openlibrary/plugins/openlibrary/utils.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from openlibrary.core.helpers import sanitize
4 changes: 1 addition & 3 deletions openlibrary/plugins/upstream/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand All @@ -39,7 +39,6 @@
from openlibrary.plugins import openlibrary as olib
from openlibrary.accounts import (
audit_accounts,
Account,
OpenLibraryAccount,
InternetArchiveAccount,
valid_email,
Expand Down Expand Up @@ -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', "")
Expand Down
1 change: 0 additions & 1 deletion openlibrary/plugins/upstream/addbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions openlibrary/plugins/upstream/addtag.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Handlers for adding and editing tags."""

import web
import json

from typing import NoReturn

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions openlibrary/plugins/upstream/borrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion openlibrary/plugins/upstream/checkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading

0 comments on commit b72499c

Please sign in to comment.