summaryrefslogtreecommitdiffstats
path: root/qa/utils.py
blob: d560d86e566c5bb4217fcefb225e605fae43eb68 (plain)
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
import locale
import os
import platform

########################################################################################################################
# PLATFORM_IS_WINDOWS


def platform_is_windows():
    return "windows" in platform.system().lower()


PLATFORM_IS_WINDOWS = platform_is_windows()

########################################################################################################################
# USE_SH_LIB
# Determine whether to use the `sh` library
# On windows we won't want to use the sh library since it's not supported - instead we'll use our own shell module.
# However, we want to be able to overwrite this behavior for testing using the GITLINT_QA_USE_SH_LIB env var.


def use_sh_library():
    gitlint_use_sh_lib_env = os.environ.get("GITLINT_QA_USE_SH_LIB", None)
    if gitlint_use_sh_lib_env:
        return gitlint_use_sh_lib_env == "1"
    return not PLATFORM_IS_WINDOWS


USE_SH_LIB = use_sh_library()

########################################################################################################################
# TERMINAL_ENCODING
# Encoding for reading gitlint command output


def getpreferredencoding():
    """Use local.getpreferredencoding() or fallback to UTF-8."""
    return locale.getpreferredencoding() or "UTF-8"


TERMINAL_ENCODING = getpreferredencoding()


########################################################################################################################
# FILE_ENCODING

# Encoding for reading/writing files within the tests, this is always UTF-8
FILE_ENCODING = "UTF-8"