12VERSION_STRING =
"1.0.0"
17logger = logging.getLogger(
"searx")
20 "PATH": os.environ[
"PATH"],
27 """Call :py:func:`subprocess.run` and return (striped) stdout. If returncode is
28 non-zero, raise a :py:func:`subprocess.CalledProcessError`.
30 if not isinstance(args, (list, tuple)):
31 args = shlex.split(args)
33 kwargs[
"env"] = kwargs.get(
"env", SUBPROCESS_RUN_ENV)
34 kwargs[
"encoding"] = kwargs.get(
"encoding",
"utf-8")
35 kwargs[
"stdout"] = subprocess.PIPE
36 kwargs[
"stderr"] = subprocess.PIPE
38 kwargs[
"check"] =
True
39 proc = subprocess.run(args, **kwargs)
40 return proc.stdout.strip()
46 except subprocess.CalledProcessError:
47 ref =
subprocess_run(
"git rev-parse --abbrev-ref master@{upstream}")
48 origin, git_branch = ref.split(
"/", 1)
52 if git_url.startswith(
"git@"):
53 git_url = git_url.replace(
":",
"/", 2).replace(
"git@",
"https://", 1)
54 if git_url.endswith(
".git"):
55 git_url = git_url.replace(
".git",
"", 1)
57 return git_url, git_branch
61 git_commit_date_hash =
subprocess_run(
r"git show -s --date='format:%Y.%m.%d' --format='%cd+%h'")
64 git_commit_date_hash = git_commit_date_hash.replace(
'.0',
'.')
65 tag_version = git_version = git_commit_date_hash
69 subprocess_run(
"git diff --quiet -- . ':!searx/settings.yml' ':!utils/brand.env'")
70 except subprocess.CalledProcessError
as e:
72 git_version +=
"+dirty"
74 logger.warning(
'"%s" returns an unexpected return code %i', e.returncode, e.cmd)
75 docker_tag = git_version.replace(
"+",
"-")
76 return git_version, tag_version, docker_tag
80 vf = importlib.import_module(
'searx.version_frozen')
81 VERSION_STRING, VERSION_TAG, DOCKER_TAG, GIT_URL, GIT_BRANCH = (
92 except subprocess.CalledProcessError
as ex:
93 logger.error(
"Error while getting the version: %s", ex.stderr)
96 except subprocess.CalledProcessError
as ex:
97 logger.error(
"Error while getting the git URL & branch: %s", ex.stderr)
98 except FileNotFoundError
as ex:
99 logger.error(
"%s is not found, fallback to the default version", ex.filename)
102logger.info(
"version: %s", VERSION_STRING)
104if __name__ ==
"__main__":
107 if len(sys.argv) >= 2
and sys.argv[1] ==
"freeze":
109 python_code = f
"""# SPDX-License-Identifier: AGPL-3.0-or-later
110# pylint: disable=missing-module-docstring
111# this file is generated automatically by searx/version.py
113VERSION_STRING = "{VERSION_STRING}"
114VERSION_TAG = "{VERSION_TAG}"
115DOCKER_TAG = "{DOCKER_TAG}"
117GIT_BRANCH = "{GIT_BRANCH}"
119 with open(os.path.join(os.path.dirname(__file__),
"version_frozen.py"),
"w", encoding=
"utf8")
as f:
121 print(f
"{f.name} created")
126VERSION_STRING="{VERSION_STRING}"
127VERSION_TAG="{VERSION_TAG}"
128DOCKER_TAG="{DOCKER_TAG}"
130GIT_BRANCH="{GIT_BRANCH}"
subprocess_run(args, **kwargs)