Skip to content

Commit 89e0e4a

Browse files
committed
Major api doc cleanup
1 parent 67c2815 commit 89e0e4a

25 files changed

+701
-37
lines changed

demosys/core/finders.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,22 @@ def __init__(self, paths):
1414
self._cache = {}
1515

1616
def find(self, path):
17+
"""
18+
Find a file in the path.
19+
When creating a custom finder, this is the method you override.
20+
21+
:param path: The path to find
22+
:return: The absolute path to the file or None if not found
23+
"""
1724
return self._find(path)
1825

1926
def _find(self, path):
27+
"""
28+
Similar to ``find()``, but it caches each result to speed things.
29+
30+
:param path: The path to find
31+
:return: The absolute path to the file or None if not found
32+
"""
2033
for p in self.paths:
2134
abspath = os.path.join(p, path)
2235
if os.path.exists(abspath):
@@ -28,10 +41,25 @@ def _find(self, path):
2841
return None
2942

3043
def find_cached(self, path):
44+
"""
45+
Check if the path is already cached.
46+
This method should normally not be overridden.
47+
48+
:param path: The path to the file
49+
:return: The absolute path to the file or None
50+
"""
3151
e = self._cache.get(path)
3252
if e.exists:
3353
return e.abspath
3454
return None
3555

3656
def cache(self, path, abspath, exists=True):
57+
"""
58+
Caches an entry.
59+
Should ideally not be overridden.
60+
61+
:param path: The path
62+
:param abspath: The absolute path
63+
:param exists: Did the file exist? (bool)
64+
"""
3765
self._cache[path] = FinderEntry(path=path, abspath=abspath, exists=exists)

demosys/core/management/base.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,53 @@ def __init__(self):
1414
pass
1515

1616
def add_arguments(self, parser):
17+
"""
18+
This method is for adding arguments to a command.
19+
When extending this class we define the arguments
20+
by adding it to the parser passed in.
21+
22+
:param parser: The parser to add arguments to (standard argparse)
23+
"""
1724
pass
1825

1926
def handle(self, *args, **options):
27+
"""
28+
The actual run logic for the command.
29+
30+
:param args: arguments from the argparser
31+
:param options: keyword arguments from the argparser
32+
"""
2033
raise NotImplementedError
2134

2235
def run_from_argv(self, argv):
36+
"""
37+
Called by the system when executing the command from the command line.
38+
This should not be overridden.
39+
40+
:param argv: Arguments from command line
41+
"""
2342
parser = self.create_parser(argv[0], argv[1])
2443
options = parser.parse_args(argv[2:])
2544
cmd_options = vars(options)
2645
args = cmd_options.pop('args', ())
2746
self.handle(*args, **cmd_options)
2847

2948
def print_help(self, prog_name, subcommand):
49+
"""
50+
Prints the help text generated by the argument parser defined for this command.
51+
This method should not be overridden.
52+
53+
:param prog_name: name of the program that started the command.
54+
:param subcommand: The subcommand name
55+
"""
3056
parser = self.create_parser(prog_name, subcommand)
3157
parser.print_help()
3258

3359
def create_parser(self, prog_name, subcommand):
3460
"""
3561
Create argument parser and deal with ``add_arguments``.
62+
This method should not be overriden.
63+
3664
:param prog_name: Name of the command (argv[0])
3765
:return: ArgumentParser
3866
"""
@@ -46,7 +74,12 @@ class CreateCommand(BaseCommand):
4674
"""Used for createproject and createeffect"""
4775

4876
def validate_name(self, name):
49-
"""Can the name be used as a python module or package?"""
77+
"""
78+
Can the name be used as a python module or package?
79+
Raises ``ValueError`` if the name is invalid.
80+
81+
:param name: the name to check
82+
"""
5083
if not name:
5184
raise ValueError("Name cannot be empty")
5285

@@ -55,10 +88,15 @@ def validate_name(self, name):
5588
raise ValueError("{} is not a valid identifier".format(name))
5689

5790
def try_import(self, name):
58-
"""Attemt to import the name"""
91+
"""
92+
Attempt to import the name.
93+
Raises ``ImportError`` if the name cannot be imported.
94+
95+
:param name: the name to import
96+
"""
5997
try:
6098
import_module(name)
6199
except ImportError:
62100
pass
63101
else:
64-
raise ValueError("{} conflicts with an existing python module".format(name))
102+
raise ImportError("{} conflicts with an existing python module".format(name))

demosys/core/shaderfiles/finders.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ def __init__(self):
1818
)
1919
super().__init__(settings.SHADER_DIRS)
2020

