Skip to content

Commit

Permalink
Merge pull request #422 from dandi/cleanup-code
Browse files Browse the repository at this point in the history
Assorted code cleanup
  • Loading branch information
yarikoptic authored Feb 25, 2021
2 parents 5d1d8a8 + 756506c commit 41000ee
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 23 deletions.
2 changes: 0 additions & 2 deletions dandi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ def set_logger_level(lgr, level):
lgr.setLevel(level)


_DEFAULT_LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"

lgr = get_logger()
# Basic settings for output, for now just basic
set_logger_level(lgr, os.environ.get("DANDI_LOG_LEVEL", logging.INFO))
Expand Down
5 changes: 1 addition & 4 deletions dandi/dandiset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Classes/utilities for support of a dandiset"""
import json
import os
from pathlib import Path

Expand Down Expand Up @@ -149,6 +148,4 @@ def _load_metadata(self):
# models as metadata, so we take dict representation
# Do R/T through json since it then maps types, although
# "access" has a side-effect: https://github.com/dandi/dandi-cli/issues/343
self.metadata = json.loads(
migrate2newschema(self.metadata).json(exclude_unset=True, exclude_none=True)
)
self.metadata = migrate2newschema(self.metadata).json_dict()
4 changes: 2 additions & 2 deletions dandi/tests/test_organize.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_organize_nwb_test_data(nwb_test_data, tmpdir, clirunner, mode):
assert not any(op.islink(p) for p in produced_paths)


def test_ambigous(simple2_nwb, tmp_path, clirunner):
def test_ambiguous(simple2_nwb, tmp_path, clirunner):
copy2 = copy_nwb_file(simple2_nwb, tmp_path)
outdir = str(tmp_path / "organized")
args = ["--files-mode", "copy", "-d", outdir, simple2_nwb, copy2]
Expand All @@ -198,7 +198,7 @@ def test_ambigous(simple2_nwb, tmp_path, clirunner):
)


def test_ambiguos_probe1():
def test_ambiguous_probe1():
base = dict(subject_id="1", session="2", extension="nwb")
# fake filenames should be ok since we never should get to reading them for object_id
metadata = [
Expand Down
20 changes: 7 additions & 13 deletions dandi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,13 @@ def ensure_strtime(t, isoformat=True):
raise TypeError(f"Do not know how to convert {t_orig!r} to string datetime")


def fromisoformat(t, impl=None):
if impl is None:
# datetime parser "does not support parsing arbitrary ISO 8601 strings"
# https://docs.python.org/3/library/datetime.html
# In particular it does not parse time zone suffix which was recently
# introduced into datetime's provided by API
impl = "dateutil"
if impl == "datetime":
return datetime.datetime.fromisoformat(t)
elif impl == "dateutil":
return dateutil.parser.isoparse(t)
else:
raise ValueError(impl)
def fromisoformat(t):
# datetime.fromisoformat "does not support parsing arbitrary ISO 8601
# strings" <https://docs.python.org/3/library/datetime.html>. In
# particular, it does not parse the time zone suffixes recently
# introduced into timestamps provided by the API. Hence, we need to use
# dateutil instead.
return dateutil.parser.isoparse(t)


def ensure_datetime(t, strip_tzinfo=False, tz=None):
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ description = Command line client for interaction with DANDI archive elements
long_description = file:README.md
long_description_content_type = text/markdown; charset=UTF-8
platforms = OS Independent
provides =
dandi
project_urls =
Source Code = https://github.com/dandi/dandi-cli

Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extras = test
commands =
# Using pytest-cov instead of using coverage directly leaves a bunch of
# .coverage.$HOSTNAME.#.# files lying around for some reason
coverage erase
coverage run -m pytest -v {posargs} dandi
coverage combine
coverage report
Expand Down

0 comments on commit 41000ee

Please sign in to comment.