.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.version Namespace Reference

Functions

str subprocess_run (str|list[str]|tuple[str] args, **kwargs)
 get_git_url_and_branch ()
tuple[str, str, str] get_git_version ()
tuple[str, str, str, str, str] get_information ()

Variables

str VERSION_STRING = "1.0.0"
str VERSION_TAG = "1.0.0"
str DOCKER_TAG = "1.0.0"
str GIT_URL = "unknown"
str GIT_BRANCH = "unknown"
 logger = logging.getLogger("searx")
dict SUBPROCESS_RUN_ENV
 vf = importlib.import_module('searx.version_frozen')
str python_code
 path = os.path.join(os.path.dirname(__file__), "version_frozen.py")
 encoding
 commit_timestamp = int(subprocess_run("git show -s --format=%ct"))
str shell_code

Function Documentation

◆ get_git_url_and_branch()

searx.version.get_git_url_and_branch ( )

Definition at line 45 of file version.py.

45def get_git_url_and_branch():
46 # handle GHA directly
47 if "GITHUB_REPOSITORY" in os.environ and "GITHUB_REF_NAME" in os.environ:
48 git_url = f"https://github.com/{os.environ['GITHUB_REPOSITORY']}"
49 git_branch = os.environ["GITHUB_REF_NAME"]
50 return git_url, git_branch
51
52 try:
53 ref = subprocess_run("git rev-parse --abbrev-ref @{upstream}")
54 except subprocess.CalledProcessError:
55 ref = subprocess_run("git rev-parse --abbrev-ref master@{upstream}")
56 origin, git_branch = ref.split("/", 1)
57 git_url = subprocess_run(["git", "remote", "get-url", origin])
58
59 # get https:// url from git@ url
60 if git_url.startswith("git@"):
61 git_url = git_url.replace(":", "/", 2).replace("git@", "https://", 1)
62 if git_url.endswith(".git"):
63 git_url = git_url.replace(".git", "", 1)
64
65 return git_url, git_branch
66
67

References subprocess_run().

Referenced by get_information().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_git_version()

tuple[str, str, str] searx.version.get_git_version ( )

Definition at line 68 of file version.py.

68def get_git_version() -> tuple[str, str, str]:
69 git_commit_date_hash: str = subprocess_run(r"git show -s --date='format:%Y.%m.%d' --format='%cd+%h'")
70 # Remove leading zero from minor and patch level / replacement of PR-2122
71 # which depended on the git version: '2023.05.06+..' --> '2023.5.6+..'
72 git_commit_date_hash = git_commit_date_hash.replace('.0', '.')
73 tag_version: str = git_commit_date_hash
74 git_version: str = git_commit_date_hash
75 docker_tag: str = git_commit_date_hash.replace("+", "-")
76
77 # add "+dirty" suffix if there are uncommitted changes except searx/settings.yml
78 try:
79 subprocess_run("git diff --quiet -- . ':!searx/settings.yml' ':!utils/brand.env'")
80 except subprocess.CalledProcessError as e:
81 if e.returncode == 1:
82 git_version += "+dirty"
83 else:
84 logger.warning('"%s" returns an unexpected return code %i', e.returncode, e.cmd)
85
86 return git_version, tag_version, docker_tag
87
88

References subprocess_run().

Referenced by get_information().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_information()

tuple[str, str, str, str, str] searx.version.get_information ( )

Definition at line 89 of file version.py.

89def get_information() -> tuple[str, str, str, str, str]:
90 version_string: str = VERSION_STRING
91 version_tag: str = VERSION_TAG
92 docker_tag: str = DOCKER_TAG
93 git_url: str = GIT_URL
94 git_branch: str = GIT_BRANCH
95
96 try:
97 version_string, version_tag, docker_tag = get_git_version()
98 except subprocess.CalledProcessError as ex:
99 logger.error("Error while getting the version: %s", ex.stderr)
100 try:
101 git_url, git_branch = get_git_url_and_branch()
102 except subprocess.CalledProcessError as ex:
103 logger.error("Error while getting the git URL & branch: %s", ex.stderr)
104
105 return version_string, version_tag, docker_tag, git_url, git_branch
106
107

