Skip to content

Commit

Permalink
Update pre-commit repo versions and configure isort to properly handl…
Browse files Browse the repository at this point in the history
…e "from . import" lines
  • Loading branch information
jwodder committed Jun 7, 2021
1 parent 8aa9f7f commit 76f9dbc
Show file tree
Hide file tree
Showing 20 changed files with 35 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 21.5b2
hooks:
- id: black
exclude: ^(dandi/_version\.py|dandi/due\.py|versioneer\.py)$
- repo: https://github.com/PyCQA/isort
rev: 5.7.0
rev: 5.8.0
hooks:
- id: isort
exclude: ^(dandi/_version\.py|dandi/due\.py|versioneer\.py)$
Expand Down
2 changes: 1 addition & 1 deletion dandi/cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import click

from ..consts import known_instances
from .. import get_logger, set_logger_level # noqa: F401
from ..consts import known_instances

lgr = get_logger()

Expand Down
2 changes: 1 addition & 1 deletion dandi/cli/cmd_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@click.argument("paths", nargs=-1, type=click.Path(exists=True, dir_okay=False))
@map_to_click_exceptions
def digest(paths, digest_alg):
""" Calculate file digests """
"""Calculate file digests"""
from ..support.digests import get_digest

for p in paths:
Expand Down
2 changes: 1 addition & 1 deletion dandi/cli/cmd_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
@click.argument("paths", nargs=-1, type=click.Path(exists=False, dir_okay=True))
@map_to_click_exceptions
def ls(paths, schema, metadata, fields=None, format="auto", recursive=False, jobs=6):
""" List .nwb files and dandisets metadata. """
"""List .nwb files and dandisets metadata."""

