File: _default_settings.py

package info (click to toggle)
python-rjsmin 1.2.5%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,256 kB
  • sloc: javascript: 8,503; python: 5,315; ansic: 821; sh: 100; makefile: 19
file content (121 lines) | stat: -rw-r--r-- 2,800 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
# -*- coding: ascii -*-
#
# Copyright 2018 - 2025
# Andr\xe9 Malo or his licensors, as applicable
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Default settings
~~~~~~~~~~~~~~~~

"""

import sys as _sys

import invoke as _invoke

from . import shell as _shell
from . import util as _util

# pylint: disable = import-outside-toplevel


def fail(msg):
    """
    Exit with message

    Parameters:
      msg (str):
        The fail message

    Raises:
      invoke.Exit: Always raised
    """
    _sys.stderr.write("Error: %s\n" % (msg,))
    raise _invoke.Exit(code=1)


def which(executable):
    """
    Find executable - or fail

    Parameters:
      executable (str):
        The executable to look out for

    Returns:
      str: The full path

    Raises:
      invoke.Exit: If the executable was not found
    """
    found = _shell.frompath(executable)
    if not found:
        fail("%s not found" % (executable,))
    return found


def find_user():
    """
    Find system user

    Returns:
      str: The user's login name or ``None``
    """
    import getpass as _getpass

    try:
        return _getpass.getuser()
    except Exception:  # pylint: disable = broad-exception-caught
        return None


def default_settings():
    """
    Create default settings

    Returns:
      dict: Default settings
    """
    return dict(
        test=_util.adict(ignore=[]),
        shell=_util.adict(
            (key, value)
            for key, value in vars(_shell).items()
            if not key.startswith("_")
        ),
        c=_shell.command,
        q=lambda x: _shell.command("%s", x),
        s=_shell.split_command,
        fail=fail,
        which=which,
        user=find_user(),
        doc=_util.adict(
            userdoc="docs/userdoc",
            website=_util.adict(
                source="docs/website",
                target="dist/website",
            ),
            sphinx=_util.adict(
                want_apidoc=True,
                build="docs/_userdoc/_build",
                source="docs/_userdoc",
            ),
        ),
        pypi=_util.adict(
            # repository='https://test.pypi.org/legacy/',
            repository="https://upload.pypi.org/legacy/",
            username="__token__",
        ),
        paths=_util.adict(),
    )