Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "enable ruff rule to check for unused imports" #9327

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openlibrary/admin/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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 # noqa: F401
from . import actions

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 # noqa: F401
from .views import showmarc


setup()
12 changes: 3 additions & 9 deletions openlibrary/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@
from openlibrary.i18n import gettext
from openlibrary.core import helpers

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
)
from openlibrary.mocks.mock_infobase import mock_site
from openlibrary.mocks.mock_ia import mock_ia
from openlibrary.mocks.mock_memcache import mock_memcache


@pytest.fixture(autouse=True)
Expand Down
1 change: 1 addition & 0 deletions openlibrary/core/edits.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import json
import web
from sqlite3 import IntegrityError
from psycopg2.errors import UniqueViolation

Expand Down
3 changes: 2 additions & 1 deletion openlibrary/core/follows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from typing import cast
import web
from typing import cast, Any
from openlibrary.core.bookshelves import Bookshelves

from . import db
Expand Down
1 change: 1 addition & 0 deletions openlibrary/core/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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: 3 additions & 1 deletion openlibrary/core/lists/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import web
import logging

from infogami.infobase import client
from infogami import config
from infogami.infobase import client, common
from infogami.utils import stats

from openlibrary.core import helpers as h
from openlibrary.core import cache
Expand Down
7 changes: 5 additions & 2 deletions openlibrary/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@
# 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
from openlibrary.utils import extract_numeric_id_from_olid, dateutil
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 @@ -992,7 +995,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 # noqa: F401
from ..plugins.upstream import borrow

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 # noqa: F401
from openlibrary.core.processors.readableurls import ReadableUrlProcessor
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
from openlibrary.accounts.model import get_internet_archive_id, sendmail
from openlibrary.core.civicrm import (
get_contact_id_by_username,
get_sponsorships_by_contact_id,
Expand Down
1 change: 1 addition & 0 deletions openlibrary/core/vendors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import time

from datetime import date
from typing import Any, Literal

import requests
Expand Down
1 change: 1 addition & 0 deletions openlibrary/core/waitinglist.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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: 1 addition & 0 deletions openlibrary/coverstore/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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: 2 additions & 0 deletions openlibrary/coverstore/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
download,
ol_get,
ol_things,
random_string,
rm_f,
safeint,
)
from openlibrary.plugins.openlibrary.processors import CORSProcessor
Expand Down
1 change: 1 addition & 0 deletions openlibrary/data/sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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_dir, extract_python
from babel.messages.extract import extract_from_file, extract_from_dir, extract_python

from .validators import validate

Expand Down
3 changes: 2 additions & 1 deletion openlibrary/i18n/validators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from itertools import groupby
import re

from babel.messages.catalog import Message, Catalog
from babel.messages.catalog import TranslationError, Message, Catalog
from babel.messages.checkers import python_format


def validate(message: Message, catalog: Catalog) -> list[str]:
Expand Down
1 change: 1 addition & 0 deletions openlibrary/plugins/admin/mem.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from infogami.utils import delegate
from infogami.utils.view import render, safeint
from openlibrary.plugins.admin import memory
import web
Expand Down
1 change: 1 addition & 0 deletions openlibrary/plugins/books/readlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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: 5 additions & 1 deletion openlibrary/plugins/openlibrary/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
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.core import models, lending, helpers as h
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.bookshelves_events import BookshelvesEvents
from openlibrary.core.observations import Observations, get_observation_metrics
from openlibrary.core.models import Booknotes, Work
Expand Down
3 changes: 2 additions & 1 deletion openlibrary/plugins/openlibrary/borrow_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import eventer

from infogami.utils import delegate
from infogami.utils.view import render_template # noqa: F401 used for its side effects
from infogami.utils.view import render_template # 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, urlencode
from urllib.parse import parse_qs, urlparse, urlencode, urlunparse
import requests
import web
import json
Expand All @@ -13,6 +13,7 @@
import logging
from time import time
import math
from pathlib import Path
import infogami

# make sure infogami.config.features is set
Expand All @@ -33,6 +34,7 @@
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 @@ -291,7 +293,7 @@ def POST(self):

class clonebook(delegate.page):
def GET(self):
from infogami.core.code import edit # noqa: F401 not sure why, probably needed
from infogami.core.code import edit

i = web.input('key')
page = web.ctx.site.get(i.key)
Expand Down Expand Up @@ -1176,9 +1178,7 @@ def setup():
authors.setup()
swagger.setup()

from openlibrary.plugins.openlibrary import (
api, # noqa: F401 not sure why but could be needed
)
from openlibrary.plugins.openlibrary import api

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
from infogami.infobase import client, lru
from infogami.utils import stats

import web
Expand Down
3 changes: 2 additions & 1 deletion openlibrary/plugins/openlibrary/design.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import web
import logging

from infogami.utils import delegate
from infogami.utils.view import render_template
from infogami.utils.view import render_template, public

logger = logging.getLogger("openlibrary.design")

Expand Down
1 change: 1 addition & 0 deletions openlibrary/plugins/openlibrary/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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 olid_to_key
from openlibrary.utils import dateutil, 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 # noqa: F401
from openlibrary.core.processors import ReadableUrlProcessor
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 stats
from infogami.utils import delegate, stats

import openlibrary.plugins.openlibrary.filters as stats_filters

Expand Down
1 change: 1 addition & 0 deletions openlibrary/plugins/openlibrary/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from openlibrary.core.helpers import sanitize
4 changes: 3 additions & 1 deletion 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 # noqa: F401 definitely needed
import infogami.core.code as core

from openlibrary import accounts
from openlibrary.i18n import gettext as _
Expand All @@ -39,6 +39,7 @@
from openlibrary.plugins import openlibrary as olib
from openlibrary.accounts import (
audit_accounts,
Account,
OpenLibraryAccount,
InternetArchiveAccount,
valid_email,
Expand Down Expand Up @@ -345,6 +346,7 @@ 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: 1 addition & 0 deletions openlibrary/plugins/upstream/addbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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: 3 additions & 0 deletions openlibrary/plugins/upstream/addtag.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Handlers for adding and editing tags."""

import web
import json

from typing import NoReturn

Expand All @@ -10,6 +11,8 @@
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, add_flash_message
from infogami.utils.view import render_template # noqa: F401 used for its side effects
from infogami.utils.view import public, render_template, add_flash_message
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: 1 addition & 0 deletions openlibrary/plugins/upstream/checkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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
Loading