File: options.py

package info (click to toggle)
dh-python 7.20251231
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,596 kB
  • sloc: python: 6,487; makefile: 605; perl: 251; sh: 36
file content (235 lines) | stat: -rw-r--r-- 8,028 bytes parent folder | download
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# Copyright © 2010-2013 Piotr Ożarowski <piotr@debian.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import re
from argparse import ArgumentParser, SUPPRESS
from dataclasses import dataclass, field
from os import environ

from dhpython.version import VersionRange


@dataclass
class DHPythonOptions:
    O: list[str] = field(default_factory=list)
    accept_upstream_versions: bool = False
    arch: bool | None = None
    clean_dbg_pkg: bool = True
    compile_all: bool = False
    depends: list[str] = field(default_factory=list)
    depends_section: list[str] = field(default_factory=list)
    guess_deps: bool = True
    ignore_shebangs: bool = False
    no_ext_rename: bool = False
    no_package: list[str] = field(default_factory=list)
    no_shebang_rewrite: bool = False
    package: list[str] = field(default_factory=list)
    private_dir: str | None = None
    recommends: list[str] = field(default_factory=list)
    recommends_section: list[str] = field(default_factory=list)
    regexpr: list[re.Pattern[str]] = field(default_factory=list)
    remaining_packages: bool = False
    requires: list[str] = field(default_factory=list)
    shebang: str | None = None
    skip_private: bool = False
    suggests: list[str] = field(default_factory=list)
    suggests_section: list[str] = field(default_factory=list)
    verbose: bool = environ.get("DH_VERBOSE") == "1"
    vrange: VersionRange | None = None
    write_log: bool = False


def compiled_regex(string: str) -> re.Pattern[str]:
    """argparse regex type"""
    try:
        return re.compile(string)
    except re.error:
        raise ValueError("regular expression is not valid")


def build_parser() -> ArgumentParser:
    parser = ArgumentParser()
    parser.add_argument("--version", action="version", version="%(prog)s DEVELV")
    parser.add_argument(
        "--no-guessing-deps",
        action="store_false",
        dest="guess_deps",
        help="disable guessing dependencies",
    )
    parser.add_argument(
        "--skip-private", action="store_true", help="don't check private directories"
    )
    parser.add_argument(
        "-v",
        "--verbose",
        action="store_true",
        help="turn verbose mode on",
    )
    # arch=False->arch:all only, arch=True->arch:any only, None->all of them
    parser.add_argument(
        "-i",
        "--indep",
        action="store_false",
        dest="arch",
        default=None,
        help="act on architecture independent packages",
    )
    parser.add_argument(
        "-a",
        "-s",
        "--arch",
        action="store_true",
        dest="arch",
        help="act on architecture dependent packages",
    )
    parser.add_argument(
        "-q", "--quiet", action="store_false", dest="verbose", help="be quiet"
    )
    parser.add_argument(
        "-p",
        "--package",
        action="append",
        metavar="PACKAGE",
        help="act on the package named PACKAGE",
    )
    parser.add_argument(
        "-N",
        "--no-package",
        action="append",
        metavar="PACKAGE",
        help="do not act on the specified package",
    )
    parser.add_argument(
        "--remaining-packages",
        action="store_true",
        help="Do not act on the packages which have already been acted on by "
        "this debhelper command earlier",
    )
    parser.add_argument(
        "--compile-all",
        action="store_true",
        help="compile all files from given private directory in postinst, not "
        "just the ones provided by the package",
    )
    parser.add_argument(
        "-V",
        type=VersionRange,
        dest="vrange",
        metavar="[X.Y][-][A.B]",
        help="specify list of supported Python versions. See py3compile(1) for "
        "examples",
    )
    parser.add_argument(
        "-X",
        "--exclude",
        action="append",
        dest="regexpr",
        type=compiled_regex,
        metavar="REGEXPR",
        help="exclude .py files that match given REGEXPR from "
        "byte-compilation, in a private dir. You may use this option "
        "multiple times to build up a list of things to exclude.",
    )
    parser.add_argument(
        "--accept-upstream-versions",
        action="store_true",
        help="accept upstream versions while translating Python dependencies "
        "into Debian ones",
    )
    parser.add_argument(
        "--depends",
        action="append",
        metavar="REQ",
        help="translate given requirements into Debian dependencies and add "
        "them to ${python3:Depends}. Use it for missing items in "
        "requires.txt.",
    )
    parser.add_argument(
        "--depends-section",
        action="append",
        metavar="SECTION",
        help="translate requirements from given section into Debian "
        "dependencies and add them to ${python3:Depends}",
    )
    parser.add_argument(
        "--recommends",
        action="append",
        metavar="REQ",
        help="translate given requirements into Debian dependencies and add "
        "them to ${python3:Recommends}",
    )
    parser.add_argument(
        "--recommends-section",
        action="append",
        metavar="SECTION",
        help="translate requirements from given section into Debian "
        "dependencies and add them to ${python3:Recommends}",
    )
    parser.add_argument(
        "--suggests",
        action="append",
        metavar="REQ",
        help="translate given requirements into Debian dependencies and add "
        "them to ${python3:Suggests}",
    )
    parser.add_argument(
        "--suggests-section",
        action="append",
        metavar="SECTION",
        help="translate requirements from given section into Debian "
        "dependencies and add them to ${python3:Suggests}",
    )
    parser.add_argument(
        "--requires",
        action="append",
        metavar="FILE",
        help="translate requirements from given file into Debian dependencies "
        "and add them to ${python3:Depends}",
    )
    parser.add_argument(
        "--shebang", metavar="COMMAND", help="use given command as shebang in scripts"
    )
    parser.add_argument(
        "--ignore-shebangs",
        action="store_true",
        help="do not translate shebangs into Debian dependencies",
    )
    parser.add_argument(
        "--no-dbg-cleaning",
        action="store_false",
        dest="clean_dbg_pkg",
        help="do not remove files from debug packages",
    )
    parser.add_argument(
        "--no-ext-rename",
        action="store_true",
        help="do not add magic tags nor multiarch tuples to extension file " "names)",
    )
    parser.add_argument(
        "--no-shebang-rewrite", action="store_true", help="do not rewrite shebangs"
    )
    parser.add_argument(
        "private_dir",
        nargs="?",
        help="Private directory containing Python modules (optional)",
    )
    # debhelper options:
    parser.add_argument("-O", action="append", help=SUPPRESS)
    return parser