Skip to content

Commit

Permalink
Use isort instead of reorder-python-imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemon24 committed Mar 10, 2024
1 parent 7934bb6 commit b98136f
Show file tree
Hide file tree
Showing 73 changed files with 169 additions and 104 deletions.
9 changes: 3 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ exclude: ^src/reader/_vendor/.*$

repos:

- repo: https://github.com/asottile/reorder_python_imports
rev: v3.12.0
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: reorder-python-imports
name: Reorder Python imports (src, tests)
files: "^(?!examples/)"
args: ["--application-directories", ".:src"]
- id: isort

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
Expand Down
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import packaging.version
from setuptools.config.pyprojecttoml import read_configuration


sys.path.insert(0, os.path.abspath('../src'))

# mock some things "by hand", so we can import reader below without any dependencies
Expand All @@ -23,6 +24,7 @@

import reader


extensions = [
'sphinx_rtd_theme',
'sphinx.ext.autodoc',
Expand Down Expand Up @@ -155,6 +157,7 @@


import pkgutil

from docutils import nodes
from sphinx.util.docutils import SphinxDirective

Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,14 @@ module = [
"reader._vendor.feedparser.*",
]
ignore_errors = true

[tool.isort]
profile = "black"
py_version = 310
src_paths = ["src", "tests"]
extend_skip = ["examples", "src/reader/_vendor"]
skip_gitignore = true
filter_files = true
force_single_line = true
order_by_type = false
lines_after_imports = 2
5 changes: 3 additions & 2 deletions scripts/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@

import click


root_dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(root_dir, '../src'))
sys.path.insert(0, os.path.join(root_dir, '../tests'))

from fakeparser import Parser

from reader import make_reader
from reader._app import create_app, get_reader
from reader._app import create_app
from reader._app import get_reader
from reader._config import make_reader_config


Expand Down
1 change: 1 addition & 0 deletions scripts/generate_import_all.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inspect
import random


context = {}
exec('from reader import *', context)
context.pop('__builtins__')
Expand Down
4 changes: 3 additions & 1 deletion scripts/jscontrols.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
from flask import redirect
from flask import request


root_dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(root_dir, '../src'))

from reader._app.api_thing import APIThing, APIError
from reader._app.api_thing import APIError
from reader._app.api_thing import APIThing


