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

Functions

 subprocess_run (args, **kwargs)
 get_git_url_and_branch ()
 get_git_version ()
 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 44 of file version.py.

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

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()

searx.version.get_git_version ( )

Definition at line 67 of file version.py.

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

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()

searx.version.get_information ( )

Definition at line 87 of file version.py.

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

References get_git_url_and_branch(), and get_git_version().

Here is the call graph for this function:

◆ subprocess_run()

searx.version.subprocess_run ( 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, **kwargs):
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)
35 kwargs["encoding"] = kwargs.get("encoding", "utf-8")
36 kwargs["stdout"] = subprocess.PIPE
37 kwargs["stderr"] = subprocess.PIPE
38 # raise CalledProcessError if returncode is non-zero
39 kwargs["check"] = True
40 proc = subprocess.run(args, **kwargs) # pylint: disable=subprocess-run-check
41 return proc.stdout.strip()
42
43

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 143 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 138 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 137 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 127 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 148 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 107 of file version.py.