We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Illegal version specifier according to pip
<!-- PLEASE FILL THESE FIELDS, IT REALLY HELPS THE MAINTAINERS OF SearXNG -->

**Version of SearXNG, commit number if you are using on master branch and stipulate if you forked SearXNG**
<!-- If you are running on master branch using git execute this command
in order to fetch the latest commit ID:
```
git log -1
``` 
If you are using searxng-docker then look at the bottom of the SearXNG page
and check for the version after "Powered by SearXNG"

Please also stipulate if you are using a forked version of SearXNG and
include a link to the fork source code.
-->

Commit 13b0c251c45c3d14700723b25b601be56178e8df

**How did you install SearXNG?**
<!-- Did you install SearXNG using the official wiki or using searxng-docker
or manually by executing the searx/webapp.py file? -->

Official wiki, install script.

**What happened?**
<!-- A clear and concise description of what the bug is. -->

Step `pip install -e .` fails with

```
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Obtaining file:///usr/local/searxng/searxng-src
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [27 lines of output]
      /usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/dist.py:543: UserWarning: The version specified ('2023.01.15-13b0c251') is an invalid version, this may not work as expected with newer versions of setuptools, pip, and PyPI. Please see PEP 440 for more details.
        warnings.warn(
      2023-01-16 13:17:41,865 INFO:root: running egg_info
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/usr/local/searxng/searxng-src/setup.py", line 19, in <module>
          setup(
        File "/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/__init__.py", line 87, in setup
          return distutils.core.setup(**attrs)
        File "/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
        File "/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/dist.py", line 1208, in run_command
          super().run_command(command)
        File "/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 987, in run_command
          cmd_obj.ensure_finalized()
        File "/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 111, in ensure_finalized
          self.finalize_options()
        File "/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/command/egg_info.py", line 219, in finalize_options
          parsed_version = parse_version(self.egg_version)
        File "/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/pkg_resources/_vendor/packaging/version.py", line 266, in __init__
          raise InvalidVersion(f"Invalid version: '{version}'")
      pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: '2023.01.15-13b0c251'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
```


**How To Reproduce**
<!-- How can we reproduce this issue? (as minimally and as precisely as possible) -->

Follow instructions in https://docs.searxng.org/admin/installation-scripts.html#installation-scripts, in my case on a Raspberry Pi 4B, with following version info:

```
$ uname -a
Linux raspberrypi 5.15.32-v8+ #1538 SMP PREEMPT Thu Mar 31 19:40:39 BST 2022 aarch64 GNU/Linux
```
```
$ python --version
Python 3.9.2
```
```
$ pip --version
pip 22.3.1 from /usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/pip (python 3.9)
```

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->

Expected installation to succeed.

**Screenshots & Logs**
<!-- If applicable, add screenshots, logs to help explain your problem. -->

N/A

**Additional context**
<!-- Add any other context about the problem here. -->