app = Flask(
Expand Down
2 changes: 2 additions & 0 deletions src/reader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

__version__ = '3.13.dev0'

# isort: off

from .core import (
Reader as Reader,
make_reader as make_reader,
Expand Down
1 change: 1 addition & 0 deletions src/reader/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys


CANNOT_IMPORT = """\
Error: cannot import reader._cli
Expand Down
5 changes: 3 additions & 2 deletions src/reader/_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
from flask import url_for

import reader
from .api_thing import APIError
from .api_thing import APIThing
from reader import Content
from reader import Entry
from reader import EntrySearchResult
Expand All @@ -40,6 +38,9 @@
from reader.types import _get_entry_content
from reader.types import TristateFilterInput

from .api_thing import APIError
from .api_thing import APIThing


blueprint = Blueprint('reader', __name__)

Expand Down
1 change: 1 addition & 0 deletions src/reader/_app/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def serve(config, host, port, plugin, verbose):
"""Start a local HTTP reader server."""
setup_logging(verbose)
from werkzeug.serving import run_simple

from . import create_app

if plugin:
Expand Down
1 change: 1 addition & 0 deletions src/reader/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import yaml

import reader

from . import StorageError
from ._config import make_reader_config
from ._config import make_reader_from_config
Expand Down
3 changes: 2 additions & 1 deletion src/reader/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
from dataclasses import dataclass
from dataclasses import field

from .plugins import DEFAULT_PLUGINS
from reader import make_reader
from reader._plugins import Loader

from .plugins import DEFAULT_PLUGINS


MAKE_READER_IMPORT_KWARGS = ('storage_cls', 'search_cls')

Expand Down
3 changes: 2 additions & 1 deletion src/reader/_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .requests import SessionFactory
from .requests import TimeoutType


if TYPE_CHECKING: # pragma: no cover
from ._lazy import Parser as Parser

Expand Down Expand Up @@ -66,8 +67,8 @@ def default_parser(
file_retriever = FileRetriever(feed_root)

def post_init(parser: Parser) -> None:
from .http import HTTPRetriever
from .feedparser import FeedparserParser
from .http import HTTPRetriever
from .jsonfeed import JSONFeedParser

parser.session_factory.timeout = session_timeout
Expand Down
1 change: 1 addition & 0 deletions src/reader/_parser/_http_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import werkzeug.http


parse_options_header = werkzeug.http.parse_options_header
parse_accept_header = werkzeug.http.parse_accept_header

Expand Down
10 changes: 5 additions & 5 deletions src/reader/_parser/_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
from typing import Any
from typing import ContextManager

from .._types import FeedForUpdate
from .._types import ParsedFeed
from .._utils import MapFunction
from ..exceptions import InvalidFeedURLError
from ..exceptions import ParseError
from . import EntryPair
from . import EntryPairsParserType
from . import FeedArgument
Expand All @@ -22,11 +27,6 @@
from . import RetrieverType
from . import wrap_cm_exceptions
from . import wrap_exceptions
from .._types import FeedForUpdate
from .._types import ParsedFeed
from .._utils import MapFunction
from ..exceptions import InvalidFeedURLError
from ..exceptions import ParseError
from ._http_utils import parse_accept_header
from ._http_utils import unparse_accept_header
from ._url_utils import normalize_url
Expand Down
2 changes: 1 addition & 1 deletion src/reader/_parser/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from typing import Any
from typing import IO

from ..exceptions import ParseError
from . import RetrieveResult
from . import wrap_exceptions
from ..exceptions import ParseError
from ._url_utils import extract_path
from ._url_utils import resolve_root

Expand Down
2 changes: 1 addition & 1 deletion src/reader/_parser/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import requests

from ..exceptions import ParseError
from . import RetrieveResult
from . import wrap_exceptions
from ..exceptions import ParseError
from ._http_utils import parse_options_header
from .requests import SessionWrapper

Expand Down
1 change: 1 addition & 0 deletions src/reader/_parser/jsonfeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ..types import Content
from ..types import Enclosure


if TYPE_CHECKING: # pragma: no cover
from . import FeedAndEntries
from .requests import Headers
Expand Down
5 changes: 4 additions & 1 deletion src/reader/_parser/requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

from ..._utils import lazy_import


if TYPE_CHECKING: # pragma: no cover
import requests

from ._lazy import SessionWrapper as SessionWrapper

__getattr__ = lazy_import(__name__, ['SessionWrapper', 'TimeoutHTTPAdapter'])
Expand Down Expand Up @@ -115,7 +117,8 @@ def __call__(self) -> SessionWrapper:
SessionWrapper:
"""
from . import SessionWrapper, TimeoutHTTPAdapter
from . import SessionWrapper
from . import TimeoutHTTPAdapter

session = SessionWrapper(
request_hooks=list(self.request_hooks),
Expand Down
2 changes: 2 additions & 0 deletions src/reader/_parser/requests/_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

from . import TimeoutType


if TYPE_CHECKING: # pragma: no cover
from typing_extensions import Self

from . import Headers
from . import RequestHook
from . import ResponseHook
Expand Down
1 change: 1 addition & 0 deletions src/reader/_plugins/enclosure_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from flask import stream_with_context
from flask import url_for


blueprint = Blueprint('enclosure_tags', __name__)


Expand Down
1 change: 1 addition & 0 deletions src/reader/_plugins/sqlite_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from reader._types import EntryData
from reader._types import FeedData


warnings.filterwarnings(
'ignore',
message='No parser was explicitly specified',
Expand Down
2 changes: 1 addition & 1 deletion src/reader/_plugins/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def init_reader(reader):
pass
end = perf_counter()

print(f"{end-start:1.6f}")
print(f"{end - start:1.6f}")
print(f"{reader.timer.total('Reader.'):1.6f}")
print(reader.timer.format_stats())
print(reader.make_reader_reserved_name('ok'))
5 changes: 3 additions & 2 deletions src/reader/_storage/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from typing import Any
from typing import TypeVar

from . import _sqlite_utils
from ..exceptions import StorageError
from . import _sqlite_utils
from ._sql_utils import paginated_query
from ._sql_utils import Query

Expand Down Expand Up @@ -70,8 +70,9 @@ def get_db(self) -> sqlite3.Connection:
def setup_db(db: sqlite3.Connection) -> None:
# Private API, used by tests.

from . import MINIMUM_SQLITE_VERSION
from . import REQUIRED_SQLITE_FUNCTIONS
from ._schema import MIGRATION
from . import MINIMUM_SQLITE_VERSION, REQUIRED_SQLITE_FUNCTIONS

return _sqlite_utils.setup_db(
db,
Expand Down
1 change: 1 addition & 0 deletions src/reader/_storage/_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ._sql_utils import Query
from ._sqlite_utils import ddl_transaction


if TYPE_CHECKING: # pragma: no cover
from ._base import StorageBase

Expand Down
1 change: 1 addition & 0 deletions src/reader/_storage/_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from ._tags import entry_tags_filter
from ._tags import feed_tags_filter


if TYPE_CHECKING: # pragma: no cover
from ._base import StorageBase
else:
Expand Down
1 change: 1 addition & 0 deletions src/reader/_storage/_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ._sqlite_utils import rowcount_exactly_one
from ._tags import feed_tags_filter


if TYPE_CHECKING: # pragma: no cover
from ._base import StorageBase
else:
Expand Down
1 change: 1 addition & 0 deletions src/reader/_storage/_html_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import warnings
from typing import TYPE_CHECKING


if TYPE_CHECKING: # pragma: no cover
import bs4

Expand Down
2 changes: 1 addition & 1 deletion src/reader/_storage/_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ def update_from_37_to_38(db: sqlite3.Connection, /) -> None: # pragma: no cover
def update_from_38_to_39(db: sqlite3.Connection, /) -> None: # pragma: no cover
# https://github.com/lemon24/reader/issues/323

from ._search import Search
from ._changes import Changes
from ._search import Search

db.execute("ALTER TABLE entries ADD COLUMN sequence BLOB;")

Expand Down
8 changes: 4 additions & 4 deletions src/reader/_storage/_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
from typing import Any
from typing import TypeVar

from . import _entries
from . import _html_utils
from . import _sqlite_utils
from . import Storage
from .._types import Action
from .._types import Change
from .._types import EntryFilter
Expand All @@ -33,6 +29,10 @@
from ..types import EntrySearchResult
from ..types import HighlightedString
from ..types import SearchSortOrder
from . import _entries
from . import _html_utils
from . import _sqlite_utils
from . import Storage
from ._sql_utils import paginated_query
from ._sql_utils import Query
from ._sqlite_utils import ddl_transaction
Expand Down
2 changes: 2 additions & 0 deletions src/reader/_storage/_sql_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
from typing import TypeVar
from typing import Union


if TYPE_CHECKING: # pragma: no cover
import sqlite3

from typing_extensions import Self


Expand Down

0 comments on commit b98136f

Please sign in to comment.