Sat, 26 Apr 2025 12:34:32 +0200
MicroPython
- Added a configuration option to disable the support for the no longer produced Pimoroni Pico Wireless Pack.
9201 | 1 | # -*- coding: utf-8 -*- |
2 | ||
11090
f5f5f5803935
Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
3 | # Copyright (c) 2022 - 2025 Detlev Offenbach <detlev@die-offenbachs.de> |
9201 | 4 | # |
5 | ||
6 | """ | |
7 | Module implementing some utility functions for setup.cfg creation. | |
8 | """ | |
9 | ||
10 | # | |
11 | # http://setuptools.readthedocs.io/en/latest/setuptools.html#specifying-values | |
12 | # | |
13 | # str - simple string | |
14 | # list-comma - dangling list or string of comma-separated values | |
15 | # list-semi - dangling list or string of semicolon-separated values | |
16 | # bool - True is 1, yes, true | |
17 | # dict - list-comma where keys are separated from values by = | |
18 | # | |
19 | ||
9205
b75da2ba2a1a
Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9201
diff
changeset
|
20 | |
9201 | 21 | def _bool2string(value): |
22 | """ | |
23 | Function to convert a bool value to a setup.cfg string. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
24 | |
9201 | 25 | @param value bool value to be converted |
26 | @type bool | |
27 | @return setup.cfg string | |
28 | @rtype str | |
29 | """ | |
30 | return "True" if value else "False" | |
31 | ||
32 | ||
33 | def _list2string(value): | |
34 | """ | |
35 | Function to convert a list value to a setup.cfg string. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
36 | |
9201 | 37 | @param value list value to be converted |
38 | @type list | |
39 | @return setup.cfg string | |
40 | @rtype str | |
41 | """ | |
42 | if value: | |
43 | return "\n{0}".format("\n".join(sorted(filter(None, value)))) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
44 | |
9205
b75da2ba2a1a
Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9201
diff
changeset
|
45 | return "" |
9201 | 46 | |
47 | ||
48 | def _dict2list(value): | |
49 | """ | |
50 | Function to convert a dict value to a setup.cfg list string. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
51 | |
9201 | 52 | @param value dict value to be converted |
53 | @type dict | |
54 | @yield setup.cfg string | |
55 | @ytype str | |
56 | """ | |
57 | for k, v in value.items(): | |
58 | yield "{0} = {1}".format(k, v) | |
59 | ||
60 | ||
61 | def _dict2string(value): | |
62 | """ | |
63 | Function to convert a dict value to a setup.cfg string. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
64 | |
9201 | 65 | @param value dict value to be converted |
66 | @type dict | |
67 | @return setup.cfg string | |
68 | @rtype str | |
69 | """ | |
70 | return _list2string(list(_dict2list(value))) | |
71 | ||
9205
b75da2ba2a1a
Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9201
diff
changeset
|
72 | |
9201 | 73 | def toString(value): |
74 | """ | |
9205
b75da2ba2a1a
Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9201
diff
changeset
|
75 | Function to convert a value to a setup.cfg string. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
76 | |
9201 | 77 | @param value value to be converted |
78 | @type bool, list, set, tuple or dict | |
79 | @return setup.cfg string | |
80 | @rtype str | |
81 | """ | |
82 | if isinstance(value, bool): | |
83 | return _bool2string(value) | |
84 | if isinstance(value, (list, set, tuple)): | |
85 | return _list2string(value) | |
86 | if isinstance(value, dict): | |
87 | return _dict2string(value) | |
88 | return str(value).rstrip() |