Coverage for docs/source/examples/docstringparsing.py: 100%
10 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-28 12:37 -0400
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-28 12:37 -0400
1"Docstring parsing example"
2from gpkit import Model, parse_variables
3from gpkit.tools.docstring import parse_varstring
6class Cube(Model):
7 """Demonstration of nomenclature syntax
9 Lines that end in "Variables" will be parsed as a scalar variable table
10 until the next blank line.
12 Variables
13 ---------
14 A [m^2] surface area
15 V 100 [L] minimum volume
17 Lines that end in "Variables of length $N" will be parsed as vector
18 variables of length $N until the next blank line.
20 Variables of length 3
21 ---------------------
22 s [m] side length
24 Let's introduce more variables: (any line ending in "Variables" is parsed)
26 Zoning Variables
27 ----------------
28 h 1 [m] minimum height
30 Upper Unbounded
31 ---------------
32 A
34 The ordering of these blocks doesn't affect anything; order them in the
35 way that makes the most sense to someone else reading your model.
36 """
37 @parse_variables(__doc__, globals())
38 def setup(self):
40 return [A >= 2*(s[0]*s[1] + s[1]*s[2] + s[2]*s[0]),
41 s.prod() >= V,
42 s[2] >= h]
45print(parse_varstring(Cube.__doc__))
46c = Cube()
47c.cost = c.A
48print(c.solve(verbosity=0).table())