Debian Codegraph @

tasks/_inv/_default_settings.py

raw symbols SCIP
1 # -*- coding: ascii -*-
2 #
3 # Copyright 2018 - 2025
4 # Andr\xe9 Malo or his licensors, as applicable
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 """
18 Default settings
19 ~~~~~~~~~~~~~~~~
20
21 """
22
23 import sys as _sys
24
25 import invoke as _invoke
26
27 from . import shell as _shell
28 from . import util as _util
29
30 # pylint: disable = import-outside-toplevel
31
32
33 def fail(msg):
34 """
35 Exit with message
36
37 Parameters:
38 msg (str):
39 The fail message
40
41 Raises:
42 invoke.Exit: Always raised
43 """
44 _sys.stderr.write("Error: %s\n" % (msg,))
45 raise _invoke.Exit(code=1)
46
47
48 def which(executable):
49 """
50 Find executable - or fail
51
52 Parameters:
53 executable (str):
54 The executable to look out for
55
56 Returns:
57 str: The full path
58
59 Raises:
60 invoke.Exit: If the executable was not found
61 """
62 found = _shell.frompath(executable)
63 if not found:
64 fail("%s not found" % (executable,))
65 return found
66
67
68 def find_user():
69 """
70 Find system user
71
72 Returns:
73 str: The user's login name or ``None``
74 """
75 import getpass as _getpass
76
77 try:
78 return _getpass.getuser()
79 except Exception: # pylint: disable = broad-exception-caught
80 return None
81
82
83 def default_settings():
84 """
85 Create default settings
86
87 Returns:
88 dict: Default settings
89 """
90 return dict(
91 test=_util.adict(ignore=[]),
92 shell=_util.adict(
93 (key, value)
94 for key, value in vars(_shell).items()
95 if not key.startswith("_")
96 ),
97 c=_shell.command,
98 q=lambda x: _shell.command("%s", x),
99 s=_shell.split_command,
100 fail=fail,
101 which=which,
102 user=find_user(),
103 doc=_util.adict(
104 userdoc="docs/userdoc",
105 website=_util.adict(
106 source="docs/website",
107 target="dist/website",
108 ),
109 sphinx=_util.adict(
110 want_apidoc=True,
111 build="docs/_userdoc/_build",
112 source="docs/_userdoc",
113 ),
114 ),
115 pypi=_util.adict(
116 # repository='https://test.pypi.org/legacy/',
117 repository="https://upload.pypi.org/legacy/",
118 username="__token__",
119 ),
120 paths=_util.adict(),
121 )