From a26b744fa86c97c5d3c091a09613294b8630ef18 Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Mon, 28 Nov 2022 12:59:44 +0530 Subject: [PATCH 1/5] update version string format --- searx/templates/etheme/base.html | 2 +- searx/version.py | 2 +- searx/webapp.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/searx/templates/etheme/base.html b/searx/templates/etheme/base.html index 6c83864b4..e65ed0808 100644 --- a/searx/templates/etheme/base.html +++ b/searx/templates/etheme/base.html @@ -8,7 +8,7 @@ - {% set version = spot_version.split('+') %} + {% set version = spot_version %} diff --git a/searx/version.py b/searx/version.py index 47e0b5fee..af8fb634e 100644 --- a/searx/version.py +++ b/searx/version.py @@ -24,7 +24,7 @@ except DistributionNotFound: VERSION_STRING = "0.0.0" try: - SPOT_VERSION, METADATA_VERSION = VERSION_STRING.split("+") + METADATA_VERSION, SPOT_VERSION = VERSION_STRING.split("-") except ValueError: SPOT_VERSION = VERSION_STRING METADATA_VERSION = "" diff --git a/searx/webapp.py b/searx/webapp.py index 884dd6529..0ebf75e6a 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -70,7 +70,7 @@ from searx.webutils import ( ) from searx.webadapter import get_search_query_from_webapp, get_selected_categories from searx.utils import html_to_text, gen_useragent, dict_subset, match_language -from searx.version import VERSION_STRING +from searx.version import VERSION_STRING, SPOT_VERSION from searx.languages import language_codes as languages from searx.search import SearchWithPlugins, initialize as search_initialize from searx.search.checker import get_result as checker_get_result @@ -409,7 +409,7 @@ def render(template_name, override_theme=None, **kwargs): if locale in rtl_locales and 'rtl' not in kwargs: kwargs['rtl'] = True - kwargs['spot_version'] = VERSION_STRING + kwargs['spot_version'] = SPOT_VERSION kwargs['year'] = datetime.today().year -- GitLab From 8c77ed7844ff57217cb62cd64dc95cad60b66ef2 Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Mon, 28 Nov 2022 23:59:50 +0530 Subject: [PATCH 2/5] update version format --- searx/templates/etheme/base.html | 25 +++--- searx/version.py | 136 +++++++++++++++++++++++++------ searx/webapp.py | 4 +- setup.py | 15 ++-- 4 files changed, 137 insertions(+), 43 deletions(-) diff --git a/searx/templates/etheme/base.html b/searx/templates/etheme/base.html index e65ed0808..2fa698ef8 100644 --- a/searx/templates/etheme/base.html +++ b/searx/templates/etheme/base.html @@ -8,23 +8,22 @@ - {% set version = spot_version %} - + {% block meta %}{% endblock %} {% block title %}{% endblock %}{{ instance_name }} - - - + + + {% for css in styles %} - + {% endfor %} @@ -95,23 +94,23 @@ {{ _('Privacy') }}
e Foundation 2018-{{ year }}, - {{ _('Powered by') }} Spot {{ version[0] }}
+ {{ _('Powered by') }} Spot {{ version }}
An open-source metasearch engine forked from Searx

