Skip to content

Commit

Permalink
Make sure it can import
Browse files Browse the repository at this point in the history
  • Loading branch information
ksunden committed Aug 28, 2020
1 parent bac5755 commit 44a0cca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
18 changes: 11 additions & 7 deletions attune/_store.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
__all__ = ["load", "restore", "redo", "store", "undo"]
__all__ = ["load", "restore", "store", "undo"]


import appdirs
import attune
from datetime import datetime, timezone
from datetime import datetime, timedelta, timezone
import json
import pathlib
import os
Expand All @@ -29,15 +29,19 @@ def find(name, time, reverse):
attune_dir = pathlib.Path(appdirs.user_data_dir("attune", "attune"))

if not (attune_dir / name).exists():
raise ValueError(f"No instrument found with name {name}")
raise ValueError(f"No instrument found with name '{name}'")

while True:
datadir = attune_dir
datadir /= name
datadir /= str(year)
datadir /= f"{month:02}"
if datadir.exists():
for d in sorted(datadir.iterdir(), reverse=reverse):
for d in sorted(
datadir.iterdir(),
key=lambda x: dateutil.parser.isoparse(x.name),
reverse=reverse,
):
if reverse:
if dateutil.parser.isoparse(d.name) <= time:
return datadir / d.name
Expand All @@ -64,7 +68,7 @@ def find(name, time, reverse):
if year > datetime.now().year + 20:
raise ValueError(f"Could not find an instrument later than {time}.")

datadir = find(name, time, direction)
datadir = find(name, time, reverse)
return attune.open(datadir / "instrument.json", load=dateutil.parser.isoparse(datadir.name))


Expand Down Expand Up @@ -94,7 +98,7 @@ def _store_instr(instrument):
attune_dir = pathlib.Path(appdirs.user_data_dir("attune", "attune"))

while True:
now = datetime.utcnow()
now = datetime.now(timezone.utc)
# make datadir
datadir = attune_dir
datadir /= instrument.name
Expand All @@ -115,7 +119,7 @@ def _store_instr(instrument):
if instrument.transition.data is not None:
instrument.transition.data.save(datadir / "data.wt5")
# store old instrument
if instrunment.transition.previous is not None:
if instrument.transition.previous is not None:
with open(datadir / "previous_instrument.json", "w") as f:
instrument.transition.previous.save(f)

Expand Down
11 changes: 8 additions & 3 deletions attune/_transition.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
return__all__ = ["Transition", "TransitionType"]

from enum import Enum
from typing import Any, Optional, Dict, TYPE_CHECKING

import WrightTools as wt

if TYPE_CHECKING:
import WrightTools as wt

from ._instrument import Instrument


class TransitionType(str, Enum):
Expand All @@ -23,9 +28,9 @@ class Transition:
def __init__(
self,
type: TransitionType,
previous: Optional[Instrument] = None,
previous: Optional["Instrument"] = None,
metadata: Optional[Dict[str, Any]] = None,
data: Optional[wt.Data] = None,
data: Optional["wt.Data"] = None,
):
self.type = type
self.previous = previous
Expand Down

0 comments on commit 44a0cca

Please sign in to comment.