From a27371850ac13a1f3db4bddf7f897a91e025e6da Mon Sep 17 00:00:00 2001 From: Antoine Lambert <antoine.lambert@inria.fr> Date: Thu, 17 Sep 2020 17:56:18 +0200 Subject: [PATCH] python: Reorder imports with isort Related to T2610 --- bin/swh-hashtree | 3 +- bin/swh-revhash | 2 +- setup.py | 6 +-- swh/model/cli.py | 19 ++++---- swh/model/fields/__init__.py | 10 ++--- swh/model/fields/compound.py | 2 +- swh/model/fields/hashes.py | 1 + swh/model/from_disk.py | 13 +++--- swh/model/hashutil.py | 3 +- swh/model/hypothesis_strategies.py | 25 +++++------ swh/model/identifiers.py | 6 +-- swh/model/merkle.py | 1 - swh/model/model.py | 15 +++---- swh/model/tests/generate_testdata.py | 6 +-- .../tests/generate_testdata_from_disk.py | 2 +- swh/model/tests/test_from_disk.py | 9 ++-- swh/model/tests/test_generate_testdata.py | 4 +- swh/model/tests/test_hypothesis_strategies.py | 11 +++-- swh/model/tests/test_identifiers.py | 3 +- swh/model/tests/test_model.py | 44 +++++++++---------- swh/model/validators.py | 2 +- 21 files changed, 89 insertions(+), 98 deletions(-) diff --git a/bin/swh-hashtree b/bin/swh-hashtree index 5b85b7b5..a4f8d7b7 100755 --- a/bin/swh-hashtree +++ b/bin/swh-hashtree @@ -5,9 +5,10 @@ # --ignore-empty-folders # 38f8d2c3a951f6b94007896d0981077e48bbd702 -import click import os +import click + from swh.model import from_disk, hashutil diff --git a/bin/swh-revhash b/bin/swh-revhash index d3a8caf8..56b587d9 100755 --- a/bin/swh-revhash +++ b/bin/swh-revhash @@ -11,7 +11,7 @@ import sys -from swh.model import identifiers, hashutil +from swh.model import hashutil, identifiers def revhash(revision_raw): diff --git a/setup.py b/setup.py index ecaac105..f42058ca 100755 --- a/setup.py +++ b/setup.py @@ -4,10 +4,10 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -from setuptools import setup, find_packages - -from os import path from io import open +from os import path + +from setuptools import find_packages, setup here = path.abspath(path.dirname(__file__)) diff --git a/swh/model/cli.py b/swh/model/cli.py index 53920700..68a36805 100644 --- a/swh/model/cli.py +++ b/swh/model/cli.py @@ -3,12 +3,12 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -# WARNING: do not import unnecessary things here to keep cli startup time under -# control -import click import os import sys +# WARNING: do not import unnecessary things here to keep cli startup time under +# control +import click CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) @@ -38,7 +38,7 @@ class SWHIDParamType(click.ParamType): def swhid_of_file(path): from swh.model.from_disk import Content - from swh.model.identifiers import swhid, CONTENT + from swh.model.identifiers import CONTENT, swhid object = Content.from_file(path=path).get_data() return swhid(CONTENT, object) @@ -46,7 +46,7 @@ def swhid_of_file(path): def swhid_of_file_content(data): from swh.model.from_disk import Content - from swh.model.identifiers import swhid, CONTENT + from swh.model.identifiers import CONTENT, swhid object = Content.from_bytes(mode=644, data=data).get_data() return swhid(CONTENT, object) @@ -54,24 +54,23 @@ def swhid_of_file_content(data): def swhid_of_dir(path): from swh.model.from_disk import Directory - from swh.model.identifiers import swhid, DIRECTORY + from swh.model.identifiers import DIRECTORY, swhid object = Directory.from_disk(path=path).get_data() return swhid(DIRECTORY, object) def swhid_of_origin(url): - from swh.model.identifiers import origin_identifier - from swh.model.identifiers import SWHID + from swh.model.identifiers import SWHID, origin_identifier return str(SWHID(object_type="origin", object_id=origin_identifier({"url": url}))) def swhid_of_git_repo(path): import dulwich.repo + from swh.model import hashutil - from swh.model.identifiers import snapshot_identifier - from swh.model.identifiers import SWHID + from swh.model.identifiers import SWHID, snapshot_identifier repo = dulwich.repo.Repo(path) diff --git a/swh/model/fields/__init__.py b/swh/model/fields/__init__.py index a5b1ed3f..7e3c2fef 100644 --- a/swh/model/fields/__init__.py +++ b/swh/model/fields/__init__.py @@ -6,13 +6,13 @@ # We do our imports here but we don't use them, so flake8 complains # flake8: noqa +from .compound import validate_against_schema, validate_all_keys, validate_any_key +from .hashes import validate_sha1, validate_sha1_git, validate_sha256 from .simple import ( - validate_type, - validate_int, - validate_str, validate_bytes, validate_datetime, validate_enum, + validate_int, + validate_str, + validate_type, ) -from .hashes import validate_sha1, validate_sha1_git, validate_sha256 -from .compound import validate_against_schema, validate_all_keys, validate_any_key diff --git a/swh/model/fields/compound.py b/swh/model/fields/compound.py index 3133f59c..90b4685b 100644 --- a/swh/model/fields/compound.py +++ b/swh/model/fields/compound.py @@ -6,7 +6,7 @@ from collections import defaultdict import itertools -from ..exceptions import ValidationError, NON_FIELD_ERRORS +from ..exceptions import NON_FIELD_ERRORS, ValidationError def validate_against_schema(model, schema, value): diff --git a/swh/model/fields/hashes.py b/swh/model/fields/hashes.py index 47e872c7..9b5ee4ad 100644 --- a/swh/model/fields/hashes.py +++ b/swh/model/fields/hashes.py @@ -4,6 +4,7 @@ # See top-level LICENSE file for more information import string + from ..exceptions import ValidationError diff --git a/swh/model/from_disk.py b/swh/model/from_disk.py index 5ac97e25..719599d0 100644 --- a/swh/model/from_disk.py +++ b/swh/model/from_disk.py @@ -7,21 +7,18 @@ import datetime import enum import os import stat +from typing import Any, Iterable, List, Optional, Tuple import attr from attrs_strict import type_validator -from typing import Any, Iterable, List, Optional, Tuple from typing_extensions import Final +from . import model from .hashutil import MultiHash +from .identifiers import directory_entry_sort_key, directory_identifier +from .identifiers import identifier_to_bytes as id_to_bytes +from .identifiers import identifier_to_str as id_to_str from .merkle import MerkleLeaf, MerkleNode -from .identifiers import ( - directory_entry_sort_key, - directory_identifier, - identifier_to_bytes as id_to_bytes, - identifier_to_str as id_to_str, -) -from . import model @attr.s diff --git a/swh/model/hashutil.py b/swh/model/hashutil.py index 954ae957..cec87789 100644 --- a/swh/model/hashutil.py +++ b/swh/model/hashutil.py @@ -54,9 +54,8 @@ Basic usage examples: import binascii import functools import hashlib -import os - from io import BytesIO +import os from typing import Callable, Dict ALGORITHMS = set(["sha1", "sha256", "sha1_git", "blake2s256", "blake2b512"]) diff --git a/swh/model/hypothesis_strategies.py b/swh/model/hypothesis_strategies.py index 21e922ee..0c54a994 100644 --- a/swh/model/hypothesis_strategies.py +++ b/swh/model/hypothesis_strategies.py @@ -28,28 +28,27 @@ from hypothesis.strategies import ( ) from .from_disk import DentryPerms +from .identifiers import identifier_to_bytes, snapshot_identifier from .model import ( - Person, - Timestamp, - TimestampWithTimezone, + BaseContent, + Content, + Directory, + DirectoryEntry, + ObjectType, Origin, OriginVisit, OriginVisitStatus, - Snapshot, - SnapshotBranch, - ObjectType, - TargetType, + Person, Release, Revision, RevisionType, - BaseContent, - Directory, - DirectoryEntry, - Content, SkippedContent, + Snapshot, + SnapshotBranch, + TargetType, + Timestamp, + TimestampWithTimezone, ) -from .identifiers import snapshot_identifier, identifier_to_bytes - pgsql_alphabet = characters( blacklist_categories=("Cs",), blacklist_characters=["\u0000"] diff --git a/swh/model/identifiers.py b/swh/model/identifiers.py index e1cf0dfe..63d028d2 100644 --- a/swh/model/identifiers.py +++ b/swh/model/identifiers.py @@ -5,9 +5,8 @@ import binascii import datetime -import hashlib - from functools import lru_cache +import hashlib from typing import Any, Dict, Union import attr @@ -16,8 +15,7 @@ from deprecated import deprecated from .collections import ImmutableDict from .exceptions import ValidationError from .fields.hashes import validate_sha1 -from .hashutil import hash_git_data, hash_to_hex, MultiHash - +from .hashutil import MultiHash, hash_git_data, hash_to_hex ORIGIN = "origin" SNAPSHOT = "snapshot" diff --git a/swh/model/merkle.py b/swh/model/merkle.py index 0311d9d1..e84ef9d9 100644 --- a/swh/model/merkle.py +++ b/swh/model/merkle.py @@ -7,7 +7,6 @@ import abc from collections.abc import Mapping - from typing import Iterator, List, Set diff --git a/swh/model/model.py b/swh/model/model.py index 219d7c5c..d7199660 100644 --- a/swh/model/model.py +++ b/swh/model/model.py @@ -3,29 +3,28 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -import datetime - from abc import ABCMeta, abstractmethod +import datetime from enum import Enum from hashlib import sha256 from typing import Any, Dict, Iterable, Optional, Tuple, TypeVar, Union -from typing_extensions import Final import attr from attrs_strict import type_validator import dateutil.parser import iso8601 +from typing_extensions import Final from .collections import ImmutableDict -from .hashutil import DEFAULT_ALGORITHMS, hash_to_bytes, MultiHash +from .hashutil import DEFAULT_ALGORITHMS, MultiHash, hash_to_bytes from .identifiers import ( - normalize_timestamp, + SWHID, directory_identifier, - revision_identifier, + normalize_timestamp, + parse_swhid, release_identifier, + revision_identifier, snapshot_identifier, - SWHID, - parse_swhid, ) diff --git a/swh/model/tests/generate_testdata.py b/swh/model/tests/generate_testdata.py index 0280a6ab..f4093a4d 100644 --- a/swh/model/tests/generate_testdata.py +++ b/swh/model/tests/generate_testdata.py @@ -4,12 +4,12 @@ # See top-level LICENSE file for more information from datetime import datetime -from pytz import all_timezones, timezone from random import choice, randint, random, shuffle -from typing import List, Dict +from typing import Dict, List -from swh.model.hashutil import MultiHash +from pytz import all_timezones, timezone +from swh.model.hashutil import MultiHash PROTOCOLS = ["git", "http", "https", "deb", "svn", "mock"] DOMAINS = ["example.com", "some.long.host.name", "xn--n28h.tld"] diff --git a/swh/model/tests/generate_testdata_from_disk.py b/swh/model/tests/generate_testdata_from_disk.py index 063e3909..3ad45646 100644 --- a/swh/model/tests/generate_testdata_from_disk.py +++ b/swh/model/tests/generate_testdata_from_disk.py @@ -7,7 +7,7 @@ from operator import itemgetter import os import sys -from swh.model.from_disk import Directory, DentryPerms +from swh.model.from_disk import DentryPerms, Directory from swh.model.hashutil import ALGORITHMS, hash_to_hex diff --git a/swh/model/tests/test_from_disk.py b/swh/model/tests/test_from_disk.py index 02561560..497bf6c0 100644 --- a/swh/model/tests/test_from_disk.py +++ b/swh/model/tests/test_from_disk.py @@ -3,19 +3,18 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +from collections import defaultdict import os -import pytest import tarfile import tempfile +from typing import ClassVar, Optional import unittest -from collections import defaultdict -from typing import ClassVar, Optional +import pytest -from swh.model import from_disk +from swh.model import from_disk, model from swh.model.from_disk import Content, DentryPerms, Directory, DiskBackedContent from swh.model.hashutil import DEFAULT_ALGORITHMS, hash_to_bytes, hash_to_hex -from swh.model import model TEST_DATA = os.path.join(os.path.dirname(__file__), "data") diff --git a/swh/model/tests/test_generate_testdata.py b/swh/model/tests/test_generate_testdata.py index aa9c8af3..6ed2e638 100644 --- a/swh/model/tests/test_generate_testdata.py +++ b/swh/model/tests/test_generate_testdata.py @@ -3,9 +3,9 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -from .generate_testdata import gen_contents, gen_origins, ORIGINS +from swh.model.model import BaseContent, Origin -from swh.model.model import Origin, BaseContent +from .generate_testdata import ORIGINS, gen_contents, gen_origins def test_gen_origins_empty(): diff --git a/swh/model/tests/test_hypothesis_strategies.py b/swh/model/tests/test_hypothesis_strategies.py index e1ab9b73..c93b24b9 100644 --- a/swh/model/tests/test_hypothesis_strategies.py +++ b/swh/model/tests/test_hypothesis_strategies.py @@ -6,23 +6,22 @@ import datetime import attr -import iso8601 from hypothesis import given, settings +import iso8601 from swh.model.hashutil import DEFAULT_ALGORITHMS from swh.model.hypothesis_strategies import ( aware_datetimes, - objects, - object_dicts, contents, - skipped_contents, - snapshots, + object_dicts, + objects, origin_visits, persons, + skipped_contents, + snapshots, ) from swh.model.model import TargetType - target_types = ("content", "directory", "revision", "release", "snapshot", "alias") all_but_skipped_content = ( "origin", diff --git a/swh/model/tests/test_identifiers.py b/swh/model/tests/test_identifiers.py index 5acbd2d3..3741b70a 100644 --- a/swh/model/tests/test_identifiers.py +++ b/swh/model/tests/test_identifiers.py @@ -5,9 +5,10 @@ import binascii import datetime -import pytest import unittest +import pytest + from swh.model import hashutil, identifiers from swh.model.exceptions import ValidationError from swh.model.hashutil import hash_to_bytes as _x diff --git a/swh/model/tests/test_model.py b/swh/model/tests/test_model.py index 0404dcd1..fdd5e044 100644 --- a/swh/model/tests/test_model.py +++ b/swh/model/tests/test_model.py @@ -12,41 +12,41 @@ from hypothesis import given from hypothesis.strategies import binary import pytest +from swh.model.hashutil import MultiHash, hash_to_bytes +import swh.model.hypothesis_strategies as strategies +from swh.model.identifiers import ( + SWHID, + directory_identifier, + parse_swhid, + release_identifier, + revision_identifier, + snapshot_identifier, +) from swh.model.model import ( BaseModel, Content, - SkippedContent, Directory, - Revision, - Release, - Snapshot, + MetadataAuthority, + MetadataAuthorityType, + MetadataFetcher, + MetadataTargetType, + MissingData, Origin, OriginVisit, OriginVisitStatus, - Timestamp, - TimestampWithTimezone, - MissingData, Person, RawExtrinsicMetadata, - MetadataTargetType, - MetadataAuthority, - MetadataAuthorityType, - MetadataFetcher, -) -from swh.model.hashutil import hash_to_bytes, MultiHash -import swh.model.hypothesis_strategies as strategies -from swh.model.identifiers import ( - directory_identifier, - revision_identifier, - release_identifier, - snapshot_identifier, - parse_swhid, - SWHID, + Release, + Revision, + SkippedContent, + Snapshot, + Timestamp, + TimestampWithTimezone, ) from swh.model.tests.test_identifiers import ( directory_example, - revision_example, release_example, + revision_example, snapshot_example, ) diff --git a/swh/model/validators.py b/swh/model/validators.py index 6cd7fc11..a2f9dbff 100644 --- a/swh/model/validators.py +++ b/swh/model/validators.py @@ -3,8 +3,8 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -from .exceptions import ValidationError, NON_FIELD_ERRORS from . import fields +from .exceptions import NON_FIELD_ERRORS, ValidationError from .hashutil import MultiHash, hash_to_bytes -- GitLab