fparser Reference Guide  0.0.14
script_options.py
1 # Modified work Copyright (c) 2017-2019 Science and Technology
2 # Facilities Council
3 # Original work Copyright (c) 1999-2008 Pearu Peterson
4 
5 # All rights reserved.
6 
7 # Modifications made as part of the fparser project are distributed
8 # under the following license:
9 
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions are
12 # met:
13 
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 
17 # 2. Redistributions in binary form must reproduce the above copyright
18 # notice, this list of conditions and the following disclaimer in the
19 # documentation and/or other materials provided with the distribution.
20 
21 # 3. Neither the name of the copyright holder nor the names of its
22 # contributors may be used to endorse or promote products derived from
23 # this software without specific prior written permission.
24 
25 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 
37 # --------------------------------------------------------------------
38 
39 # The original software (in the f2py project) was distributed under
40 # the following license:
41 
42 # Redistribution and use in source and binary forms, with or without
43 # modification, are permitted provided that the following conditions are met:
44 
45 # a. Redistributions of source code must retain the above copyright notice,
46 # this list of conditions and the following disclaimer.
47 # b. Redistributions in binary form must reproduce the above copyright
48 # notice, this list of conditions and the following disclaimer in the
49 # documentation and/or other materials provided with the distribution.
50 # c. Neither the name of the F2PY project nor the names of its
51 # contributors may be used to endorse or promote products derived from
52 # this software without specific prior written permission.
53 
54 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
55 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
58 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
60 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
61 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
64 # DAMAGE.
65 
66 __all__ = ["set_read_options", "set_parse_options", "get_fortran_code_group"]
67 from optparse import OptionGroup, NO_DEFAULT
68 
69 
70 def set_read_options(parser):
71  parser.set_usage(
72  """\
73 %prog [options] <Fortran files>
74 
75 Description:
76  %prog reads Fortran codes."""
77  )
78  parser.add_option(
79  "--task",
80  default="show",
81  choices=["show"],
82  help="Specify reading task. Default: %default.",
83  )
84  parser.add_option_group(get_fortran_code_group(parser))
85 
86 
87 def set_parse_options(parser):
88  parser.set_usage(
89  """\
90 %prog [options] <Fortran files>
91 
92 Description:
93  %prog parses Fortran codes."""
94  )
95  parser.add_option(
96  "--task",
97  default="show",
98  choices=["show", "none"],
99  help="Specify parsing result task. Default: %default.",
100  )
101  parser.add_option_group(get_fortran_code_group(parser))
102 
103 
104 def set_fparser_options(parser):
105  """Command line options used by the fparser2 script.
106 
107  :param parser: The OptionParser object.
108  :type parser: :py:class:`optparse.OptionParser`
109 
110  """
111 
112  parser.set_usage(
113  """\
114 %prog [options] <Fortran files>
115 
116 Description:
117  %prog parses Fortran code."""
118  )
119  parser.add_option(
120  "--task",
121  default="show",
122  choices=["show", "repr", "none"],
123  help="Specify parsing result task. Default: %default.",
124  )
125  parser.add_option(
126  "--std",
127  default="f2003",
128  choices=["f2003", "f2008"],
129  help="Specify the Fortran standard to use. Default: %default.",
130  )
131 
132 
133 def get_fortran_code_group(parser):
134  group = OptionGroup(
135  parser,
136  "Fortran code options",
137  description="Specify information about Fortran codes.",
138  )
139  group.add_option(
140  "--mode",
141  default="auto",
142  choices=["auto", "free", "fix", "f77", "pyf"],
143  help="Specify Fortran code mode. Default: %default.",
144  )
145  return group