Skip to content

Commit fa3e7d5

Browse files
onefloidMariusWirtz
authored andcommitted
format: reformat the whole project with black
1 parent df8fcf3 commit fa3e7d5

File tree

101 files changed

+11020
-9258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+11020
-9258
lines changed

TM1py/Exceptions/Exceptions.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,33 @@ def __init__(self, function: str):
4444
def __str__(self):
4545
return f"Function '{self.function}' requires admin permissions"
4646

47+
4748
class TM1pyNotDataAdminException(Exception):
4849
def __init__(self, function: str):
4950
self.function = function
5051

5152
def __str__(self):
5253
return f"Function '{self.function}' requires DataAdmin permissions"
53-
54+
55+
5456
class TM1pyNotSecurityAdminException(Exception):
5557
def __init__(self, function: str):
5658
self.function = function
5759

5860
def __str__(self):
5961
return f"Function '{self.function}' requires SecurityAdmin permissions"
60-
62+
63+
6164
class TM1pyNotOpsAdminException(Exception):
6265
def __init__(self, function: str):
6366
self.function = function
6467

6568
def __str__(self):
6669
return f"Function '{self.function}' requires OperationsAdmin permissions"
6770

68-
class TM1pyException(Exception):
69-
""" The default exception for TM1py
7071

71-
"""
72+
class TM1pyException(Exception):
73+
"""The default exception for TM1py"""
7274

7375
def __init__(self, message):
7476
self.message = message
@@ -78,9 +80,7 @@ def __str__(self):
7880

7981

8082
class TM1pyRestException(TM1pyException):
81-
""" Exception for failing REST operations
82-
83-
"""
83+
"""Exception for failing REST operations"""
8484

8585
def __init__(self, response: str, status_code: int, reason: str, headers: Mapping):
8686
super(TM1pyRestException, self).__init__(response)
@@ -106,10 +106,8 @@ def headers(self):
106106

107107
def __str__(self):
108108
return "Text: '{}' - Status Code: {} - Reason: '{}' - Headers: {}".format(
109-
self.message,
110-
self._status_code,
111-
self._reason,
112-
self._headers)
109+
self.message, self._status_code, self._reason, self._headers
110+
)
113111

114112

