Skip to content

Commit 67d3af1

Browse files
fixed imports
1 parent c8b850a commit 67d3af1

File tree

7 files changed

+59
-43
lines changed

7 files changed

+59
-43
lines changed

src/cobra/core/metadata/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
ExternalResources,
66
Qualifier,
77
)
8-
from cobra.core.metadata.history import Creator, HistoryDatetime, History
8+
from cobra.core.metadata.history import Creator, History, HistoryDatetime
99
from cobra.core.metadata.keyvaluepairs import KeyValuePairs
1010
from cobra.core.metadata.metadata import MetaData
1111
from cobra.core.metadata.notes import Notes

src/cobra/core/metadata/history.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
model objects. The history allows to encode who created or modified
44
objects in a model with respective time stamps.
55
"""
6-
from typing import Iterable, Dict, List, Union
76
from datetime import datetime
7+
from typing import Dict, Iterable, List, Union
88

99

1010
class History:
@@ -19,11 +19,12 @@ class History:
1919
modified_dates : list
2020
A list of datetimes when the object was modified.
2121
"""
22+
2223
def __init__(
2324
self,
24-
creators: List['Creator'] = None,
25-
created_date: 'HistoryDatetime' = None,
26-
modified_dates: List['HistoryDatetime'] = None,
25+
creators: List["Creator"] = None,
26+
created_date: "HistoryDatetime" = None,
27+
modified_dates: List["HistoryDatetime"] = None,
2728
):
2829
self._creators = list()
2930
self._created_date = None
@@ -39,7 +40,7 @@ def creators(self) -> List:
3940
return self._creators
4041

4142
@creators.setter
42-
def creators(self, values: Iterable['Creator']) -> None:
43+
def creators(self, values: Iterable["Creator"]) -> None:
4344
self._creators = list()
4445
if values:
4546
self._creators = [Creator.from_data(v) for v in values]
@@ -49,22 +50,21 @@ def created_date(self) -> "HistoryDatetime":
4950
return self._created_date
5051

5152
@created_date.setter
52-
def created_date(self, date: Union[str, 'HistoryDateTime']) -> None:
53+
def created_date(self, date: Union[str, "HistoryDateTime"]) -> None:
5354
self._created_date = HistoryDatetime(date)
5455

5556
@property
5657
def modified_dates(self) -> List:
5758
return self._modified_dates
5859

5960
@modified_dates.setter
60-
def modified_dates(self, dates: Iterable[
61-
Union[str, 'HistoryDateTime']]) -> None:
61+
def modified_dates(self, dates: Iterable[Union[str, "HistoryDateTime"]]) -> None:
6262
self._modified_dates = list()
6363
if dates:
6464
self._modified_dates = [HistoryDatetime(d) for d in dates]
6565

6666
@staticmethod
67-
def from_data(data: Union[Dict, 'History']) -> 'History':
67+
def from_data(data: Union[Dict, "History"]) -> "History":
6868
"""Parse history from data."""
6969
if data is None:
7070
return History()
@@ -88,7 +88,7 @@ def is_empty(self) -> bool:
8888
return False
8989
return True
9090