# TODO: more logical ordering in case of fields = None
from .formatter import (
Expand Down
4 changes: 2 additions & 2 deletions dandi/dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import requests
import tenacity

from .consts import MAX_CHUNK_SIZE, known_instances_rev
from . import get_logger
from .consts import MAX_CHUNK_SIZE, known_instances_rev
from .keyring import keyring_lookup
from .utils import USER_AGENT, is_interactive, try_multiple

Expand Down Expand Up @@ -334,7 +334,7 @@ def delete_dandiset(self, dandiset_id):
def get_dandiset_assets(
self, dandiset_id, version, page_size=None, path=None, include_metadata=False
):
""" A generator to provide asset records """
"""A generator to provide asset records"""
resp = self.get(
f"/dandisets/{dandiset_id}/versions/{version}/assets/",
parameters={"page_size": page_size, "path": path},
Expand Down
18 changes: 9 additions & 9 deletions dandi/dandiarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from pydantic import AnyHttpUrl, BaseModel, parse_obj_as, validator
import requests

from . import get_logger
from .consts import known_instances
from .dandiapi import DandiAPIClient
from .exceptions import FailedToConnectError, NotFoundError, UnknownURLError
from . import get_logger
from .utils import get_instance

lgr = get_logger()
Expand Down Expand Up @@ -41,7 +41,7 @@ def _validate_api_url(cls, v: AnyHttpUrl) -> AnyHttpUrl:
return parse_obj_as(AnyHttpUrl, v.rstrip("/"))

def get_client(self) -> DandiAPIClient:
""" Returns an unauthenticated `DandiAPIClient` for `api_url` """
"""Returns an unauthenticated `DandiAPIClient` for `api_url`"""
return DandiAPIClient(self.api_url)

def get_dandiset(self, client: DandiAPIClient) -> dict:
Expand Down Expand Up @@ -119,7 +119,7 @@ class DandisetURL(ParsedDandiURL):
def get_assets(
self, client: DandiAPIClient, include_metadata: bool = False
) -> Iterator[dict]:
""" Returns all assets in the Dandiset """
"""Returns all assets in the Dandiset"""
return client.get_dandiset_assets(
self.dandiset_id,
self.get_version_id(client),
Expand All @@ -128,19 +128,19 @@ def get_assets(


class SingleAssetURL(ParsedDandiURL):
""" Superclass for parsed URLs that refer to a single asset """
"""Superclass for parsed URLs that refer to a single asset"""

pass


class MultiAssetURL(ParsedDandiURL):
""" Superclass for parsed URLs that refer to multiple assets """
"""Superclass for parsed URLs that refer to multiple assets"""

path: str


class AssetIDURL(SingleAssetURL):
""" Parsed from a URL that refers to an asset by ID """
"""Parsed from a URL that refers to an asset by ID"""

asset_id: str

Expand Down Expand Up @@ -172,7 +172,7 @@ def get_assets(
}

def get_asset_ids(self, client: DandiAPIClient) -> Iterator[str]:
""" Yields the ID of the asset (regardless of whether it exists) """
"""Yields the ID of the asset (regardless of whether it exists)"""
yield self.asset_id


Expand All @@ -184,7 +184,7 @@ class AssetPathPrefixURL(MultiAssetURL):
def get_assets(
self, client: DandiAPIClient, include_metadata: bool = False
) -> Iterator[dict]:
""" Returns the assets whose paths start with `path` """
"""Returns the assets whose paths start with `path`"""
return client.get_dandiset_assets(
self.dandiset_id,
self.get_version_id(client),
Expand All @@ -194,7 +194,7 @@ def get_assets(


class AssetItemURL(SingleAssetURL):
""" Parsed from a URL that refers to a specific asset by path """
"""Parsed from a URL that refers to a specific asset by path"""

path: str

Expand Down
2 changes: 1 addition & 1 deletion dandi/dandiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from dandischema.models import get_schema_version

from .consts import dandiset_metadata_file
from . import get_logger
from .consts import dandiset_metadata_file
from .utils import find_parent_directory_containing, yaml_dump, yaml_load

lgr = get_logger()
Expand Down
2 changes: 1 addition & 1 deletion dandi/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import humanize
import requests

from . import get_logger
from .consts import dandiset_metadata_file
from .dandiarchive import DandisetURL, MultiAssetURL, SingleAssetURL, parse_dandi_url
from .dandiset import Dandiset
from . import get_logger
from .support.digests import get_digest
from .support.pyout import naturalsize
from .utils import (
Expand Down
2 changes: 1 addition & 1 deletion dandi/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LockingError(RuntimeError):


class CliVersionError(RuntimeError):
""" Base class for `CliVersionTooOldError` and `BadCliVersionError` """
"""Base class for `CliVersionTooOldError` and `BadCliVersionError`"""

def __init__(self, our_version, minversion, bad_versions):
self.our_version = our_version
Expand Down
2 changes: 1 addition & 1 deletion dandi/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from dandischema import models

from .dandiset import Dandiset
from . import __version__, get_logger
from .dandiset import Dandiset
from .pynwb_utils import (
_get_pynwb_metadata,
get_neurodata_types,
Expand Down
4 changes: 2 additions & 2 deletions dandi/organize.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import numpy as np

from .exceptions import OrganizeImpossibleError
from . import get_logger
from .exceptions import OrganizeImpossibleError
from .pynwb_utils import get_neurodata_types_to_modalities_map, get_object_id
from .utils import ensure_datetime, flattened, yaml_load

Expand Down Expand Up @@ -230,7 +230,7 @@ def _get_hashable(v):


def _get_unique_values_among_non_unique(metadata, non_unique_paths, field):
"""Per each non-unique path return values """
"""Per each non-unique path return values"""
return {
_get_hashable(r.get(field))
for r in metadata
Expand Down
2 changes: 1 addition & 1 deletion dandi/pynwb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
from pynwb import NWBHDF5IO
import semantic_version

from . import __version__, get_logger
from .consts import (
metadata_nwb_computed_fields,
metadata_nwb_file_fields,
metadata_nwb_subject_fields,
)
from . import __version__, get_logger
from .utils import get_module_version

lgr = get_logger()
Expand Down
2 changes: 1 addition & 1 deletion dandi/support/pyout.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import humanize
import pyout

from ..consts import metadata_dandiset_fields, metadata_nwb_fields
from .. import get_logger
from ..consts import metadata_dandiset_fields, metadata_nwb_fields

lgr = get_logger()

Expand Down
2 changes: 1 addition & 1 deletion dandi/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import requests

from .skip import skipif
from .. import get_logger
from ..cli.command import organize
from ..consts import dandiset_metadata_file, known_instances
from ..dandiapi import DandiAPIClient
from .. import get_logger
from ..pynwb_utils import make_nwb_file, metadata_nwb_file_fields
from ..upload import upload

Expand Down
2 changes: 1 addition & 1 deletion dandi/tests/test_dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import click

from .. import dandiapi
from ..consts import dandiset_metadata_file
from ..dandiapi import DandiAPIClient
from ..download import download
from .. import dandiapi
from ..upload import upload
from ..utils import find_files

Expand Down
2 changes: 1 addition & 1 deletion dandi/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import responses
from semantic_version import Version

from .. import __version__
from ..consts import dandi_instance, known_instances
from ..exceptions import BadCliVersionError, CliVersionTooOldError
from .. import __version__
from ..utils import (
ensure_datetime,
ensure_strtime,
Expand Down
2 changes: 1 addition & 1 deletion dandi/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import click

from .consts import dandiset_identifier_regex, dandiset_metadata_file
from . import lgr
from .consts import dandiset_identifier_regex, dandiset_metadata_file
from .utils import ensure_datetime, get_instance, pluralize


Expand Down
8 changes: 4 additions & 4 deletions dandi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
except ImportError:
# TODO - remove whenever python >= 3.8
from importlib_metadata import version as importlib_version

import inspect
import io
import itertools
Expand All @@ -26,13 +27,12 @@
from semantic_version import Version
import tenacity

from .consts import dandi_instance, known_instances, known_instances_rev
from .exceptions import BadCliVersionError, CliVersionTooOldError

#
# Additional handlers
#
from . import __version__, get_logger
from .consts import dandi_instance, known_instances, known_instances_rev
from .exceptions import BadCliVersionError, CliVersionTooOldError

lgr = get_logger()

Expand Down Expand Up @@ -362,7 +362,7 @@ def good_file(path):


def copy_file(src, dst):
""" Copy file from src to dst """
"""Copy file from src to dst"""
global _cp_supports_reflink
if _cp_supports_reflink is None:
r = subprocess.run(
Expand Down
2 changes: 1 addition & 1 deletion dandi/validate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os.path as op

from .consts import dandiset_metadata_file
from . import get_logger
from .consts import dandiset_metadata_file
from .metadata import get_metadata
from .pynwb_utils import validate as pynwb_validate
from .pynwb_utils import validate_cache
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ exclude='\.eggs|\.git|\.mypy_cache|\.tox|\.venv|_build|buck-out|build|dist|_vers
profile = "black"
force_sort_within_sections = true
reverse_relative = true
sort_relative_in_force_sorted_sections = true
known_first_party = ["dandi"]

0 comments on commit 76f9dbc

Please sign in to comment.