Skip to content

Commit e630ac5

Browse files
authored
Merge pull request #167 from Chrezm/documentation
Documentation
2 parents 62a18d9 + 6d0b307 commit e630ac5

File tree

7 files changed

+705
-48
lines changed

7 files changed

+705
-48
lines changed

server/area_manager.py

Lines changed: 116 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@
4848

4949
class AreaManager(AssetManager):
5050
"""
51-
Create a new manager for the areas in a server.
52-
Contains the Area object definition, as well as the server's area list.
51+
A manager for areas. Area managers store a list of areas either from a
52+
loaded file or an adequate Python representation.
53+
It also contains the Area object definition.
5354
"""
5455

5556
class Area:
@@ -1148,14 +1149,14 @@ def __init__(self, server: TsuserverDR):
11481149
Parameters
11491150
----------
11501151
server: TsuserverDR
1151-
The server this area belongs to.
1152+
The server this area manager belongs to.
11521153
"""
11531154

11541155
super().__init__(server)
11551156
self._areas = []
11561157
self._source_file = 'config/areas.yaml'
11571158
self.area_names = set()
1158-
self.load_areas()
1159+
self.load_file(self._source_file)
11591160

11601161
@property
11611162
def areas(self) -> List[Area]:
@@ -1165,28 +1166,92 @@ def areas(self) -> List[Area]:
11651166
return self.get_areas()
11661167

11671168
def get_name(self) -> str:
1169+
"""
1170+
Return `'area list'`.
1171+
1172+
Returns
1173+
-------
1174+
str
1175+
`'area list'`.
1176+
"""
1177+
11681178
return 'area list'
11691179

11701180
def get_default_file(self) -> str:
1181+
"""
1182+
Return `'config/areas.yaml'`.
1183+
1184+
Returns
1185+
-------
1186+
str
1187+
`'config/areas.yaml'`.
1188+
"""
1189+
11711190
return 'config/areas.yaml'
11721191

11731192
def get_loader(self) -> Callable[[str, ], str]:
1174-
return self.server.load_areas
1193+
"""
1194+
Return `self.server.load_file`.
11751195
1176-
def get_areas(self) -> List[Area]:
1177-
return self._areas.copy()
1196+
Returns
1197+
-------
1198+
Callable[[str, ], str]
1199+
`self.server.load_file`.
1200+
"""
1201+
1202+
return self.server.load_areas
11781203

11791204
def get_source_file(self) -> Union[str, None]:
1205+
"""
1206+
Return the source file of the last area list the manager successfully loaded relative to
1207+
the root directory of the server, or None if the latest loaded area list was loaded raw.
1208+
1209+
Returns
1210+
-------
1211+
Union[str, None]
1212+
Source file or None.
1213+
"""
1214+
11801215
return self._source_file
11811216

1217+
def get_custom_folder(self) -> str:
1218+
"""
1219+
Return `'config/area_lists'`.
1220+
1221+
Returns
1222+
-------
1223+
str
1224+
`'config/area_lists'`.
1225+
"""
1226+
1227+
return 'config/area_lists'
1228+
1229+
def get_areas(self) -> List[Area]:
1230+
"""
1231+
Return a copy of the areas managed by this manager.
1232+
1233+
Returns
1234+
-------
1235+
List[Area]
1236+
Areas managed.
1237+
"""
1238+
1239+
return self._areas.copy()
1240+
11821241
def load_areas(self, area_list_file: str = 'config/areas.yaml') -> List[Area]:
1242+
Constants.warn_deprecated('area_manager.load_areas',
1243+
'area_manager.load_file',
1244+
'4.4')
1245+
return self.load_file(area_list_file)
1246+
1247+
def load_file(self, source_file: str) -> List:
11831248
"""
1184-
Load an area list.
1249+
Load an area list from a file.
11851250
11861251
Parameters
11871252
----------
1188-
area_list_file: str, optional
1189-
Location of the area list to load. Defaults to 'config/areas.yaml'.
1253+
source_file: str
1254+
Location of the area list to load.
11901255
11911256
Returns
11921257
-------
@@ -1202,19 +1267,44 @@ def load_areas(self, area_list_file: str = 'config/areas.yaml') -> List[Area]:
12021267
ServerError.YAMLInvalidError
12031268
If the file was empty, had a YAML syntax error, or could not be decoded using UTF-8.
12041269
ServerError.FileSyntaxError
1205-
If the file failed verification for its asset type.
1270+
If the file failed verification for areas.
12061271
"""
12071272

1208-
areas = ValidateAreas().validate(area_list_file, extra_parameters={
1273+
areas = ValidateAreas().validate(source_file, extra_parameters={
12091274
'server_character_list': self.server.character_manager.get_characters(),
12101275
'server_default_area_description': self.server.config['default_area_description']
12111276
})
1212-
areas = self._load_areas(areas, area_list_file)
1277+
areas = self._load_areas(areas, source_file)
12131278
self._check_structure()
12141279

12151280
return areas
12161281

1217-
def load_areas_raw(self, yaml_contents: Dict) -> List[Area]:
1282+
def load_raw(self, yaml_contents: Dict) -> List[Area]:
1283+
"""
1284+
Load an area list from a YAML representation.
1285+
1286+
Parameters
1287+
----------
1288+
yaml_contents: Dict
1289+
YAML representation.
1290+
1291+
Returns
1292+
-------
1293+
List[AreaManager.Area]
1294+
Areas.
1295+
1296+
Raises
1297+
------
1298+
ServerError.FileNotFoundError
1299+
If the file was not found.
1300+
ServerError.FileOSError
1301+
If there was an operating system error when opening the file.
1302+
ServerError.YAMLInvalidError
1303+
If the file was empty, had a YAML syntax error, or could not be decoded using UTF-8.
1304+
ServerError.FileSyntaxError
1305+
If the file failed verification for its asset type.
1306+
"""
1307+
12181308
areas = ValidateAreas().validate_contents(yaml_contents, extra_parameters={
12191309
'server_character_list': self.server.character_manager.get_characters(),
12201310
'server_default_area_description': self.server.config['default_area_description']
@@ -1446,5 +1536,16 @@ def change_passage_lock(self, client: ClientManager.Client,
14461536

14471537
return now_reachable
14481538

1449-
def _check_structure(self) -> bool:
1539+
def _check_structure(self):
1540+
"""
1541+
Assert that all invariants specified in the class description are maintained.
1542+
1543+
Raises
1544+
------
1545+
AssertionError
1546+
If any of the invariants are not maintained.
1547+
1548+
"""
1549+
1550+
# 1. At least one area.
14501551
assert self._areas

0 commit comments

Comments
 (0)