File: 0004-Compatibility-with-argparse-manpage.patch

package info (click to toggle)
cmake-format 0.6.13-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,436 kB
  • sloc: python: 16,990; makefile: 14
file content (166 lines) | stat: -rw-r--r-- 5,366 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
From: Ian Campbell <ijc@debian.org>
Date: Fri, 1 May 2020 13:38:13 +0800
Subject: Compatibility with `argparse-manpage`

* Refactor construction of `argparse.ArgumentParser` into a `get_argparser()`
  function in each binary.
* Set `prog` property (the default uses `sys.arg[0]` which breaks with
  `argparse-manpage`, arguably this is an `argparse-manpage` bug).
* Set the `man_short_description` property based on the first line of the
  description. This is used as a summary in the `NAME` section of the man page.

Forwarded: https://github.com/cheshirekow/cmake_format/pull/305
---
 cmakelang/annotate.py        | 19 ++++++++++++++-----
 cmakelang/format/__main__.py | 13 ++++++++++---
 cmakelang/genparsers.py      | 23 +++++++++++++++--------
 cmakelang/lint/__main__.py   | 19 +++++++++++++------
 4 files changed, 52 insertions(+), 22 deletions(-)

diff --git a/cmakelang/annotate.py b/cmakelang/annotate.py
index c8f387f..0019e39 100644
--- a/cmakelang/annotate.py
+++ b/cmakelang/annotate.py
@@ -107,17 +107,26 @@ def setup_argparser(arg_parser):
   arg_parser.add_argument('infilepaths', nargs='*')
 
 
+def get_argparser():
+  argparser = argparse.ArgumentParser(
+      prog='cmake-annotate',
+      description=__doc__,
+      formatter_class=argparse.RawDescriptionHelpFormatter,
+      usage=USAGE_STRING)
+
+  setattr(argparser, 'man_short_description', __doc__.strip().splitlines()[0])
+
+  setup_argparser(argparser)
+  return argparser
+
+
 def main():
   """Parse arguments, open files, start work."""
 
   # set up main logger, which logs everything. We'll leave this one logging
   # to the console
   logging.basicConfig(level=logging.INFO)
-  arg_parser = argparse.ArgumentParser(
-      description=__doc__,
-      formatter_class=argparse.RawDescriptionHelpFormatter,
-      usage=USAGE_STRING)
-  setup_argparser(arg_parser)
+  arg_parser = get_argparser()
   args = arg_parser.parse_args()
 
   assert (len(args.infilepaths) == 1
diff --git a/cmakelang/format/__main__.py b/cmakelang/format/__main__.py
index bbcbf98..da0b9e6 100644
--- a/cmakelang/format/__main__.py
+++ b/cmakelang/format/__main__.py
@@ -566,15 +566,22 @@ def onefile_main(infile_path, args, argparse_dict):
     shutil.move(tempfile_path, infile_path)
 
 
-def inner_main():
-  """Parse arguments, open files, start work."""
-
+def get_argparser():
   arg_parser = argparse.ArgumentParser(
+      prog='cmake-format',
       description=__doc__,
       formatter_class=argparse.RawDescriptionHelpFormatter,
       usage=USAGE_STRING)
 
+  setattr(arg_parser, 'man_short_description', __doc__.strip().splitlines()[0])
+
   setup_argparser(arg_parser)
+  return arg_parser
+
+def inner_main():
+  """Parse arguments, open files, start work."""
+
+  arg_parser = get_argparser()
   try:
     import argcomplete
     argcomplete.autocomplete(arg_parser)
diff --git a/cmakelang/genparsers.py b/cmakelang/genparsers.py
index 410f541..adaf313 100644
--- a/cmakelang/genparsers.py
+++ b/cmakelang/genparsers.py
@@ -1,7 +1,6 @@
 # -*- coding: utf-8 -*-
 """
-Parse cmake listfiles, find function and macro declarations, and generate
-parsers for them.
+Parse cmake listfiles, find function and macro declarations, and generate parsers for them.
 """
 from __future__ import print_function, unicode_literals
 
@@ -214,6 +213,19 @@ def setup_argparse(argparser):
   argparser.add_argument('infilepaths', nargs='*')
 
 
+def get_argparser():
+  argparser = argparse.ArgumentParser(
+      prog='cmake-genparsers',
+      description=__doc__,
+      formatter_class=argparse.RawDescriptionHelpFormatter,
+      usage=USAGE_STRING)
+
+  setattr(argparser, 'man_short_description', __doc__.strip().splitlines()[0])
+
+  setup_argparse(argparser)
+  return argparser
+
+
 USAGE_STRING = """
 cmake-genparsers [-h] [-o OUTFILE_PATH] infilepath [infilepath ...]
 """
@@ -223,12 +235,7 @@ def main():
   """Parse arguments, open files, start work."""
   logging.basicConfig(level=logging.INFO, format="%(levelname)s %(message)s")
 
-  argparser = argparse.ArgumentParser(
-      description=__doc__,
-      formatter_class=argparse.RawDescriptionHelpFormatter,
-      usage=USAGE_STRING)
-
-  setup_argparse(argparser)
+  argparser = get_argparser()
   args = argparser.parse_args()
   logging.getLogger().setLevel(getattr(logging, args.log_level.upper()))
 
diff --git a/cmakelang/lint/__main__.py b/cmakelang/lint/__main__.py
index a172290..0c8e883 100644
--- a/cmakelang/lint/__main__.py
+++ b/cmakelang/lint/__main__.py
@@ -94,16 +94,23 @@ cmake-lint [-h]
 """
 
 
-def inner_main():
-  """Parse arguments, open files, start work."""
-  logging.basicConfig(level=logging.INFO, format="%(levelname)s %(message)s")
-
-  argparser = argparse.ArgumentParser(
+def get_argparser():
+  arg_parser = argparse.ArgumentParser(
+      prog='cmake-lint',
       description=__doc__,
       formatter_class=argparse.RawDescriptionHelpFormatter,
       usage=USAGE_STRING)
 
-  setup_argparse(argparser)
+  setattr(arg_parser, 'man_short_description', __doc__.strip().splitlines()[0])
+
+  setup_argparse(arg_parser)
+  return arg_parser
+
+def inner_main():
+  """Parse arguments, open files, start work."""
+  logging.basicConfig(level=logging.INFO, format="%(levelname)s %(message)s")
+
+  argparser = get_argparser()
   try:
     import argcomplete
     argcomplete.autocomplete(argparser)