Skip to content

Commit 6db973f

Browse files
author
Ram Rachum
committed
-
1 parent b0c923a commit 6db973f

File tree

11 files changed

+55
-35
lines changed

11 files changed

+55
-35
lines changed

garlicsim/garlicsim/general_misc/arguments_profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def __getitem__(self, argument_name):
422422

423423
def get(self, argument_name, default=None):
424424
'''Get the value of a specified argument, if missing get `default`.'''
425-
return self._arguments.get(key, argument_name)
425+
return self._arguments.get(argument_name, default)
426426

427427

428428
def keys(self):

garlicsim/garlicsim/general_misc/function_anchoring_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __new__(mcls, name, bases, namespace_dict):
5252

5353
# Since this metaclass is a hacky enough solution as it is, let's
5454
# be careful and ensure no object is already defined by the same
55-
# name in the module level: (blocktodotest)
55+
# name in the module level: (todotest)
5656
try:
5757
already_defined_object = getattr(module_name, function_name)
5858
except AttributeError:

garlicsim/garlicsim/general_misc/import_tools.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,29 @@ def import_if_exists(module_name, silent_fail=False):
118118

119119

120120
def _module_exists_in_some_zip_path(module_name):
121+
'''
122+
Return whether a module by the name `module_name` exists in a zip archive.
123+
124+
Used internally by `exists`.
125+
'''
121126
assert '.' not in module_name
122127

123128
zip_paths = [path for path in sys.path if '.zip' in path]
124129
# todo: Find better way to filter zip paths.
125130

126131
for zip_path in zip_paths:
127132

128-
# Trying to create a zip imported:
133+
# Trying to create a zip importer:
129134
try:
130135
zip_importer = zipimport.zipimporter(zip_path)
131136
except zipimport.ZipImportError:
132137
continue
133138
# Excepted `ZipImportError` because we may have zip paths in
134139
# `sys.path` that don't really exist, which causes `zipimport` to
135-
# raise `ZipImportError`. todo: should find smarter way of catching
136-
# this, excepting `ZipImportError` is not a good idea.
140+
# raise `ZipImportError`.
141+
#
142+
# todo: should find smarter way of catching this, excepting
143+
# `ZipImportError` is not a good idea.
137144

138145
if zip_importer.find_module(module_name) is not None:
139146
return True
@@ -151,7 +158,7 @@ def exists(module_name):
151158
152159
Currently implemented for top-level packages only. (i.e. no dots.)
153160
154-
(Supports modules imported from a zip file.)
161+
Supports modules imported from a zip file.
155162
'''
156163
assert '.' not in module_name
157164
try:

garlicsim/garlicsim/general_misc/misc_tools.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ def is_subclass(candidate, base_class):
1717
You may pass in a tuple of base classes instead of just one, and it will
1818
check whether `candidate` is a subclass of any of these base classes.
1919
20-
tododoc The advantage of this over the built-in `issubclass` is that it doesn't
21-
throw an exception if `candidate` is not a type. (Python issue 10569.)
20+
This has 2 advantages of over the built-in `issubclass`:
21+
22+
1. It doesn't throw an exception if `candidate` is not a type. (Python
23+
issue 10569.)
24+
2. It manually checks for a `__subclasscheck__` method on `base_class`.
25+
This is helpful for Python 2.5 compatibility because Python started
26+
using `__subclasscheck__` in its built-in `issubclass` starting from
27+
Python 2.6.
28+
2229
'''
30+
# todo: disable ability to use nested iterables.
2331
if cute_iter_tools.is_iterable(base_class):
2432
return any(is_subclass(candidate, single_base_class) for
2533
single_base_class in base_class)