91-
def __eq__(self, history: 'History') -> bool:
91+
def __eq__(self, history: "History") -> bool:
9292
""" Checking equality of two history objects.
9393
9494
A history is equal if all attributes are equal.
@@ -119,10 +119,10 @@ def to_dict(self):
119119
for modified_date in self._modified_dates:
120120
modified_dates.append(modified_date.datetime)
121121
return {
122-
"creators": [c.to_dict() for c in self.creators],
123-
"created_date": self.created_date.datetime,
124-
"modified_dates": modified_dates
125-
}
122+
"creators": [c.to_dict() for c in self.creators],
123+
"created_date": self.created_date.datetime,
124+
"modified_dates": modified_dates,
125+
}
126126

127127
def __str__(self) -> str:
128128
return str(self.to_dict())
@@ -155,7 +155,7 @@ def __init__(
155155
self.organization_name = organization_name # type: str
156156

157157
@staticmethod
158-
def from_data(data: Union[Dict, 'Creator']) -> 'Creator':
158+
def from_data(data: Union[Dict, "Creator"]) -> "Creator":
159159
"""Parse creator from data."""
160160
if not data:
161161
return Creator()
@@ -183,11 +183,11 @@ def __eq__(self, creator_obj: "Creator") -> bool:
183183

184184
def to_dict(self):
185185
return {
186-
"first_name": self.first_name,
187-
"last_name": self.last_name,
188-
"email": self.email,
189-
"organization_name": self.organization_name,
190-
}
186+
"first_name": self.first_name,
187+
"last_name": self.last_name,
188+
"email": self.email,
189+
"organization_name": self.organization_name,
190+
}
191191

192192
def __str__(self) -> str:
193193
return str(self.to_dict())
@@ -207,6 +207,7 @@ class HistoryDatetime:
207207
datetime: str, datetime
208208
date in the form of a string
209209
"""
210+
210211
def __init__(self, history_datetime: str = None):
211212
self._datetime = None # type: str
212213
self.datetime = history_datetime
@@ -237,7 +238,7 @@ def parse_datetime(self, value: str) -> str:
237238
)
238239

239240
@staticmethod
240-
def utcnow() -> 'HistoryDatetime':
241+
def utcnow() -> "HistoryDatetime":
241242
"""HistoryDatetime with current UTC time."""
242243
utcnow = datetime.utcnow()
243244
value = utcnow.strftime("%Y-%m-%dT%H:%M:%S%z")
@@ -250,8 +251,9 @@ def validate_datetime(datetime_str: str) -> bool:
250251
Raises ValueError if not valid.
251252
"""
252253
if not isinstance(datetime_str, str):
253-
raise TypeError(f"The date passed must be of "
254-
f"type string: {datetime_str}")
254+
raise TypeError(
255+
f"The date passed must be of " f"type string: {datetime_str}"
256+
)
255257

256258
# python 3.6 doesn't allow : (colon) in the utc offset.
257259
try:
@@ -260,7 +262,9 @@ def validate_datetime(datetime_str: str) -> bool:
260262
# checking for python 3.6
261263
if "Z" in datetime_str:
262264
try:
263-
datetime.strptime(datetime_str.replace("Z", ""), "%Y-%m-%dT%H:%M:%S")
265+
datetime.strptime(
266+
datetime_str.replace("Z", ""), "%Y-%m-%dT%H:%M:%S"
267+
)
264268
except ValueError as e1:
265269
raise ValueError(str(e1))
266270
return False
@@ -277,7 +281,7 @@ def validate_datetime(datetime_str: str) -> bool:
277281

278282
return True
279283

280-
def __eq__(self, history_datetime: 'HistoryDatetime') -> bool:
284+
def __eq__(self, history_datetime: "HistoryDatetime") -> bool:
281285
return self.datetime == history_datetime.datetime
282286

283287
def __str__(self) -> str:

src/cobra/core/metadata/keyvaluepairs.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections import OrderedDict
2-
from typing import Dict, Union, Iterable
32
from collections.abc import MutableMapping
3+
from typing import Dict, Iterable, Union
44

55

66
class KeyValueEntry:
@@ -16,16 +16,23 @@ class KeyValueEntry:
1616
value : str
1717
uri : str
1818
"""
19-
def __init__(self, id: str = None, name: str = None,
20-
key: str = None, value: str = None, uri: str = None):
19+
20+
def __init__(
21+
self,
22+
id: str = None,
23+
name: str = None,
24+
key: str = None,
25+
value: str = None,
26+
uri: str = None,
27+
):
2128
self.id = id
2229
self.name = name
2330
self.key = key
2431
self.value = value
2532
self.uri = uri
2633

