File: api_milc.md

package info (click to toggle)
python-milc 1.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 788 kB
  • sloc: python: 1,868; sh: 55; makefile: 3
file content (464 lines) | stat: -rw-r--r-- 9,791 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<a id="milc"></a>

# milc

<a id="milc.MILC"></a>

## MILC Objects

```python
class MILC(object)
```

MILC - An Opinionated Batteries Included Framework

<a id="milc.MILC.__init__"></a>

#### \_\_init\_\_

```python
def __init__(name: Optional[str] = None,
             author: Optional[str] = None,
             version: Optional[str] = None,
             logger: Optional[logging.Logger] = None) -> None
```

Initialize the MILC object.

<a id="milc.MILC.argv_name"></a>

#### argv\_name

```python
def argv_name() -> str
```

Returns the name of our program by examining argv.

<a id="milc.MILC.echo"></a>

#### echo

```python
def echo(text: str, *args: Any, **kwargs: Any) -> None
```

Print colorized text to stdout.

ANSI color strings (such as {fg_blue}) will be converted into ANSI
escape sequences, and the ANSI reset sequence will be added to all
strings.

If *args or **kwargs are passed they will be used to %-format the strings.

<a id="milc.MILC.run"></a>

#### run

```python
def run(command: Sequence[str],
        capture_output: bool = True,
        combined_output: bool = False,
        text: bool = True,
        **kwargs: Any) -> Any
```

Run a command using `subprocess.run`, but using some different defaults.

Unlike subprocess.run you must supply a sequence of arguments. You can use `shlex.split()` to build this from a string.

The **kwargs arguments get passed directly to `subprocess.run`.

**Arguments**:

  command
  A sequence where the first item is the command to run, and any remaining items are arguments to pass.
  
  capture_output
  Set to False to have output written to the terminal instead of being available in the returned `subprocess.CompletedProcess` instance.
  
  combined_output
  When true STDERR will be written to STDOUT. Equivalent to the shell construct `2>&1`.
  
  text
  Set to False to disable encoding and get `bytes()` from `.stdout` and `.stderr`.

<a id="milc.MILC.initialize_argparse"></a>

#### initialize\_argparse

```python
def initialize_argparse() -> None
```

Prepare to process arguments from sys.argv.

<a id="milc.MILC.print_help"></a>

#### print\_help

```python
def print_help(*args: Any, **kwargs: Any) -> None
```

Print a help message for the main program or subcommand, depending on context.

<a id="milc.MILC.print_usage"></a>

#### print\_usage

```python
def print_usage(*args: Any, **kwargs: Any) -> None
```

Print brief description of how the main program or subcommand is invoked, depending on context.

<a id="milc.MILC.log_deprecated_warning"></a>

#### log\_deprecated\_warning

```python
def log_deprecated_warning(item_type: str, name: str, reason: str) -> None
```

Logs a warning with a custom message if a argument or command is deprecated.

<a id="milc.MILC.add_argument"></a>

#### add\_argument

```python
def add_argument(*args: Any, **kwargs: Any) -> None
```

Wrapper to add arguments and track whether they were passed on the command line.

<a id="milc.MILC.initialize_logging"></a>

#### initialize\_logging

```python
def initialize_logging(logger: Optional[logging.Logger]) -> None
```

Prepare the defaults for the logging infrastructure.

<a id="milc.MILC.initialize_arguments"></a>

#### initialize\_arguments

```python
def initialize_arguments() -> None
```

Setup and add default arguments.

<a id="milc.MILC.acquire_lock"></a>

#### acquire\_lock

```python
def acquire_lock(blocking: bool = True) -> bool
```

Acquire the MILC lock for exclusive access to properties.

<a id="milc.MILC.release_lock"></a>

#### release\_lock

```python
def release_lock() -> None
```

Release the MILC lock.

<a id="milc.MILC.find_config_file"></a>

#### find\_config\_file

```python
@lru_cache(maxsize=None)
def find_config_file() -> Path
```

Locate the config file.

<a id="milc.MILC.argument"></a>

#### argument

```python
def argument(*args: Any, **kwargs: Any) -> Callable[..., Any]
```

Decorator to call self.add_argument or self.<subcommand>.add_argument.

<a id="milc.MILC.parse_args"></a>

#### parse\_args

```python
def parse_args() -> None
```

Parse the CLI args.

<a id="milc.MILC.read_config_file"></a>

#### read\_config\_file

```python
def read_config_file() -> Tuple[Configuration, Configuration]
```

Read in the configuration file and return Configuration objects for it and the config_source.

<a id="milc.MILC.initialize_config"></a>

#### initialize\_config

```python
def initialize_config() -> None
```

Read in the configuration file and store it in self.config.

<a id="milc.MILC.merge_args_into_config"></a>

#### merge\_args\_into\_config

```python
def merge_args_into_config() -> None
```

