| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 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 |
|
| 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: |
| 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 |
|
| 117 |
repository="https://upload.pypi.org/legacy/", |
| 118 |
username="__token__", |
| 119 |
), |
| 120 |
paths=_util.adict(), |
| 121 |
) |