garlicsim/garlicsim/general_misc/sequence_tools.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def combinations(sequence, n=None, start=0):
3737
3838
`n` specifies the number of items. (Use `None` for all possible sizes
3939
together.) `start` specifies the index number of the member from which to
40-
start giving combinations. (Keep the default of `0` for doing the whole
41-
sequence.)
40+
start giving combinations. (Keep the default of `start=0` for doing the
41+
whole sequence.)
4242
4343
Example:
4444
@@ -63,7 +63,6 @@ def combinations(sequence, n=None, start=0):
6363
yield [thing] + sub_result
6464

6565

66-
6766
### Not using now, might want in future:
6867

6968
#def is_sequence(thing):

garlicsim/garlicsim/general_misc/sys_tools.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ def __exit__(self, *args, **kwargs):
8484

8585

8686
frozen = getattr(sys, 'frozen', None)
87+
'''
88+
The "frozen string", if we are frozen, otherwise `None`.
89+
90+
This is useful for checking if we are frozen, e.g. with py2exe.
91+
'''
8792

8893

8994
# May want in future:
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2009-2011 Ram Rachum.
22
# This program is distributed under the LGPL2.1 license.
33

4-
'''Package for caching of functions that take states or history browsers.'''
4+
'''Package for caching of functions that take history browsers.'''
5+
# todo: reorganize?
56

67
from .decorators import history_cache

garlicsim/garlicsim/misc/caching/decorators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# This program is distributed under the LGPL2.1 license.
33

44
'''
5-
tododoc perhaps reorganize
6-
Provides decorators to cache state- or history-dependent functions.
5+
This module defines the `history_cache` decorator.
76
8-
`state_cache` is for functions that take a state. `history_cache` is for
9-
functions that take a history browser.
7+
See its documentation for more information.
108
'''
9+
10+
# todo perhaps reorganize
1111
#todo: make sure the cache gets lost on pickling
1212

1313
from __future__ import with_statement

garlicsim/garlicsim/misc/simpack_grokker/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def __init__(self, simpack_grokker):
5252
List of scalar state functions given by the simpack.
5353
5454
A scalar state function is a function from a state to a real number.
55-
These should be decorated by `garlicsim.misc.cached.state_cache`. tododoc
55+
It's recommended to decorate these with
56+
`garlicsim.general_misc.caching.cache`
5657
'''
5758

5859
self.SCALAR_HISTORY_FUNCTIONS = []

garlicsim/garlicsim/scripts/start_simpack.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55
'''
66
Script for starting a new simpack.
77
8+
This is a script for creating a skeleton for a `garlicsim` simpack. Use this
9+
when you want to make a new simpack to have the basic folders and files created
10+
for you.
11+
812
Usage:
9-
start_simpack.py quantum_mechanics
13+
14+
start_simpack.py my_simpack_name
15+
16+
The simpack will be created in the current path, in a directory with the name
17+
of the simpack.
1018
'''
1119

1220
from __future__ import with_statement
@@ -21,18 +29,6 @@
2129
from garlicsim.scripts import simpack_template
2230
simpack_template_package_name = simpack_template.__name__
2331

24-
25-
_help_text = '''\
26-
This is a script for creating a skeleton for a `garlicsim` simpack. Use this
27-
when you want to make a new simpack to have the basic folders and files created
28-
for you.
29-
30-
Usage: start_simpack.py my_simpack_name
31-
32-
The simpack will be created in the current path, in a directory with the name
33-
of the simpack.
34-
'''
35-
3632

3733
def _walk_folder(package_name, folder):
3834
'''
@@ -113,7 +109,6 @@ def start_simpack(containing_folder, name):
113109
string_to_write = source_string\
114110
.replace('\r', '')\
115111
.replace('simpack_name', name)
116-
117112

118113
destination.write(string_to_write)
119114

@@ -141,8 +136,8 @@ def _make_writeable(filename):
141136

142137

143138
def show_help():
144-
'''Print some help text that describes how to use this script'''
145-
print(_help_text)
139+
'''Print some help text that describes how to use this script.'''
140+
print(__doc__)
146141

147142

148143
def start(argv=None):

0 commit comments

Comments
 (0)