2734
@staticmethod
28-
def from_data(data: Union[Dict, 'KeyValueEntry']) -> 'KeyValueEntry':
35+
def from_data(data: Union[Dict, "KeyValueEntry"]) -> "KeyValueEntry":
2936
""" Makes a KeyValueDict object using the data passed. """
3037
if data is None:
3138
return KeyValueEntry()
@@ -60,6 +67,7 @@ class KeyValuePairs(MutableMapping):
6067
entries : Iterable
6168
an iterable containing entry information
6269
"""
70+
6371
def __init__(self, entries: Iterable[Union[Dict, KeyValueEntry]] = None):
6472
self.mapping = OrderedDict() # type: OrderedDict[str, KeyValueEntry]
6573
if entries:

src/cobra/core/metadata/metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from collections import OrderedDict, MutableMapping
1+
from collections import MutableMapping, OrderedDict
22
from typing import Dict, Iterator, List, Union
33

44
from cobra.core.metadata.cvterm import CVTerms
5-
from cobra.core.metadata.history import History, Creator, HistoryDatetime
5+
from cobra.core.metadata.history import Creator, History, HistoryDatetime
66
from cobra.core.metadata.keyvaluepairs import KeyValuePairs
77

88

@@ -128,7 +128,7 @@ def to_dict(self) -> Dict:
128128
return d
129129

130130
@staticmethod
131-
def from_dict(data: Dict) -> 'MetaData':
131+
def from_dict(data: Dict) -> "MetaData":
132132
cvterms = data["cvterms"] if "cvterms" in data else None
133133
history = data["history"] if "history" in data else None
134134
keyValuepairs = data["keyvaluepairs"] if "keyvaluepairs" in data else None

src/cobra/core/metadata/notes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Notes(collections.MutableMapping):
5151
notes_xhtml : string
5252
The complete notes (xhtml) data in the form of a string.
5353
"""
54+
5455
# pattern checking for "<p> key : value </p>" type string
5556
PATTERN_PTAG = re.compile(
5657
r"<(?P<prefix>(\w+:)?)p[^>]*>(?P<content>.*?)</(?P=prefix)p>",
@@ -80,7 +81,7 @@ def notes_xhtml(self, value: str) -> None:
8081
else:
8182
raise TypeError(f"notes data must be of type string: {value}")
8283

83-
def __eq__(self, other: 'Notes') -> bool:
84+
def __eq__(self, other: "Notes") -> bool:
8485
if not isinstance(other, Notes):
8586
return False
8687
return self._notes_xhtml == other._notes_xhtml

src/cobra/test/test_core/test_metadata/test_history.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os
2-
import pytest
32
from datetime import datetime
43

5-
from cobra.io import read_sbml_model
4+
import pytest
5+
66
from cobra.core.metadata.history import Creator, History, HistoryDatetime
7+
from cobra.io import read_sbml_model
78

89

910
def _read_ecoli_annotation_model(data_directory):

src/cobra/test/test_core/test_metadata/test_keyvaluepair.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ def test_keyvaluepairs():
2727
"value": "45",
2828
"uri": "https://tinyurl.com/ybyr7b62",
2929
}
30-
entry2 = KeyValueEntry.from_data({
31-
"id": "id2",
32-
"name": "abc_xyz2",
33-
"key": "key2",
34-
"value": "48",
35-
"uri": "https://tinyurl2.com/ybyr7b62",
36-
})
30+
entry2 = KeyValueEntry.from_data(
31+
{
32+
"id": "id2",
33+
"name": "abc_xyz2",
34+
"key": "key2",
35+
"value": "48",
36+
"uri": "https://tinyurl2.com/ybyr7b62",
37+
}
38+
)
3739

3840
kvp = KeyValuePairs(entries=[entry1, entry2])
3941
print(kvp)

0 commit comments

Comments
 (0)