Merge CLI arguments into self.config to create the runtime configuration.

<a id="milc.MILC.write_config_option"></a>

#### write\_config\_option

```python
def write_config_option(section: str, option: Any) -> None
```

Save a single config option to the config file.

<a id="milc.MILC.save_config"></a>

#### save\_config

```python
def save_config() -> None
```

Save the current configuration to the config file.

<a id="milc.MILC.__call__"></a>

#### \_\_call\_\_

```python
def __call__() -> Any
```

Execute the entrypoint function.

<a id="milc.MILC.entrypoint"></a>

#### entrypoint

```python
def entrypoint(description: str,
               deprecated: Optional[str] = None) -> Callable[..., Any]
```

Decorator that marks the entrypoint used when a subcommand is not supplied.

**Arguments**:

  description
  A one-line description to display in --help
  
  deprecated
  Deprecation message. When set the subcommand will marked as deprecated and this message will be displayed in the help output.

<a id="milc.MILC.add_subcommand"></a>

#### add\_subcommand

```python
def add_subcommand(handler: Callable[..., Any],
                   description: str,
                   hidden: bool = False,
                   deprecated: Optional[str] = None,
                   **kwargs: Any) -> Callable[..., Any]
```

Register a subcommand.

**Arguments**:

  
  handler
  The function to exececute for this subcommand.
  
  description
  A one-line description to display in --help
  
  hidden
  When True don't display this command in --help
  
  deprecated
  Deprecation message. When set the subcommand will be marked as deprecated
  and this message will be displayed in help output.

<a id="milc.MILC.subcommand"></a>

#### subcommand

```python
def subcommand(description: str,
               hidden: bool = False,
               **kwargs: Any) -> Callable[..., Any]
```

Decorator to register a subcommand.

**Arguments**:

  
  description
  A one-line description to display in --help
  
  hidden
  When True don't display this command in --help

<a id="milc.MILC.setup_logging"></a>

#### setup\_logging

```python
def setup_logging() -> None
```

Called by __enter__() to setup the logging configuration.

<a id="milc.MILC.is_spinner"></a>

#### is\_spinner

```python
def is_spinner(name: str) -> bool
```

Returns true if name is a valid spinner.

<a id="milc.MILC.add_spinner"></a>

#### add\_spinner

```python
def add_spinner(name: str, spinner: Dict[str, Union[int,
                                                    Sequence[str]]]) -> None
```

Adds a new spinner to the list of spinners.

A spinner is a dictionary with two keys:

    interval
        An integer that sets how long (in ms) to wait between frames.

    frames
        A list of frames for this spinner

<a id="milc.MILC.spinner"></a>

#### spinner

```python
def spinner(text: str,
            *args: Any,
            spinner: Optional[str] = None,
            animation: str = 'ellipsed',
            placement: str = 'left',
            color: str = 'blue',
            interval: int = -1,
            stream: Any = sys.stdout,
            enabled: bool = True,
            **kwargs: Any) -> Halo
```

Create a spinner object for showing activity to the user.

This uses halo <https://github.com/ManrajGrover/halo> behind the scenes, most of the arguments map to Halo objects 1:1.

There are 3 basic ways to use this:

* Instantiating a spinner and then using `.start()` and `.stop()` on your object.
* Using a context manager (`with cli.spinner(...):`)
* Decorate a function (`@cli.spinner(...)`)

#### Instantiating a spinner

```python
spinner = cli.spinner(text='Loading', spinner='dots')
spinner.start()

# Do something here

spinner.stop()
```

#### Using a context manager

```python
with cli.spinner(text='Loading', spinner='dots'):
    # Do something here
```

#### Decorate a function

```python
@cli.spinner(text='Loading', spinner='dots')
def long_running_function():
    # Do something here
```

### Arguments

    text
        The text to display next to the spinner. ANSI color strings
        (such as {fg_blue}) will be converted into ANSI escape
        sequences, and the ANSI reset sequence will be added to the
        end of the string.

        If *args or **kwargs are passed they will be used to
        %-format the text.

    spinner
        The name of the spinner to use. Available names are here:
        <https://raw.githubusercontent.com/sindresorhus/cli-spinners/dac4fc6571059bb9e9bc204711e9dfe8f72e5c6f/spinners.json>

    animation
        The animation to apply to the text if it doesn't fit the
        terminal. One of `ellipsed`, `bounce`, `marquee`.

    placement
        Which side of the text to display the spinner on. One of
        `left`, `right`.

    color
        Color of the spinner. One of `blue`, `grey`, `red`, `green`,
        `yellow`, `magenta`, `cyan`, `white`

    interval
        How long in ms to wait between frames. Defaults to the spinner interval (recommended.)

    stream
        Stream to write the output. Defaults to sys.stdout.

    enabled
        Enable or disable the spinner. Defaults to `True`.