From 2917dc4a76219e3d0b13a9e5f85fd7079062c824 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 3 Jan 2025 10:32:51 -0500 Subject: [PATCH] Apply import sort fixers from ruff. --- importlib_resources/__init__.py | 7 ++----- importlib_resources/_common.py | 12 ++++++------ importlib_resources/_functional.py | 3 +-- importlib_resources/abc.py | 14 +++++++++++--- importlib_resources/compat/py38.py | 2 -- importlib_resources/compat/py39.py | 1 - importlib_resources/future/adapters.py | 2 +- importlib_resources/readers.py | 3 +-- importlib_resources/tests/_path.py | 8 ++------ .../tests/test_compatibilty_files.py | 1 - importlib_resources/tests/test_contents.py | 1 + importlib_resources/tests/test_custom.py | 5 +++-- importlib_resources/tests/test_files.py | 7 ++++--- importlib_resources/tests/test_functional.py | 7 +++---- importlib_resources/tests/test_open.py | 1 + importlib_resources/tests/test_path.py | 1 + importlib_resources/tests/test_read.py | 3 ++- importlib_resources/tests/test_reader.py | 2 +- importlib_resources/tests/test_resource.py | 3 ++- importlib_resources/tests/util.py | 12 +++++------- 20 files changed, 47 insertions(+), 48 deletions(-) diff --git a/importlib_resources/__init__.py b/importlib_resources/__init__.py index 723c9f9e..27d6c7f8 100644 --- a/importlib_resources/__init__.py +++ b/importlib_resources/__init__.py @@ -8,12 +8,11 @@ """ from ._common import ( + Anchor, + Package, as_file, files, - Package, - Anchor, ) - from ._functional import ( contents, is_resource, @@ -23,10 +22,8 @@ read_binary, read_text, ) - from .abc import ResourceReader - __all__ = [ 'Package', 'Anchor', diff --git a/importlib_resources/_common.py b/importlib_resources/_common.py index f065d493..5f41c265 100644 --- a/importlib_resources/_common.py +++ b/importlib_resources/_common.py @@ -1,15 +1,15 @@ +import contextlib +import functools +import importlib +import inspect +import itertools import os import pathlib import tempfile -import functools -import contextlib import types -import importlib -import inspect import warnings -import itertools +from typing import Optional, Union, cast -from typing import Union, Optional, cast from .abc import ResourceReader, Traversable Package = Union[types.ModuleType, str] diff --git a/importlib_resources/_functional.py b/importlib_resources/_functional.py index f59416f2..5a3ca0a2 100644 --- a/importlib_resources/_functional.py +++ b/importlib_resources/_functional.py @@ -2,8 +2,7 @@ import warnings -from ._common import files, as_file - +from ._common import as_file, files _MISSING = object() diff --git a/importlib_resources/abc.py b/importlib_resources/abc.py index 7a58dd2f..c0a4cb95 100644 --- a/importlib_resources/abc.py +++ b/importlib_resources/abc.py @@ -2,12 +2,20 @@ import io import itertools import pathlib -from typing import Any, BinaryIO, Iterable, Iterator, NoReturn, Text, Optional -from typing import runtime_checkable, Protocol +from typing import ( + Any, + BinaryIO, + Iterable, + Iterator, + NoReturn, + Optional, + Protocol, + Text, + runtime_checkable, +) from .compat.py38 import StrPath - __all__ = ["ResourceReader", "Traversable", "TraversableResources"] diff --git a/importlib_resources/compat/py38.py b/importlib_resources/compat/py38.py index 4d548257..80940e94 100644 --- a/importlib_resources/compat/py38.py +++ b/importlib_resources/compat/py38.py @@ -1,9 +1,7 @@ import os import sys - from typing import Union - if sys.version_info >= (3, 9): StrPath = Union[str, os.PathLike[str]] else: diff --git a/importlib_resources/compat/py39.py b/importlib_resources/compat/py39.py index ed5abd5e..684d3c63 100644 --- a/importlib_resources/compat/py39.py +++ b/importlib_resources/compat/py39.py @@ -1,6 +1,5 @@ import sys - __all__ = ['ZipPath'] diff --git a/importlib_resources/future/adapters.py b/importlib_resources/future/adapters.py index 5cf17556..239e52b7 100644 --- a/importlib_resources/future/adapters.py +++ b/importlib_resources/future/adapters.py @@ -3,7 +3,7 @@ from contextlib import suppress from types import SimpleNamespace -from .. import readers, _adapters +from .. import _adapters, readers def _block_standard(reader_getter): diff --git a/importlib_resources/readers.py b/importlib_resources/readers.py index 4f761c64..99884b6a 100644 --- a/importlib_resources/readers.py +++ b/importlib_resources/readers.py @@ -3,14 +3,13 @@ import collections import contextlib import itertools -import pathlib import operator +import pathlib import re import warnings from collections.abc import Iterator from . import abc - from ._itertools import only from .compat.py39 import ZipPath diff --git a/importlib_resources/tests/_path.py b/importlib_resources/tests/_path.py index b144628c..0033983d 100644 --- a/importlib_resources/tests/_path.py +++ b/importlib_resources/tests/_path.py @@ -1,10 +1,6 @@ -import pathlib import functools - -from typing import Dict, Union -from typing import runtime_checkable -from typing import Protocol - +import pathlib +from typing import Dict, Protocol, Union, runtime_checkable #### # from jaraco.path 3.7.1 diff --git a/importlib_resources/tests/test_compatibilty_files.py b/importlib_resources/tests/test_compatibilty_files.py index 13ad0dfb..e8aac284 100644 --- a/importlib_resources/tests/test_compatibilty_files.py +++ b/importlib_resources/tests/test_compatibilty_files.py @@ -2,7 +2,6 @@ import unittest import importlib_resources as resources - from importlib_resources._adapters import ( CompatibilityFiles, wrap_spec, diff --git a/importlib_resources/tests/test_contents.py b/importlib_resources/tests/test_contents.py index 741a7407..dcb872ec 100644 --- a/importlib_resources/tests/test_contents.py +++ b/importlib_resources/tests/test_contents.py @@ -1,4 +1,5 @@ import unittest + import importlib_resources as resources from . import util diff --git a/importlib_resources/tests/test_custom.py b/importlib_resources/tests/test_custom.py index 86c65676..25ae0e75 100644 --- a/importlib_resources/tests/test_custom.py +++ b/importlib_resources/tests/test_custom.py @@ -1,10 +1,11 @@ -import unittest import contextlib import pathlib +import unittest import importlib_resources as resources + from .. import abc -from ..abc import TraversableResources, ResourceReader +from ..abc import ResourceReader, TraversableResources from . import util from .compat.py39 import os_helper diff --git a/importlib_resources/tests/test_files.py b/importlib_resources/tests/test_files.py index 8d87a01e..be206603 100644 --- a/importlib_resources/tests/test_files.py +++ b/importlib_resources/tests/test_files.py @@ -1,15 +1,16 @@ +import contextlib +import importlib import pathlib import py_compile import textwrap import unittest import warnings -import importlib -import contextlib import importlib_resources as resources + from ..abc import Traversable from . import util -from .compat.py39 import os_helper, import_helper +from .compat.py39 import import_helper, os_helper @contextlib.contextmanager diff --git a/importlib_resources/tests/test_functional.py b/importlib_resources/tests/test_functional.py index ffe12db4..2285389e 100644 --- a/importlib_resources/tests/test_functional.py +++ b/importlib_resources/tests/test_functional.py @@ -1,12 +1,11 @@ -import unittest -import os import importlib - -from .compat.py39 import warnings_helper +import os +import unittest import importlib_resources as resources from . import util +from .compat.py39 import warnings_helper # Since the functional API forwards to Traversable, we only test # filesystem resources here -- not zip files, namespace packages etc. diff --git a/importlib_resources/tests/test_open.py b/importlib_resources/tests/test_open.py index c40bb8c6..8a4b68e3 100644 --- a/importlib_resources/tests/test_open.py +++ b/importlib_resources/tests/test_open.py @@ -1,6 +1,7 @@ import unittest import importlib_resources as resources + from . import util diff --git a/importlib_resources/tests/test_path.py b/importlib_resources/tests/test_path.py index 1e30f2bc..0be673d2 100644 --- a/importlib_resources/tests/test_path.py +++ b/importlib_resources/tests/test_path.py @@ -3,6 +3,7 @@ import unittest import importlib_resources as resources + from . import util diff --git a/importlib_resources/tests/test_read.py b/importlib_resources/tests/test_read.py index 6780a2d1..216c8feb 100644 --- a/importlib_resources/tests/test_read.py +++ b/importlib_resources/tests/test_read.py @@ -1,8 +1,9 @@ import unittest +from importlib import import_module + import importlib_resources as resources from . import util -from importlib import import_module class CommonBinaryTests(util.CommonTests, unittest.TestCase): diff --git a/importlib_resources/tests/test_reader.py b/importlib_resources/tests/test_reader.py index 0a77eb40..f8cfd8de 100644 --- a/importlib_resources/tests/test_reader.py +++ b/importlib_resources/tests/test_reader.py @@ -1,8 +1,8 @@ import os.path import pathlib import unittest - from importlib import import_module + from importlib_resources.readers import MultiplexedPath, NamespaceReader from . import util diff --git a/importlib_resources/tests/test_resource.py b/importlib_resources/tests/test_resource.py index a0da6a35..c80afdc7 100644 --- a/importlib_resources/tests/test_resource.py +++ b/importlib_resources/tests/test_resource.py @@ -1,8 +1,9 @@ import unittest +from importlib import import_module + import importlib_resources as resources from . import util -from importlib import import_module class ResourceTests: diff --git a/importlib_resources/tests/util.py b/importlib_resources/tests/util.py index 5f755178..07d1529a 100644 --- a/importlib_resources/tests/util.py +++ b/importlib_resources/tests/util.py @@ -1,18 +1,16 @@ import abc +import contextlib import importlib import io +import pathlib import sys import types -import pathlib -import contextlib +from importlib.machinery import ModuleSpec from ..abc import ResourceReader -from .compat.py39 import import_helper, os_helper -from . import zip as zip_ from . import _path - - -from importlib.machinery import ModuleSpec +from . import zip as zip_ +from .compat.py39 import import_helper, os_helper class Reader(ResourceReader):