21-
# TODO: Use values from settings to filter shader files
22-
# def find(self, path):
23-
# pass
24-
2521

2622
class EffectDirectoriesFinder(finders.FileSystemFinder):
2723
"""Finds shaders in the registered effects"""
@@ -42,6 +38,14 @@ def get_finders():
4238

4339
@functools.lru_cache(maxsize=None)
4440
def get_finder(import_path):
41+
"""
42+
Get a finder class from an import path.
43+
Raises ``demosys.core.exceptions.ImproperlyConfigured`` if the finder is not found.
44+
This function uses an lru cache.
45+
46+
:param import_path: string representing an import path
47+
:return: An instance of the finder
48+
"""
4549
Finder = import_string(import_path)
4650
if not issubclass(Finder, finders.FileSystemFinder):
4751
raise ImproperlyConfigured('Finder {} is not a subclass of core.finders.FileSystemFinder'.format(import_path))

demosys/core/texturefiles/finders.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ def get_finders():
4242

4343
@functools.lru_cache(maxsize=None)
4444
def get_finder(import_path):
45+
"""
46+
Get a finder class from an import path.
47+
Raises ``demosys.core.exceptions.ImproperlyConfigured`` if the finder is not found.
48+
This function uses an lru cache.
49+
50+
:param import_path: string representing an import path
51+
:return: An instance of the finder
52+
"""
4553
Finder = import_string(import_path)
4654
if not issubclass(Finder, finders.FileSystemFinder):
4755
raise ImproperlyConfigured('Finder {} is not a subclass of core.finders.FileSystemFinder'.format(import_path))

demosys/effects/default/effect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class DefaultEffect(effect.Effect):
8-
"""Generated default efffect"""
8+
"""Generated default effect"""
99
def __init__(self):
1010
self.shader = self.get_shader("default/default.glsl")
1111
self.cube = geometry.cube(4.0, 4.0, 4.0)

demosys/effects/managers.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,52 @@ class ManagerError(Exception):
66

77

88
class BaseEffectManger:
9-
"""Base effect manager"""
9+
"""
10+
Base effect manager.
11+
A manager is responsible for figuring out what effect should be drawn
12+
at any given time.
13+
"""
1014
def pre_load(self):
11-
"""Init after context creations"""
15+
"""
16+
Called after OpenGL context creation before resources are loaded.
17+
This method should be overridden.
18+
"""
1219
return True
1320

1421
def post_load(self):
22+
"""
23+
Called after resources are loaded.
24+
This method should be overridden.
25+
"""
1526
return True
1627

1728
def draw(self, time, frametime, target):
18-
"""Draw efffect(s)"""
29+
"""
30+
Called by the system every frame.
31+
This method should be overridden.
32+
33+
:param time: The current time in seconds
34+
:param frametime: The time one frame should take in seconds
35+
:param target: The target FBO
36+
"""
1937
pass
2038

2139

2240
class SingleEffectManager(BaseEffectManger):
2341
"""Run a single effect"""
2442
def __init__(self, effect_module=None):
43+
"""
44+
Initalize the manager telling it what effect should run.
45+
46+
:param effect_module: The effect module to run
47+
"""
2548
self.active_effect = None
2649
self.effect_module = effect_module
2750

2851
def pre_load(self):
29-
"""Init after context creations"""
52+
"""
53+
Initialize the effect that should run.
54+
"""
3055
effect_list = [cfg.cls() for name, cfg in effects.effects.items()]
3156
for effect in effect_list:
3257
if effect.name == self.effect_module:

demosys/effects/registry.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,18 @@ def __init__(self):
2828
self.effects = {}
2929

3030
def get_dirs(self):
31-
"""Get all effect directories"""
31+
"""
32+
Get all effect directories for registered effects.
33+
"""
3234
for k, v in self.effects.items():
3335
yield v.path
3436

3537
def polulate(self, effect_list):
36-
"""Find all effects"""
38+
"""
39+
Find all effect modules.
40+
41+
:param effect_list: List of effect module paths
42+
"""
3743
for effect in effect_list:
3844
name = '{}.{}'.format(effect, EFFECT_MODULE)
3945
module, cls = self.get_effect_cls(name)
@@ -44,7 +50,9 @@ def polulate(self, effect_list):
4450
raise EffectError("Effect '{}' has no effect class".format(effect))
4551

4652
def get_effect_cls(self, module_name):
47-
"""Find and return an effect class in a module
53+
"""
54+
Find and return an effect class in a module
55+
4856
:param module_name: Name of the module
4957
:returns: module, cls tuple
5058
"""

0 commit comments

Comments
 (0)