Skip to content

Commit dccce4f

Browse files
committed
Add docs and fix style
Move comment onto multiple lines to shorten to line length Add docstring to modloader.rreload Use ``isinstance`` instead of ``type`` in modloader.rreload Add extra newlines to modloader.modast to conform with PEP8 Fix typo in docstring in modloader.modast Remove redundant imports in modloader.modclass Add docstring to modloader.modconfig.remove_mod Add docstring to modloader.modinfo.reset_mods Change methods in core to staticmethods Remove redundant imports in core Remove redundant variables in core Add extra newlines to core to conform with PEP8 Add docstrings to core Add extra newlines to testing.test to conform with PEP8
1 parent e690410 commit dccce4f

File tree

7 files changed

+55
-22
lines changed

7 files changed

+55
-22
lines changed

modloader/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ def get_mod_path():
1919
return os.path.join(renpy.config.gamedir, "mods")
2020

2121

22-
# Credit to Matthew for this code: https://stackoverflow.com/a/17194836/3398583, modified by muddyfish
22+
# Credit to Matthew for this code: https://stackoverflow.com/a/17194836/3398583
23+
# Modified by muddyfish
2324
def rreload(module, modules=None):
24-
"""Recursively reload modules."""
25+
"""Recursively reloads a module.
26+
27+
Ignores modules in ``modules`` and all modules not in the mods folder
28+
29+
30+
"""
2531
print "RELOADING", module.__file__
2632
sys.stdout.flush()
2733
reload(module)
@@ -31,7 +37,7 @@ def rreload(module, modules=None):
3137
modules.append(module)
3238
for attribute_name in dir(module):
3339
attribute = getattr(module, attribute_name)
34-
if type(attribute) is ModuleType:
40+
if isinstance(attribute, ModuleType):
3541
if attribute not in modules:
3642
if get_mod_path() in attribute.__file__:
3743
rreload(attribute, modules)

modloader/modast.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def find_label(label):
4646
"""
4747
return renpy.game.script.lookup(label)
4848

49+
4950
def search_for_node_type(node, type_, max_depth=200):
5051
"""Search for a specific type of node
5152
@@ -210,6 +211,7 @@ def find_python_statement(statement):
210211
"NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm",
211212
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz")
212213

214+
213215
class ASTHook(ast.Node):
214216
"""A custom :class:`renpy.ast.Node` that acts as a hook between
215217
other node objects.
@@ -413,6 +415,7 @@ def call_hook(node, dest_node, func=None):
413415
hook = hook_opcode(node, None)
414416

415417
def call_function(hook):
418+
# pylint: disable=missing-docstring
416419
if func:
417420
func(hook)
418421

@@ -425,7 +428,7 @@ def call_function(hook):
425428

426429

427430
def unhook_label(label):
428-
"""Unhook a hook from a lbel
431+
"""Unhook a hook from a label
429432
430433
Args:
431434
label (str): The label's name

modloader/modclass.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""This file is free software under the GPLv3 license"""
2-
import sys
32
from modloader import modinfo
43

54

modloader/modconfig.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88

99
def remove_mod(mod_name):
10+
"""Remove a mod from the game and reload.
11+
12+
Args:
13+
mod_name (str): The internal name of the mod to be removed
14+
"""
1015
mod_class = get_mods()[mod_name]
1116
mod_folder = mod_class.__module__
1217
shutil.rmtree(os.path.join(renpy.config.gamedir, "mods", mod_folder))

modloader/modinfo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ def get_mods():
1515

1616

1717
def reset_mods():
18+
"""Remove all mods from the registry"""
1819
modlist.clear()

mods/core/__init__.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
"""This file is free software under the GPLv3 license"""
2-
import renpy
32
import renpy.parser as parser
43
import renpy.ast as ast
54

65
from modloader import modinfo, modast
7-
from modloader.modgame import sprnt
86
from modloader.modgame import base as ml
97
from modloader.modclass import Mod, loadable_mod
108