N/A

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `searx/version.py`
Content:
```
1 # SPDX-License-Identifier: AGPL-3.0-or-later
2 # lint: pylint
3 # pylint: disable=,missing-module-docstring,missing-class-docstring
4 
5 import os
6 import shlex
7 import subprocess
8 import logging
9 import importlib
10 
11 # fallback values
12 # if there is searx.version_frozen module, and it is not possible to get the git tag
13 VERSION_STRING = "1.0.0"
14 VERSION_TAG = "1.0.0"
15 GIT_URL = "unknow"
16 GIT_BRANCH = "unknow"
17 
18 logger = logging.getLogger("searx")
19 
20 SUBPROCESS_RUN_ENV = {
21     "PATH": os.environ["PATH"],
22     "LC_ALL": "C",
23     "LANGUAGE": "",
24 }
25 
26 
27 def 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 
44 def get_git_url_and_branch():
45     try:
46         ref = subprocess_run("git rev-parse --abbrev-ref @{upstream}")
47     except subprocess.CalledProcessError:
48         ref = subprocess_run("git rev-parse --abbrev-ref master@{upstream}")
49     origin, git_branch = ref.split("/", 1)
50     git_url = subprocess_run(["git", "remote", "get-url", origin])
51 
52     # get https:// url from git@ url
53     if git_url.startswith("git@"):
54         git_url = git_url.replace(":", "/", 2).replace("git@", "https://", 1)
55     if git_url.endswith(".git"):
56         git_url = git_url.replace(".git", "", 1)
57 
58     return git_url, git_branch
59 
60 
61 def get_git_version():
62     git_commit_date_hash = subprocess_run(r"git show -s --date='format:%Y.%m.%d' --format='%cd-%h'")
63     tag_version = git_version = git_commit_date_hash
64 
65     # add "-dirty" suffix if there are uncommited changes except searx/settings.yml
66     try:
67         subprocess_run("git diff --quiet -- . ':!searx/settings.yml' ':!utils/brand.env'")
68     except subprocess.CalledProcessError as e:
69         if e.returncode == 1:
70             git_version += "-dirty"
71         else:
72             logger.warning('"%s" returns an unexpected return code %i', e.returncode, e.cmd)
73     return git_version, tag_version
74 
75 
76 try:
77     vf = importlib.import_module('searx.version_frozen')
78     VERSION_STRING, VERSION_TAG, GIT_URL, GIT_BRANCH = vf.VERSION_STRING, vf.VERSION_TAG, vf.GIT_URL, vf.GIT_BRANCH
79 except ImportError:
80     try:
81         try:
82             VERSION_STRING, VERSION_TAG = get_git_version()
83         except subprocess.CalledProcessError as ex:
84             logger.error("Error while getting the version: %s", ex.stderr)
85         try:
86             GIT_URL, GIT_BRANCH = get_git_url_and_branch()
87         except subprocess.CalledProcessError as ex:
88             logger.error("Error while getting the git URL & branch: %s", ex.stderr)
89     except FileNotFoundError as ex:
90         logger.error("%s is not found, fallback to the default version", ex.filename)
91 
92 
93 logger.info("version: %s", VERSION_STRING)
94 
95 if __name__ == "__main__":
96     import sys
97 
98     if len(sys.argv) >= 2 and sys.argv[1] == "freeze":
99         # freeze the version (to create an archive outside a git repository)
100         python_code = f"""# SPDX-License-Identifier: AGPL-3.0-or-later
101 # this file is generated automatically by searx/version.py
102 
103 VERSION_STRING = "{VERSION_STRING}"
104 VERSION_TAG = "{VERSION_TAG}"
105 GIT_URL = "{GIT_URL}"
106 GIT_BRANCH = "{GIT_BRANCH}"
107 """
108         with open(os.path.join(os.path.dirname(__file__), "version_frozen.py"), "w", encoding="utf8") as f:
109             f.write(python_code)
110             print(f"{f.name} created")
111     else:
112         # output shell code to set the variables
113         # usage: eval "$(python -m searx.version)"
114         shell_code = f"""
115 VERSION_STRING="{VERSION_STRING}"
116 VERSION_TAG="{VERSION_TAG}"
117 GIT_URL="{GIT_URL}"
118 GIT_BRANCH="{GIT_BRANCH}"
119 """
120         print(shell_code)
121
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/searx/version.py b/searx/version.py
--- a/searx/version.py
+++ b/searx/version.py
@@ -59,7 +59,7 @@
 
 
 def get_git_version():
-    git_commit_date_hash = subprocess_run(r"git show -s --date='format:%Y.%m.%d' --format='%cd-%h'")
+    git_commit_date_hash = subprocess_run(r"git show -s --date='format:%Y.%m.%d' --format='%cd+%h'")
     tag_version = git_version = git_commit_date_hash
 
     # add "-dirty" suffix if there are uncommited changes except searx/settings.yml
@@ -67,7 +67,7 @@
         subprocess_run("git diff --quiet -- . ':!searx/settings.yml' ':!utils/brand.env'")
     except subprocess.CalledProcessError as e:
         if e.returncode == 1:
-            git_version += "-dirty"
+            git_version += "+dirty"
         else:
             logger.warning('"%s" returns an unexpected return code %i', e.returncode, e.cmd)
     return git_version, tag_version

{"golden_diff": "diff --git a/searx/version.py b/searx/version.py\n--- a/searx/version.py\n+++ b/searx/version.py\n@@ -59,7 +59,7 @@\n \n \n def get_git_version():\n-    git_commit_date_hash = subprocess_run(r\"git show -s --date='format:%Y.%m.%d' --format='%cd-%h'\")\n+    git_commit_date_hash = subprocess_run(r\"git show -s --date='format:%Y.%m.%d' --format='%cd+%h'\")\n     tag_version = git_version = git_commit_date_hash\n \n     # add \"-dirty\" suffix if there are uncommited changes except searx/settings.yml\n@@ -67,7 +67,7 @@\n         subprocess_run(\"git diff --quiet -- . ':!searx/settings.yml' ':!utils/brand.env'\")\n     except subprocess.CalledProcessError as e:\n         if e.returncode == 1:\n-            git_version += \"-dirty\"\n+            git_version += \"+dirty\"\n         else:\n             logger.warning('\"%s\" returns an unexpected return code %i', e.returncode, e.cmd)\n     return git_version, tag_version\n", "issue": "Illegal version specifier according to pip\n<!-- PLEASE FILL THESE FIELDS, IT REALLY HELPS THE MAINTAINERS OF SearXNG -->\r\n\r\n**Version of SearXNG, commit number if you are using on master branch and stipulate if you forked SearXNG**\r\n<!-- If you are running on master branch using git execute this command\r\nin order to fetch the latest commit ID:\r\n```\r\ngit log -1\r\n``` \r\nIf you are using searxng-docker then look at the bottom of the SearXNG page\r\nand check for the version after \"Powered by SearXNG\"\r\n\r\nPlease also stipulate if you are using a forked version of SearXNG and\r\ninclude a link to the fork source code.\r\n-->\r\n\r\nCommit 13b0c251c45c3d14700723b25b601be56178e8df\r\n\r\n**How did you install SearXNG?**\r\n<!-- Did you install SearXNG using the official wiki or using searxng-docker\r\nor manually by executing the searx/webapp.py file? -->\r\n\r\nOfficial wiki, install script.\r\n\r\n**What happened?**\r\n<!-- A clear and concise description of what the bug is. -->\r\n\r\nStep `pip install -e .` fails with\r\n\r\n```\r\nLooking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple\r\nObtaining file:///usr/local/searxng/searxng-src\r\n  Preparing metadata (setup.py) ... error\r\n  error: subprocess-exited-with-error\r\n\r\n  \u00d7 python setup.py egg_info did not run successfully.\r\n  \u2502 exit code: 1\r\n  \u2570\u2500> [27 lines of output]\r\n      /usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/dist.py:543: UserWarning: The version specified ('2023.01.15-13b0c251') is an invalid version, this may not work as expected with newer versions of setuptools, pip, and PyPI. Please see PEP 440 for more details.\r\n        warnings.warn(\r\n      2023-01-16 13:17:41,865 INFO:root: running egg_info\r\n      Traceback (most recent call last):\r\n        File \"<string>\", line 2, in <module>\r\n        File \"<pip-setuptools-caller>\", line 34, in <module>\r\n        File \"/usr/local/searxng/searxng-src/setup.py\", line 19, in <module>\r\n          setup(\r\n        File \"/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/__init__.py\", line 87, in setup\r\n          return distutils.core.setup(**attrs)\r\n        File \"/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/_distutils/core.py\", line 185, in setup\r\n          return run_commands(dist)\r\n        File \"/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/_distutils/core.py\", line 201, in run_commands\r\n          dist.run_commands()\r\n        File \"/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/_distutils/dist.py\", line 969, in run_commands\r\n          self.run_command(cmd)\r\n        File \"/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/dist.py\", line 1208, in run_command\r\n          super().run_command(command)\r\n        File \"/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/_distutils/dist.py\", line 987, in run_command\r\n          cmd_obj.ensure_finalized()\r\n        File \"/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/_distutils/cmd.py\", line 111, in ensure_finalized\r\n          self.finalize_options()\r\n        File \"/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/setuptools/command/egg_info.py\", line 219, in finalize_options\r\n          parsed_version = parse_version(self.egg_version)\r\n        File \"/usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/pkg_resources/_vendor/packaging/version.py\", line 266, in __init__\r\n          raise InvalidVersion(f\"Invalid version: '{version}'\")\r\n      pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: '2023.01.15-13b0c251'\r\n      [end of output]\r\n\r\n  note: This error originates from a subprocess, and is likely not a problem with pip.\r\nerror: metadata-generation-failed\r\n\r\n\u00d7 Encountered error while generating package metadata.\r\n\u2570\u2500> See above for output.\r\n\r\nnote: This is an issue with the package mentioned above, not pip.\r\nhint: See above for details.\r\n```\r\n\r\n\r\n**How To Reproduce**\r\n<!-- How can we reproduce this issue? (as minimally and as precisely as possible) -->\r\n\r\nFollow instructions in https://docs.searxng.org/admin/installation-scripts.html#installation-scripts, in my case on a Raspberry Pi 4B, with following version info:\r\n\r\n```\r\n$ uname -a\r\nLinux raspberrypi 5.15.32-v8+ #1538 SMP PREEMPT Thu Mar 31 19:40:39 BST 2022 aarch64 GNU/Linux\r\n```\r\n```\r\n$ python --version\r\nPython 3.9.2\r\n```\r\n```\r\n$ pip --version\r\npip 22.3.1 from /usr/local/searxng/searx-pyenv/lib/python3.9/site-packages/pip (python 3.9)\r\n```\r\n\r\n**Expected behavior**\r\n<!-- A clear and concise description of what you expected to happen. -->\r\n\r\nExpected installation to succeed.\r\n\r\n**Screenshots & Logs**\r\n<!-- If applicable, add screenshots, logs to help explain your problem. -->\r\n\r\nN/A\r\n\r\n**Additional context**\r\n<!-- Add any other context about the problem here. -->\r\n\r\nN/A\n", "before_files": [{"content": "# SPDX-License-Identifier: AGPL-3.0-or-later\n# lint: pylint\n# pylint: disable=,missing-module-docstring,missing-class-docstring\n\nimport os\nimport shlex\nimport subprocess\nimport logging\nimport importlib\n\n# fallback values\n# if there is searx.version_frozen module, and it is not possible to get the git tag\nVERSION_STRING = \"1.0.0\"\nVERSION_TAG = \"1.0.0\"\nGIT_URL = \"unknow\"\nGIT_BRANCH = \"unknow\"\n\nlogger = logging.getLogger(\"searx\")\n\nSUBPROCESS_RUN_ENV = {\n    \"PATH\": os.environ[\"PATH\"],\n    \"LC_ALL\": \"C\",\n    \"LANGUAGE\": \"\",\n}\n\n\ndef subprocess_run(args, **kwargs):\n    \"\"\"Call :py:func:`subprocess.run` and return (striped) stdout.  If returncode is\n    non-zero, raise a :py:func:`subprocess.CalledProcessError`.\n    \"\"\"\n    if not isinstance(args, (list, tuple)):\n        args = shlex.split(args)\n\n    kwargs[\"env\"] = kwargs.get(\"env\", SUBPROCESS_RUN_ENV)\n    kwargs[\"encoding\"] = kwargs.get(\"encoding\", \"utf-8\")\n    kwargs[\"stdout\"] = subprocess.PIPE\n    kwargs[\"stderr\"] = subprocess.PIPE\n    # raise CalledProcessError if returncode is non-zero\n    kwargs[\"check\"] = True\n    proc = subprocess.run(args, **kwargs)  # pylint: disable=subprocess-run-check\n    return proc.stdout.strip()\n\n\ndef get_git_url_and_branch():\n    try:\n        ref = subprocess_run(\"git rev-parse --abbrev-ref @{upstream}\")\n    except subprocess.CalledProcessError:\n        ref = subprocess_run(\"git rev-parse --abbrev-ref master@{upstream}\")\n    origin, git_branch = ref.split(\"/\", 1)\n    git_url = subprocess_run([\"git\", \"remote\", \"get-url\", origin])\n\n    # get https:// url from git@ url\n    if git_url.startswith(\"git@\"):\n        git_url = git_url.replace(\":\", \"/\", 2).replace(\"git@\", \"https://\", 1)\n    if git_url.endswith(\".git\"):\n        git_url = git_url.replace(\".git\", \"\", 1)\n\n    return git_url, git_branch\n\n\ndef get_git_version():\n    git_commit_date_hash = subprocess_run(r\"git show -s --date='format:%Y.%m.%d' --format='%cd-%h'\")\n    tag_version = git_version = git_commit_date_hash\n\n    # add \"-dirty\" suffix if there are uncommited changes except searx/settings.yml\n    try:\n        subprocess_run(\"git diff --quiet -- . ':!searx/settings.yml' ':!utils/brand.env'\")\n    except subprocess.CalledProcessError as e:\n        if e.returncode == 1:\n            git_version += \"-dirty\"\n        else:\n            logger.warning('\"%s\" returns an unexpected return code %i', e.returncode, e.cmd)\n    return git_version, tag_version\n\n\ntry:\n    vf = importlib.import_module('searx.version_frozen')\n    VERSION_STRING, VERSION_TAG, GIT_URL, GIT_BRANCH = vf.VERSION_STRING, vf.VERSION_TAG, vf.GIT_URL, vf.GIT_BRANCH\nexcept ImportError:\n    try:\n        try:\n            VERSION_STRING, VERSION_TAG = get_git_version()\n        except subprocess.CalledProcessError as ex:\n            logger.error(\"Error while getting the version: %s\", ex.stderr)\n        try:\n            GIT_URL, GIT_BRANCH = get_git_url_and_branch()\n        except subprocess.CalledProcessError as ex:\n            logger.error(\"Error while getting the git URL & branch: %s\", ex.stderr)\n    except FileNotFoundError as ex:\n        logger.error(\"%s is not found, fallback to the default version\", ex.filename)\n\n\nlogger.info(\"version: %s\", VERSION_STRING)\n\nif __name__ == \"__main__\":\n    import sys\n\n    if len(sys.argv) >= 2 and sys.argv[1] == \"freeze\":\n        # freeze the version (to create an archive outside a git repository)\n        python_code = f\"\"\"# SPDX-License-Identifier: AGPL-3.0-or-later\n# this file is generated automatically by searx/version.py\n\nVERSION_STRING = \"{VERSION_STRING}\"\nVERSION_TAG = \"{VERSION_TAG}\"\nGIT_URL = \"{GIT_URL}\"\nGIT_BRANCH = \"{GIT_BRANCH}\"\n\"\"\"\n        with open(os.path.join(os.path.dirname(__file__), \"version_frozen.py\"), \"w\", encoding=\"utf8\") as f:\n            f.write(python_code)\n            print(f\"{f.name} created\")\n    else:\n        # output shell code to set the variables\n        # usage: eval \"$(python -m searx.version)\"\n        shell_code = f\"\"\"\nVERSION_STRING=\"{VERSION_STRING}\"\nVERSION_TAG=\"{VERSION_TAG}\"\nGIT_URL=\"{GIT_URL}\"\nGIT_BRANCH=\"{GIT_BRANCH}\"\n\"\"\"\n        print(shell_code)\n", "path": "searx/version.py"}], "after_files": [{"content": "# SPDX-License-Identifier: AGPL-3.0-or-later\n# lint: pylint\n# pylint: disable=,missing-module-docstring,missing-class-docstring\n\nimport os\nimport shlex\nimport subprocess\nimport logging\nimport importlib\n\n# fallback values\n# if there is searx.version_frozen module, and it is not possible to get the git tag\nVERSION_STRING = \"1.0.0\"\nVERSION_TAG = \"1.0.0\"\nGIT_URL = \"unknow\"\nGIT_BRANCH = \"unknow\"\n\nlogger = logging.getLogger(\"searx\")\n\nSUBPROCESS_RUN_ENV = {\n    \"PATH\": os.environ[\"PATH\"],\n    \"LC_ALL\": \"C\",\n    \"LANGUAGE\": \"\",\n}\n\n\ndef subprocess_run(args, **kwargs):\n    \"\"\"Call :py:func:`subprocess.run` and return (striped) stdout.  If returncode is\n    non-zero, raise a :py:func:`subprocess.CalledProcessError`.\n    \"\"\"\n    if not isinstance(args, (list, tuple)):\n        args = shlex.split(args)\n\n    kwargs[\"env\"] = kwargs.get(\"env\", SUBPROCESS_RUN_ENV)\n    kwargs[\"encoding\"] = kwargs.get(\"encoding\", \"utf-8\")\n    kwargs[\"stdout\"] = subprocess.PIPE\n    kwargs[\"stderr\"] = subprocess.PIPE\n    # raise CalledProcessError if returncode is non-zero\n    kwargs[\"check\"] = True\n    proc = subprocess.run(args, **kwargs)  # pylint: disable=subprocess-run-check\n    return proc.stdout.strip()\n\n\ndef get_git_url_and_branch():\n    try:\n        ref = subprocess_run(\"git rev-parse --abbrev-ref @{upstream}\")\n    except subprocess.CalledProcessError:\n        ref = subprocess_run(\"git rev-parse --abbrev-ref master@{upstream}\")\n    origin, git_branch = ref.split(\"/\", 1)\n    git_url = subprocess_run([\"git\", \"remote\", \"get-url\", origin])\n\n    # get https:// url from git@ url\n    if git_url.startswith(\"git@\"):\n        git_url = git_url.replace(\":\", \"/\", 2).replace(\"git@\", \"https://\", 1)\n    if git_url.endswith(\".git\"):\n        git_url = git_url.replace(\".git\", \"\", 1)\n\n    return git_url, git_branch\n\n\ndef get_git_version():\n    git_commit_date_hash = subprocess_run(r\"git show -s --date='format:%Y.%m.%d' --format='%cd+%h'\")\n    tag_version = git_version = git_commit_date_hash\n\n    # add \"-dirty\" suffix if there are uncommited changes except searx/settings.yml\n    try:\n        subprocess_run(\"git diff --quiet -- . ':!searx/settings.yml' ':!utils/brand.env'\")\n    except subprocess.CalledProcessError as e:\n        if e.returncode == 1:\n            git_version += \"+dirty\"\n        else:\n            logger.warning('\"%s\" returns an unexpected return code %i', e.returncode, e.cmd)\n    return git_version, tag_version\n\n\ntry:\n    vf = importlib.import_module('searx.version_frozen')\n    VERSION_STRING, VERSION_TAG, GIT_URL, GIT_BRANCH = vf.VERSION_STRING, vf.VERSION_TAG, vf.GIT_URL, vf.GIT_BRANCH\nexcept ImportError:\n    try:\n        try:\n            VERSION_STRING, VERSION_TAG = get_git_version()\n        except subprocess.CalledProcessError as ex:\n            logger.error(\"Error while getting the version: %s\", ex.stderr)\n        try:\n            GIT_URL, GIT_BRANCH = get_git_url_and_branch()\n        except subprocess.CalledProcessError as ex:\n            logger.error(\"Error while getting the git URL & branch: %s\", ex.stderr)\n    except FileNotFoundError as ex:\n        logger.error(\"%s is not found, fallback to the default version\", ex.filename)\n\n\nlogger.info(\"version: %s\", VERSION_STRING)\n\nif __name__ == \"__main__\":\n    import sys\n\n    if len(sys.argv) >= 2 and sys.argv[1] == \"freeze\":\n        # freeze the version (to create an archive outside a git repository)\n        python_code = f\"\"\"# SPDX-License-Identifier: AGPL-3.0-or-later\n# this file is generated automatically by searx/version.py\n\nVERSION_STRING = \"{VERSION_STRING}\"\nVERSION_TAG = \"{VERSION_TAG}\"\nGIT_URL = \"{GIT_URL}\"\nGIT_BRANCH = \"{GIT_BRANCH}\"\n\"\"\"\n        with open(os.path.join(os.path.dirname(__file__), \"version_frozen.py\"), \"w\", encoding=\"utf8\") as f:\n            f.write(python_code)\n            print(f\"{f.name} created\")\n    else:\n        # output shell code to set the variables\n        # usage: eval \"$(python -m searx.version)\"\n        shell_code = f\"\"\"\nVERSION_STRING=\"{VERSION_STRING}\"\nVERSION_TAG=\"{VERSION_TAG}\"\nGIT_URL=\"{GIT_URL}\"\nGIT_BRANCH=\"{GIT_BRANCH}\"\n\"\"\"\n        print(shell_code)\n", "path": "searx/version.py"}]}