References get_git_url_and_branch(), and get_git_version().

Here is the call graph for this function:

◆ subprocess_run()

str searx.version.subprocess_run ( str | list[str] | tuple[str] args,
** kwargs )
Call :py:func:`subprocess.run` and return (striped) stdout.  If returncode is
non-zero, raise a :py:func:`subprocess.CalledProcessError`.

Definition at line 27 of file version.py.

27def subprocess_run(args: str | list[str] | tuple[str], **kwargs) -> str: # type: ignore
28 """Call :py:func:`subprocess.run` and return (striped) stdout. If returncode is
29 non-zero, raise a :py:func:`subprocess.CalledProcessError`.
30 """
31 if not isinstance(args, (list, tuple)):
32 args = shlex.split(args)
33
34 kwargs["env"] = kwargs.get("env", SUBPROCESS_RUN_ENV) # type: ignore
35 kwargs["encoding"] = kwargs.get("encoding", "utf-8") # type: ignore
36 kwargs["stdout"] = subprocess.PIPE
37 kwargs["stderr"] = subprocess.PIPE
38 # raise CalledProcessError if returncode is non-zero
39 kwargs["check"] = True
40 # pylint: disable=subprocess-run-check
41 proc = subprocess.run(args, **kwargs) # type: ignore
42 return proc.stdout.strip() # type: ignore
43
44

Referenced by get_git_url_and_branch(), and get_git_version().

Here is the caller graph for this function:

Variable Documentation

◆ commit_timestamp

searx.version.commit_timestamp = int(subprocess_run("git show -s --format=%ct"))

Definition at line 145 of file version.py.

◆ DOCKER_TAG

searx.version.DOCKER_TAG = "1.0.0"

Definition at line 14 of file version.py.

◆ encoding

searx.version.encoding

Definition at line 140 of file version.py.

◆ GIT_BRANCH

searx.version.GIT_BRANCH = "unknown"

Definition at line 16 of file version.py.

◆ GIT_URL

searx.version.GIT_URL = "unknown"

Definition at line 15 of file version.py.

◆ logger

searx.version.logger = logging.getLogger("searx")

Definition at line 18 of file version.py.

◆ path

searx.version.path = os.path.join(os.path.dirname(__file__), "version_frozen.py")

Definition at line 139 of file version.py.

◆ python_code

str searx.version.python_code
Initial value:
1= f"""# SPDX-License-Identifier: AGPL-3.0-or-later
2# pylint: disable=missing-module-docstring
3# this file is generated automatically by searx/version.py
4
5VERSION_STRING = "{VERSION_STRING}"
6VERSION_TAG = "{VERSION_TAG}"
7DOCKER_TAG = "{DOCKER_TAG}"
8GIT_URL = "{GIT_URL}"
9GIT_BRANCH = "{GIT_BRANCH}"
10"""

Definition at line 129 of file version.py.

◆ shell_code

str searx.version.shell_code
Initial value:
1= f"""
2VERSION_STRING="{VERSION_STRING}"
3VERSION_TAG="{VERSION_TAG}"
4DOCKER_TAG="{DOCKER_TAG}"
5GIT_URL="{GIT_URL}"
6GIT_BRANCH="{GIT_BRANCH}"
7"""

Definition at line 150 of file version.py.

◆ SUBPROCESS_RUN_ENV

dict searx.version.SUBPROCESS_RUN_ENV
Initial value:
1= {
2 "PATH": os.environ["PATH"],
3 "LC_ALL": "C",
4 "LANGUAGE": "",
5}

Definition at line 20 of file version.py.

◆ VERSION_STRING

searx.version.VERSION_STRING = "1.0.0"

Definition at line 12 of file version.py.

◆ VERSION_TAG

searx.version.VERSION_TAG = "1.0.0"

Definition at line 13 of file version.py.

◆ vf

searx.version.vf = importlib.import_module('searx.version_frozen')

Definition at line 109 of file version.py.