Skip to content

Commit

Permalink
Apply isort
Browse files Browse the repository at this point in the history
  • Loading branch information
jl-wynen committed Dec 1, 2022
1 parent d7e54d4 commit 487fa78
Show file tree
Hide file tree
Showing 31 changed files with 70 additions and 63 deletions.
5 changes: 2 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import doctest

import scitacean

import os
import sys

import scitacean

sys.path.insert(0, os.path.abspath("."))

# General information about the project.
Expand Down
2 changes: 1 addition & 1 deletion src/scitacean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
except importlib.metadata.PackageNotFoundError:
__version__ = "0.0.0"

from ._dataset_fields import DatasetType
from .client import Client
from .dataset import Dataset
from .error import ScicatCommError, ScicatLoginError
from .file import File
from .pid import PID
from ._dataset_fields import DatasetType

__all__ = (
"Client",
Expand Down
14 changes: 7 additions & 7 deletions src/scitacean/_dataset_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import dataclasses
from datetime import datetime, timezone
from typing import Any, Callable, Dict, Generator, Literal, List, Optional, Union
from typing import Any, Callable, Dict, Generator, List, Literal, Optional, Union

import dateutil.parser

Expand Down Expand Up @@ -88,7 +88,7 @@ def required(self, dataset_type: DatasetType) -> bool:
),
Field(
name="contact_email",
description="Email of contact person for this dataset. May contain a list of emails, which should then be seperated by semicolons.",
description="Email of contact person for this dataset. May contain a list of emails, which should then be separated by semicolons.",
read_only=False,
required_by_derived=True,
required_by_raw=True,
Expand Down Expand Up @@ -328,7 +328,7 @@ def required(self, dataset_type: DatasetType) -> bool:
),
Field(
name="owner",
description="Owner or custodian of the dataset, usually first name + lastname. The string may contain a list of persons, which should then be seperated by semicolons.",
description="Owner or custodian of the dataset, usually first name + lastname. The string may contain a list of persons, which should then be separated by semicolons.",
read_only=False,
required_by_derived=True,
required_by_raw=True,
Expand All @@ -338,7 +338,7 @@ def required(self, dataset_type: DatasetType) -> bool:
),
Field(
name="owner_email",
description="Email of owner or of custodian of the dataset. The string may contain a list of emails, which should then be seperated by semicolons.",
description="Email of owner or of custodian of the dataset. The string may contain a list of emails, which should then be separated by semicolons.",
read_only=False,
required_by_derived=False,
required_by_raw=False,
Expand Down Expand Up @@ -628,7 +628,7 @@ def classification(self, val: Optional[str]):

@property
def contact_email(self) -> Optional[str]:
"""Email of contact person for this dataset. May contain a list of emails, which should then be seperated by semicolons."""
"""Email of contact person for this dataset. May contain a list of emails, which should then be separated by semicolons."""
return self._fields["contact_email"]

@contact_email.setter
Expand Down Expand Up @@ -800,7 +800,7 @@ def orcid_of_owner(self, val: Optional[str]):

@property
def owner(self) -> Optional[str]:
"""Owner or custodian of the dataset, usually first name + lastname. The string may contain a list of persons, which should then be seperated by semicolons."""
"""Owner or custodian of the dataset, usually first name + lastname. The string may contain a list of persons, which should then be separated by semicolons."""
return self._fields["owner"]

@owner.setter
Expand All @@ -809,7 +809,7 @@ def owner(self, val: Optional[str]):

@property
def owner_email(self) -> Optional[str]:
"""Email of owner or of custodian of the dataset. The string may contain a list of emails, which should then be seperated by semicolons."""
"""Email of owner or of custodian of the dataset. The string may contain a list of emails, which should then be separated by semicolons."""
return self._fields["owner_email"]

@owner_email.setter
Expand Down
4 changes: 2 additions & 2 deletions src/scitacean/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

import requests

from . import model
from .dataset import Dataset
from .error import ScicatCommError, ScicatLoginError
from .logging import get_logger
from .pid import PID
from .typing import FileTransfer
from .util.credentials import SecretStr, StrStorage
from . import model


class Client:
Expand Down Expand Up @@ -532,7 +532,7 @@ def _get_token(url: str, username: StrStorage, password: StrStorage) -> str:
# Users/login only works for functional accounts and auth/msad for regular users.
# Try both and see what works. This is not nice but seems to be the only
# feasible solution right now.
get_logger().info("Loging in to %s", url)
get_logger().info("Logging in to %s", url)

response = _log_in_via_users_login(url=url, username=username, password=password)
if response.ok:
Expand Down
3 changes: 2 additions & 1 deletion src/scitacean/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"""Main dataset structure."""

from __future__ import annotations

import html
from dataclasses import dataclass
from datetime import datetime
import html
from pathlib import Path
from typing import Any, Dict, Iterable, List, Optional, Union

Expand Down
8 changes: 4 additions & 4 deletions src/scitacean/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"""Class to represent files."""

from __future__ import annotations
from datetime import datetime, timezone

import hashlib
import os
from datetime import datetime, timezone
from pathlib import Path, PurePosixPath
from typing import Optional, Union


from .error import IntegrityError
from .logging import get_logger
from .model import DataFile
Expand Down Expand Up @@ -66,7 +66,7 @@ def from_local(
-> remote_path: folder/file.nxs
-> actual remote location: remote/storage/folder/file.nxs
``remote_path`` can also be overriden, in which case ``path`` and
``remote_path`` can also be overridden, in which case ``path`` and
``base_path`` are not used to deduce the "actual remote location".
Parameters
Expand Down Expand Up @@ -250,7 +250,7 @@ def _new_hash(algorithm: str):
return hashlib.new(algorithm)


# size based on http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f=src/ioblksize.h;h=ed2f4a9c4d77462f357353eb73ee4306c28b37f1;hb=HEAD#l23 # noqa
# size based on http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f=src/ioblksize.h;h=ed2f4a9c4d77462f357353eb73ee4306c28b37f1;hb=HEAD#l23 # noqa: E501
def checksum_of_file(path: Union[str, Path], *, algorithm: str) -> str:
chk = _new_hash(algorithm)
buffer = memoryview(bytearray(128 * 1024))
Expand Down
2 changes: 1 addition & 1 deletion src/scitacean/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

"""Pydantic models to encode data for communication with SciCat."""

from datetime import datetime
import enum
from datetime import datetime
from typing import Dict, List, Optional

import pydantic
Expand Down
3 changes: 2 additions & 1 deletion src/scitacean/pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# Copyright (c) 2022 Scitacean contributors (https://github.com/SciCatProject/scitacean)
# @author Jan-Lukas Wynen
from __future__ import annotations
from typing import Optional

import uuid
from typing import Optional


class PID:
Expand Down
8 changes: 4 additions & 4 deletions src/scitacean/testing/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
from __future__ import annotations

import functools
import uuid
from copy import deepcopy
from pathlib import Path
from typing import Dict, List, Optional, Union
import uuid

from .. import model
from ..client import Client, ScicatClient
from ..dataset import Dataset
from ..error import ScicatCommError
from ..pid import PID
from ..typing import FileTransfer
from ..util.credentials import StrStorage
from .. import model


def _conditionally_disabled(func):
Expand Down Expand Up @@ -121,7 +121,7 @@ def __init__(
"""
# Normally, client must not be None, but the fake must never
# call it, so setting it to None serves as an extra safeguard.
super().__init__(client=None, file_transfer=file_transfer) # noqa
super().__init__(client=None, file_transfer=file_transfer) # type: ignore

self._scicat_client = FakeScicatClient(self)
self.disabled = {} if disable is None else dict(disable)
Expand Down Expand Up @@ -206,7 +206,7 @@ class FakeScicatClient(ScicatClient):
"""Mimics a ScicatClient, to be used by FakeClient."""

def __init__(self, main_client):
super().__init__(url="", token="") # noqa # nosec
super().__init__(url="", token="") # nosec: B106
self.main = main_client

@_conditionally_disabled
Expand Down
2 changes: 1 addition & 1 deletion src/scitacean/testing/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from dateutil.parser import parse as parse_date

from ..model import DataFile, DatasetType, OrigDatablock, RawDataset
from ..pid import PID
from .client import FakeClient
from ..model import DataFile, DatasetType, OrigDatablock, RawDataset
from .transfer import FakeFileTransfer


Expand Down
7 changes: 4 additions & 3 deletions src/scitacean/testing/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from functools import partial
from typing import Dict, Optional

from email_validator import validate_email, EmailNotValidError
from scitacean import Dataset, DatasetType, PID
from scitacean._internal.orcid import orcid_checksum
from email_validator import EmailNotValidError, validate_email
from hypothesis import strategies as st

from scitacean import PID, Dataset, DatasetType
from scitacean._internal.orcid import orcid_checksum


# email_validator and by extension pydantic is more picky than hypothesis
# so make sure that generated emails actually pass model validation.
Expand Down
2 changes: 1 addition & 1 deletion src/scitacean/testing/transfer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2022 Scitacean contributors (https://github.com/SciCatProject/scitacean)
# @author Jan-Lukas Wynen
from contextlib import contextmanager
import os
from contextlib import contextmanager
from pathlib import Path
from typing import Any, Dict, Optional, Union

Expand Down
4 changes: 2 additions & 2 deletions src/scitacean/transfer/ess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# Copyright (c) 2022 Scitacean contributors (https://github.com/SciCatProject/scitacean)
# @author Jan-Lukas Wynen

import os
from contextlib import contextmanager
from getpass import getpass
import os
from pathlib import Path
from typing import Union, Tuple, Optional
from typing import Optional, Tuple, Union

# These are quite heavy dependencies.
# It would be great if we could do without them in the long run.
Expand Down
1 change: 1 addition & 0 deletions src/scitacean/util/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# @author Jan-Lukas Wynen
"""Tools for securely handling credentials."""
from __future__ import annotations

import datetime
from typing import Optional, Union

Expand Down
9 changes: 4 additions & 5 deletions tests/client_test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2022 Scitacean contributors (https://github.com/SciCatProject/scitacean)
# @author Jan-Lukas Wynen
from copy import deepcopy
import pickle
from copy import deepcopy

from dateutil.parser import parse as parse_date
import pytest
from scitacean.model import DataFile, DatasetType, DerivedDataset, OrigDatablock
from scitacean import PID, ScicatCommError
from dateutil.parser import parse as parse_date

from scitacean import PID, Client, ScicatCommError
from scitacean.model import DataFile, DatasetType, DerivedDataset, OrigDatablock
from scitacean.testing.client import FakeClient
from scitacean.util.credentials import SecretStr
from scitacean import Client

from . import data
from .common.backend import skip_if_not_backend
Expand Down
5 changes: 2 additions & 3 deletions tests/common/backend.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import json
from pathlib import Path
import requests
import shutil
import subprocess
import time
from pathlib import Path
from urllib.parse import urljoin

import pytest
import requests

from ..data import load_datasets, load_orig_datablocks


_TEST_BASE = Path(__file__).resolve().parent.parent
_SCICAT_DOCKER_CONFIG = _TEST_BASE / "scicatlive/docker-compose.yaml"
_SCICAT_DATASET_SEED_FILE = Path("seed_db/seed/Dataset.json")
Expand Down
2 changes: 1 addition & 1 deletion tests/common/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Copyright (c) 2022 Scitacean contributors (https://github.com/SciCatProject/scitacean)
# @author Jan-Lukas Wynen

from datetime import datetime, timezone
import hashlib
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Dict, Optional, Union

Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from dataclasses import dataclass
import tempfile
from dataclasses import dataclass
from typing import Dict

import hypothesis
import pytest

from .common import backend


# The datasets strategy requires a large amount of memory and time.
# This is not good but hard to avoid.
# So simply disable health checks and accept that tests are slow.
Expand Down
3 changes: 1 addition & 2 deletions tests/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
# Copyright (c) 2022 Scitacean contributors (https://github.com/SciCatProject/scitacean)
# @author Jan-Lukas Wynen
"""Handle input data for tests."""
from functools import lru_cache
import json
from functools import lru_cache
from pathlib import Path

from scitacean.model import DerivedDataset, OrigDatablock, RawDataset


_BASE_PATH = Path(__file__).resolve().parent


Expand Down
10 changes: 6 additions & 4 deletions tests/dataset_fields_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
from datetime import datetime, timedelta, timezone

import dateutil.parser
from hypothesis import given, settings, strategies as st
import pydantic
import pytest
from scitacean.model import DataFile, DerivedDataset, OrigDatablock, RawDataset
from hypothesis import given, settings
from hypothesis import strategies as st

from scitacean import Dataset, DatasetType
from scitacean.model import DataFile, DerivedDataset, OrigDatablock, RawDataset


def test_init_dataset_with_only_type():
Expand All @@ -32,12 +34,12 @@ def test_init_dataset_accepted_types(typ):

def test_init_dataset_raises_for_bad_type():
with pytest.raises(ValueError):
Dataset(type="bad-type") # noqa
Dataset(type="bad-type") # type: ignore


def test_init_dataset_needs_type():
with pytest.raises(TypeError):
Dataset() # noqa
Dataset() # type: ignore


def test_init_dataset_sets_creation_time():
Expand Down
Loading

0 comments on commit 487fa78

Please sign in to comment.