115113
class TM1pyWriteFailureException(TM1pyException):
@@ -129,6 +127,8 @@ def __init__(self, statuses: List[str], error_log_files: List[str], attempts: in
129127
self.error_log_files = error_log_files
130128
self.attempts = attempts
131129

132-
message = f"{len(self.statuses)} out of {self.attempts} write operations failed partially. " \
133-
f"Details: {self.error_log_files}"
130+
message = (
131+
f"{len(self.statuses)} out of {self.attempts} write operations failed partially. "
132+
f"Details: {self.error_log_files}"
133+
)
134134
super(TM1pyWritePartialFailureException, self).__init__(message)

TM1py/Exceptions/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
from TM1py.Exceptions.Exceptions import TM1pyRestException, TM1pyException, TM1pyTimeout, TM1pyVersionException, \
2-
TM1pyNotAdminException, TM1pyWriteFailureException, TM1pyWritePartialFailureException
1+
from TM1py.Exceptions.Exceptions import (
2+
TM1pyRestException,
3+
TM1pyException,
4+
TM1pyTimeout,
5+
TM1pyVersionException,
6+
TM1pyNotAdminException,
7+
TM1pyWriteFailureException,
8+
TM1pyWritePartialFailureException,
9+
)

TM1py/Objects/Annotation.py

Lines changed: 73 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,33 @@
22

33
import collections
44
import json
5-
from typing import Iterable, Dict, List
5+
from typing import Dict, Iterable, List
66

77
from TM1py.Objects.TM1Object import TM1Object
88
from TM1py.Utils import format_url
99

1010

1111
class Annotation(TM1Object):
12-
""" Abtraction of TM1 Annotation
12+
"""Abtraction of TM1 Annotation
1313
14-
:Notes:
15-
- Class complete, functional and tested.
16-
- doesn't cover Attachments though
14+
:Notes:
15+
- Class complete, functional and tested.
16+
- doesn't cover Attachments though
1717
"""
1818

19-
def __init__(self, comment_value: str, object_name: str, dimensional_context: Iterable[str],
20-
comment_type: str = 'ANNOTATION', annotation_id: str = None,
21-
text: str = '', creator: str = None, created: str = None, last_updated_by: str = None,
22-
last_updated: str = None):
19+
def __init__(
20+
self,
21+
comment_value: str,
22+
object_name: str,
23+
dimensional_context: Iterable[str],
24+
comment_type: str = "ANNOTATION",
25+
annotation_id: str = None,
26+
text: str = "",
27+
creator: str = None,
28+
created: str = None,
29+
last_updated_by: str = None,
30+
last_updated: str = None,
31+
):
2332
self._id = annotation_id
2433
self._text = text
2534
self._creator = creator
@@ -32,26 +41,35 @@ def __init__(self, comment_value: str, object_name: str, dimensional_context: It
3241
self._object_name = object_name
3342

3443
@classmethod
35-
def from_json(cls, annotation_as_json: str) -> 'Annotation':
36-
""" Alternative constructor
44+
def from_json(cls, annotation_as_json: str) -> "Annotation":
45+
"""Alternative constructor
3746
38-
:param annotation_as_json: String, JSON
39-
:return: instance of TM1py.Process
47+
:param annotation_as_json: String, JSON
48+
:return: instance of TM1py.Process
4049
"""
4150
annotation_as_dict = json.loads(annotation_as_json)
42-
annotation_id = annotation_as_dict['ID']
43-
text = annotation_as_dict['Text']
44-
creator = annotation_as_dict['Creator']
45-
created = annotation_as_dict['Created']
46-
last_updated_by = annotation_as_dict['LastUpdatedBy']
47-
last_updated = annotation_as_dict['LastUpdated']
48-
dimensional_context = [item['Name'] for item in annotation_as_dict['DimensionalContext']]
49-
comment_type = annotation_as_dict['commentType']
50-
comment_value = annotation_as_dict['commentValue']
51-
object_name = annotation_as_dict['objectName']
52-
return cls(comment_value=comment_value, object_name=object_name, dimensional_context=dimensional_context,
53-
comment_type=comment_type, annotation_id=annotation_id, text=text, creator=creator, created=created,
54-
last_updated_by=last_updated_by, last_updated=last_updated)
51+
annotation_id = annotation_as_dict["ID"]
52+
text = annotation_as_dict["Text"]
53+
creator = annotation_as_dict["Creator"]
54+
created = annotation_as_dict["Created"]
55+
last_updated_by = annotation_as_dict["LastUpdatedBy"]
56+
last_updated = annotation_as_dict["LastUpdated"]
57+
dimensional_context = [item["Name"] for item in annotation_as_dict["DimensionalContext"]]
58+
comment_type = annotation_as_dict["commentType"]
59+
comment_value = annotation_as_dict["commentValue"]
60+
object_name = annotation_as_dict["objectName"]
61+
return cls(
62+
comment_value=comment_value,
63+
object_name=object_name,
64+
dimensional_context=dimensional_context,
65+
comment_type=comment_type,
66+
annotation_id=annotation_id,
67+
text=text,
68+
creator=creator,
69+
created=created,
70+
last_updated_by=last_updated_by,
71+
last_updated=last_updated,
72+
)
5573

5674
@property
5775
def body(self) -> str:
@@ -98,55 +116,55 @@ def id(self) -> str:
98116
return self._id
99117

100118
def move(self, dimension_order: Iterable[str], dimension: str, target_element: str, source_element: str = None):
101-
""" Move annotation on given dimension from source_element to target_element
102-
103-
:param dimension_order: List, order of the dimensions in the cube
104-
:param dimension: dimension name
105-
:param target_element: target element name
106-
:param source_element: source element name
107-
:return:
119+
"""Move annotation on given dimension from source_element to target_element
120+
121+
:param dimension_order: List, order of the dimensions in the cube
122+
:param dimension: dimension name
123+
:param target_element: target element name
124+
:param source_element: source element name
125+
:return:
108126
"""
109127
for i, dimension_name in enumerate(dimension_order):
110128
if dimension_name.lower() == dimension.lower():
111129
if not source_element or self._dimensional_context[i] == source_element:
112130
self._dimensional_context[i] = target_element
113131

114132
def _construct_body(self) -> Dict:
115-
""" construct the ODATA conform JSON represenation for the Annotation entity.
133+
"""construct the ODATA conform JSON represenation for the Annotation entity.
116134
117-
:return: string, the valid JSON
135+
:return: string, the valid JSON
118136
"""
119-
dimensional_context = [{'Name': element} for element in self._dimensional_context]
137+
dimensional_context = [{"Name": element} for element in self._dimensional_context]
120138
body = collections.OrderedDict()
121-
body['ID'] = self._id
122-
body['Text'] = self._text
123-
body['Creator'] = self._creator
124-
body['Created'] = self._created
125-
body['LastUpdatedBy'] = self._last_updated_by
126-
body['LastUpdated'] = self._last_updated
127-
body['DimensionalContext'] = dimensional_context
128-
comment_locations = ','.join(self._dimensional_context)
129-
body['commentLocation'] = comment_locations[1:]
130-
body['commentType'] = self._comment_type
131-
body['commentValue'] = self._comment_value
132-
body['objectName'] = self._object_name
139+
body["ID"] = self._id
140+
body["Text"] = self._text
141+
body["Creator"] = self._creator
142+
body["Created"] = self._created
143+
body["LastUpdatedBy"] = self._last_updated_by
144+
body["LastUpdated"] = self._last_updated
145+
body["DimensionalContext"] = dimensional_context
146+
comment_locations = ",".join(self._dimensional_context)
147+
body["commentLocation"] = comment_locations[1:]
148+
body["commentType"] = self._comment_type
149+
body["commentValue"] = self._comment_value
150+
body["objectName"] = self._object_name
133151
return body
134152

135153
def construct_body_for_post(self, cube_dimensions) -> Dict:
136154
body = collections.OrderedDict()
137155
body["Text"] = self.text
138-
body["ApplicationContext"] = [{
139-
"[email protected]": "ApplicationContextFacets('}Cubes')",
140-
"Value": self.object_name}]
156+
body["ApplicationContext"] = [
157+
{"[email protected]": "ApplicationContextFacets('}Cubes')", "Value": self.object_name}
158+
]
141159
body["[email protected]"] = []
142160

143161
for dimension, element in zip(cube_dimensions, self.dimensional_context):
144162
coordinates = format_url("Dimensions('{}')/Hierarchies('{}')/Members('{}')", dimension, dimension, element)
145163
body["[email protected]"].append(coordinates)
146164

147-
body['objectName'] = self.object_name
148-
body['commentValue'] = self.comment_value
149-
body['commentType'] = 'ANNOTATION'
150-
body['commentLocation'] = ','.join(self.dimensional_context)
165+
body["objectName"] = self.object_name
166+
body["commentValue"] = self.comment_value
167+
body["commentType"] = "ANNOTATION"
168+
body["commentLocation"] = ",".join(self.dimensional_context)
151169

152170
return body

TM1py/Objects/Application.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from TM1py.Objects.TM1Object import TM1Object
99
from TM1py.Utils import format_url
1010

11-
ApplicationType = namedtuple('ApplicationType', ['value', 'suffix', 'odata_type'])
11+
ApplicationType = namedtuple("ApplicationType", ["value", "suffix", "odata_type"])
1212

1313

1414
class ApplicationTypes(Enum):
@@ -43,7 +43,7 @@ def __init__(self, path: str, name: str, application_type: Union[ApplicationType
4343
self.path = path
4444
# remove suffix from name
4545
if application_type.suffix and name.endswith(application_type.suffix):
46-
self.name = name[: - len(application_type.suffix)]
46+
self.name = name[: -len(application_type.suffix)]
4747
else:
4848
self.name = name
4949
# raise ValueError if not a valid type
@@ -103,8 +103,9 @@ def body(self) -> str:
103103

104104

105105
class DocumentApplication(Application):
106-
def __init__(self, path: str, name: str, content: bytes, file_id: str = None, file_name: str = None,
107-
last_updated: str = None):
106+
def __init__(
107+
self, path: str, name: str, content: bytes, file_id: str = None, file_name: str = None, last_updated: str = None
108+
):
108109
super().__init__(path, name, ApplicationTypes.DOCUMENT)
109110
self.content = content
110111
# below fields only populated for retrieved applications
@@ -113,10 +114,7 @@ def __init__(self, path: str, name: str, content: bytes, file_id: str = None, fi
113114
self.last_updated = last_updated
114115

115116
def to_xlsx(self, path_to_file: str):
116-
warnings.warn(
117-
f"Function 'to_xlsx' is deprecated. Use 'to_file' instead",
118-
DeprecationWarning,
119-
stacklevel=2)
117+
warnings.warn(f"Function 'to_xlsx' is deprecated. Use 'to_file' instead", DeprecationWarning, stacklevel=2)
120118
return self.to_file(path_to_file=path_to_file)
121119

122120
def to_file(self, path_to_file: str):
@@ -170,7 +168,10 @@ def body(self) -> str:
170168
body_as_dict = self.body_as_dict
171169
body_as_dict["[email protected]"] = format_url(
172170
"Dimensions('{}')/Hierarchies('{}')/Subsets('{}')",
173-
self.dimension_name, self.hierarchy_name, self.subset_name)
171+
self.dimension_name,
172+
self.hierarchy_name,
173+
self.subset_name,
174+
)
174175
return json.dumps(body_as_dict, ensure_ascii=False)
175176

176177

0 commit comments

Comments
 (0)