- - - - {% if autocomplete %}{% endif %} - + + + {% if autocomplete %}{% endif %} + {% for script in scripts %} - + {% endfor %} diff --git a/searx/version.py b/searx/version.py index af8fb634e..cefdb7a43 100644 --- a/searx/version.py +++ b/searx/version.py @@ -1,30 +1,120 @@ -# -*- coding: utf-8 -*- -''' -searx is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. +# SPDX-License-Identifier: AGPL-3.0-or-later +# lint: pylint +# pylint: disable=,missing-module-docstring,missing-class-docstring -searx is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. +import os +import shlex +import subprocess +import logging +import importlib -You should have received a copy of the GNU Affero General Public License -along with searx. If not, see < http://www.gnu.org/licenses/ >. +# fallback values +# if there is searx.version_frozen module, and it is not possible to get the git tag +VERSION_STRING = "1.0.0" +VERSION_TAG = "1.0.0" +GIT_URL = "unknow" +GIT_BRANCH = "unknow" -(C) 2013- by Adam Tauber, -''' +logger = logging.getLogger("searx") -from pkg_resources import get_distribution, DistributionNotFound +SUBPROCESS_RUN_ENV = { + "PATH": os.environ["PATH"], + "LC_ALL": "C", + "LANGUAGE": "", +} + + +def subprocess_run(args, **kwargs): + """Call :py:func:`subprocess.run` and return (striped) stdout. If returncode is + non-zero, raise a :py:func:`subprocess.CalledProcessError`. + """ + if not isinstance(args, (list, tuple)): + args = shlex.split(args) + + kwargs["env"] = kwargs.get("env", SUBPROCESS_RUN_ENV) + kwargs["encoding"] = kwargs.get("encoding", "utf-8") + kwargs["stdout"] = subprocess.PIPE + kwargs["stderr"] = subprocess.PIPE + # raise CalledProcessError if returncode is non-zero + kwargs["check"] = True + proc = subprocess.run(args, **kwargs) # pylint: disable=subprocess-run-check + return proc.stdout.strip() + + +def get_git_url_and_branch(): + try: + ref = subprocess_run("git rev-parse --abbrev-ref @{upstream}") + except subprocess.CalledProcessError: + ref = subprocess_run("git rev-parse --abbrev-ref master@{upstream}") + origin, git_branch = ref.split("/", 1) + git_url = subprocess_run(["git", "remote", "get-url", origin]) + + # get https:// url from git@ url + if git_url.startswith("git@"): + git_url = git_url.replace(":", "/", 2).replace("git@", "https://", 1) + if git_url.endswith(".git"): + git_url = git_url.replace(".git", "", 1) + + return git_url, git_branch + + +def get_git_version(): + 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 + try: + subprocess_run("git diff --quiet -- . ':!searx/settings.yml' ':!utils/brand.env'") + except subprocess.CalledProcessError as e: + if e.returncode == 1: + git_version += "-dirty" + else: + logger.warning('"%s" returns an unexpected return code %i', e.returncode, e.cmd) + return git_version, tag_version -try: - VERSION_STRING = get_distribution("spot").version -except DistributionNotFound: - VERSION_STRING = "0.0.0" try: - METADATA_VERSION, SPOT_VERSION = VERSION_STRING.split("-") -except ValueError: - SPOT_VERSION = VERSION_STRING - METADATA_VERSION = "" + vf = importlib.import_module('searx.version_frozen') + VERSION_STRING, VERSION_TAG, GIT_URL, GIT_BRANCH = vf.VERSION_STRING, vf.VERSION_TAG, vf.GIT_URL, vf.GIT_BRANCH +except ImportError: + try: + try: + VERSION_STRING, VERSION_TAG = get_git_version() + except subprocess.CalledProcessError as ex: + logger.error("Error while getting the version: %s", ex.stderr) + try: + GIT_URL, GIT_BRANCH = get_git_url_and_branch() + except subprocess.CalledProcessError as ex: + logger.error("Error while getting the git URL & branch: %s", ex.stderr) + except FileNotFoundError as ex: + logger.error("%s is not found, fallback to the default version", ex.filename) + + +logger.info("version: %s", VERSION_STRING) + +if __name__ == "__main__": + import sys + + if len(sys.argv) >= 2 and sys.argv[1] == "freeze": + # freeze the version (to create an archive outside a git repository) + python_code = f"""# SPDX-License-Identifier: AGPL-3.0-or-later +# this file is generated automatically by searx/version.py + +VERSION_STRING = "{VERSION_STRING}" +VERSION_TAG = "{VERSION_TAG}" +GIT_URL = "{GIT_URL}" +GIT_BRANCH = "{GIT_BRANCH}" +""" + with open(os.path.join(os.path.dirname(__file__), "version_frozen.py"), "w", encoding="utf8") as f: + f.write(python_code) + print(f"{f.name} created") + else: + # output shell code to set the variables + # usage: eval "$(python -m searx.version)" + shell_code = f""" +VERSION_STRING="{VERSION_STRING}" +VERSION_TAG="{VERSION_TAG}" +GIT_URL="{GIT_URL}" +GIT_BRANCH="{GIT_BRANCH}" +""" + print(shell_code) diff --git a/searx/webapp.py b/searx/webapp.py index 0ebf75e6a..82994acc5 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -70,7 +70,7 @@ from searx.webutils import ( ) from searx.webadapter import get_search_query_from_webapp, get_selected_categories from searx.utils import html_to_text, gen_useragent, dict_subset, match_language -from searx.version import VERSION_STRING, SPOT_VERSION +from searx.version import VERSION_TAG from searx.languages import language_codes as languages from searx.search import SearchWithPlugins, initialize as search_initialize from searx.search.checker import get_result as checker_get_result @@ -409,7 +409,7 @@ def render(template_name, override_theme=None, **kwargs): if locale in rtl_locales and 'rtl' not in kwargs: kwargs['rtl'] = True - kwargs['spot_version'] = SPOT_VERSION + kwargs['version'] = VERSION_TAG kwargs['year'] = datetime.today().year diff --git a/setup.py b/setup.py index 068f290f7..b27664eb7 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup from setuptools import find_packages -from searx.version import VERSION_STRING +from searx.version import VERSION_TAG from searx import brand with open('README.md', encoding='utf-8') as f: @@ -17,11 +17,11 @@ with open('requirements-dev.txt') as f: setup( name='spot', + python_requires=">=3.7", + version=VERSION_TAG, description="A privacy-respecting, hackable metasearch engine", long_description=long_description, url=brand.DOCS_URL, - use_scm_version={"tag_regex": r"^(?:[\w-]+-)?(?P[vV]?\d+(?:\.\d+){0,2}.*)$"}, - setup_requires=['setuptools_scm'], project_urls={ "Code": brand.GIT_URL, "Issue tracker": brand.ISSUE_URL @@ -35,8 +35,8 @@ setup( 'License :: OSI Approved :: GNU Affero General Public License v3' ], keywords='metasearch searchengine search web http', - author='E FOUNDATION', - author_email='dev@e.email', + author='MURENA SAS', + author_email='dev@murena.io', license='GNU Affero General Public License', packages=find_packages(exclude=["tests*", "searx_extra"]), zip_safe=False, @@ -57,6 +57,8 @@ setup( '../requirements.txt', '../requirements-dev.txt', 'data/*', + 'info/*', + 'info/*/*', 'plugins/*/*', 'static/*.*', 'static/*/*.*', @@ -65,6 +67,9 @@ setup( 'static/*/*/*/*/*.*', 'templates/*/*.*', 'templates/*/*/*.*', + 'tests/*', + 'tests/*/*', + 'tests/*/*/*', 'translations/*/*/*' ], }, -- GitLab From 0922eb4b371a389967f16f69848512139c85a749 Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Tue, 29 Nov 2022 12:22:53 +0530 Subject: [PATCH 3/5] use PEP 440 version format --- searx/templates/etheme/results.html | 4 ++-- searx/version.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/searx/templates/etheme/results.html b/searx/templates/etheme/results.html index 1eca167a9..aa6549f56 100644 --- a/searx/templates/etheme/results.html +++ b/searx/templates/etheme/results.html @@ -73,7 +73,7 @@ {% if pageno == 1 and 'general' in selected_categories %}
- +
{{ put_results(results[:3], True) }}
@@ -148,6 +148,6 @@
- + {% endblock %} diff --git a/searx/version.py b/searx/version.py index cefdb7a43..133e1aa1a 100644 --- a/searx/version.py +++ b/searx/version.py @@ -59,7 +59,7 @@ def get_git_url_and_branch(): 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'") tag_version = git_version = git_commit_date_hash # add "-dirty" suffix if there are uncommited changes except searx/settings.yml -- GitLab From aa1a86eb52c6c1a177bbc34227f7653f1197923a Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Tue, 29 Nov 2022 12:32:27 +0530 Subject: [PATCH 4/5] fix version_tag --- searx/webapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/searx/webapp.py b/searx/webapp.py index 82994acc5..c0162057a 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -1161,7 +1161,7 @@ def config(): 'autocomplete': settings['search']['autocomplete'], 'safe_search': settings['search']['safe_search'], 'default_theme': settings['ui']['default_theme'], - 'version': VERSION_STRING, + 'version': VERSION_TAG, 'brand': { 'CONTACT_URL': brand.CONTACT_URL, 'GIT_URL': brand.GIT_URL, -- GitLab From 314029dcdd54e05f140fc7aa5060638064a51644 Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Wed, 7 Dec 2022 23:45:31 +0530 Subject: [PATCH 5/5] use version from spot package --- searx/version.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/searx/version.py b/searx/version.py index 133e1aa1a..c9fd58f1a 100644 --- a/searx/version.py +++ b/searx/version.py @@ -6,7 +6,7 @@ import os import shlex import subprocess import logging -import importlib +from importlib.metadata import version # fallback values # if there is searx.version_frozen module, and it is not possible to get the git tag @@ -74,8 +74,8 @@ def get_git_version(): try: - vf = importlib.import_module('searx.version_frozen') - VERSION_STRING, VERSION_TAG, GIT_URL, GIT_BRANCH = vf.VERSION_STRING, vf.VERSION_TAG, vf.GIT_URL, vf.GIT_BRANCH + vf = version('spot') + VERSION_STRING = VERSION_TAG = vf except ImportError: try: try: -- GitLab