9+
1110
@loadable_mod
1211
class AWSWMod(Mod):
13-
"""The core mod
12+
"""The core mod.
1413
1514
This mod is responsible for being a proxy between renpy code and modlib
1615
"""
17-
def mod_info(self):
16+
17+
@staticmethod
18+
def mod_info():
19+
"""Get the mod info
20+
Returns: a three element tuple containing the mod name, version and description
21+
"""
1822
return ("Core", "v0.1", "")
1923

20-
def mod_load(self):
24+
@staticmethod
25+
def mod_load():
26+
"""Run various housekeeping tasks for ease of modding.
27+
Disables the screen cache.
28+
Adds the MODS button to the main menu.
29+
"""
2130
# This is called due to renpy's screen cache. Any modifications to screens with an
2231
# enabled cache will fail!
2332
modast.disable_slast_cache()
@@ -35,25 +44,23 @@ def mod_load(self):
3544
modast.call_hook(stmt, modast.find_label("_core_updateChapter"))
3645

3746
# How to abuse the ren'py parser for your own personal gain!
38-
target_display = None
39-
4047
tocompile = """
4148
screen dummy:
4249
imagebutton auto "ui/mods_%s.png" action [Show("preferencesbg"), Show('modmenu'), Play("audio", "se/sounds/open.wav")] hovered Play("audio", "se/sounds/select.ogg") xalign 0.03 yalign 0.955
4350
"""
51+
4452
compiled = parser.parse("FNDummy", tocompile)
4553
target_display = None
4654
for node in compiled:
47-
#sprnt(type(e).__name__)
4855
if isinstance(node, ast.Init):
4956
for child in node.block[0].screen.children:
5057
target_display = child
5158

5259
modast.get_slscreen('main_menu').children.append(target_display)
5360

54-
55-
def mod_complete(self):
56-
# Insert an NSFW warning if any mods register as NSFW
61+
@staticmethod
62+
def mod_complete():
63+
"""Insert a NSFW warning if any mods register as NSFW"""
5764

5865
for mod_name, mod in modinfo.get_mods().iteritems():
5966
mod_info = mod.mod_info()

testing/test.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,30 @@
55

66
from modloader import modast
77

8+
89
def test_get_screen():
910
result = modast.get_screen("screen_test_get_screen")
1011
return result is not None and isinstance(result,
1112
renpy.display.screen.Screen)
1213

14+
1315
def test_get_slscreen():
1416
result = modast.get_slscreen("screen_test_get_screen")
1517
return result is not None and isinstance(result,
1618
renpy.sl2.slast.SLScreen)
1719

20+
1821
def test_find_label():
1922
result = modast.find_label("label_test_find_label")
2023
return result is not None and isinstance(result, renpy.ast.Label)
2124

25+
2226
def test_search_for_node_type():
2327
result = modast.search_for_node_type(
2428
modast.find_label("label_test_find_label"), renpy.ast.Menu)
2529
return result is not None and isinstance(result, renpy.ast.Menu)
2630

31+
2732
def test_search_for_node_with_criteria():
2833
def bryce_say(node):
2934
return isinstance(node, renpy.ast.Say) and node.who == "Br"
@@ -32,49 +37,56 @@ def bryce_say(node):
3237
modast.find_label("label_test_find_label"), bryce_say)
3338
return result is not None and isinstance(result, renpy.ast.Say)
3439

40+
3541
def test_remove_slif():
3642
sl = modast.get_slscreen("screen_test_get_screen")
3743
result = modast.remove_slif(sl, "persistent.test")
3844
return result and len(sl.children[0].entries[0][1].children) == 0
3945

46+
4047
def test_find_menu_single():
4148
result = modast.find_menu("Yes you are!")
4249
return result is not None and isinstance(result, list)
4350

51+
4452
def test_find_menu_multi():
4553
result = modast.find_menu(["Yes you are!", "Of course!"])
4654
return result is not None and isinstance(result, list)
4755

56+
4857
def test_find_say():
4958
result = modast.find_say("This should not be displayed")
5059
return result is not None and isinstance(result, renpy.ast.Say) \
5160
and result.who == "c"
5261

62+
5363
def test_add_menu_option():
5464
menu = modast.find_menu("Yes you are!")[0]
5565
modast.add_menu_option(menu, "No you aren't",
5666
modast.find_label("label_extra"))
5767
return len(menu.items) == 3
5868

69+
5970
def test_find_in_source_code():
6071
# TODO: Fix this, it fails
6172
result = modast.find_in_source_code(16, "test.rpy")
6273
return result is not None and isinstance(result, renpy.ast.Label)
6374

75+
6476
def test_find_python_statement():
6577
result = modast.find_python_statement("this_is_a_very_unique = \"variable\"")
6678
return result is not None
6779

80+
6881
def test_tests():
6982
list_of_tests = [test_get_screen, test_get_slscreen,
70-
test_find_label, test_search_for_node_type,
71-
test_search_for_node_with_criteria, test_remove_slif,
72-
test_find_menu_single, test_find_menu_multi,
73-
test_find_say, test_add_menu_option,
74-
test_find_in_source_code, test_find_python_statement]
83+
test_find_label, test_search_for_node_type,
84+
test_search_for_node_with_criteria, test_remove_slif,
85+
test_find_menu_single, test_find_menu_multi,
86+
test_find_say, test_add_menu_option,
87+
test_find_in_source_code, test_find_python_statement]
7588

7689
for test in list_of_tests:
77-
success = False
7890
try:
7991
success = test()
8092
except Exception, e:

0 commit comments

Comments
 (0)