From 3a14cf0efe1154acb41730824ca398f28f96cc09 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Sat, 14 Jan 2023 15:22:59 +0000 Subject: [PATCH] Version: rely on pyproject.toml and setuptools_scm Move brand information to Python package rather than settings.yml `pip install .` works with the right version. Dependencies are moved to setup.py requirements.txt contains the dev dependencies. requirements-dev.txt is removed "make install" is broken --- pyproject.toml | 8 +++++ requirements-dev.txt | 22 ------------ requirements.txt | 41 ++++++++++++---------- searx/settings_defaults.py | 26 +++++++++++--- setup.py | 71 ++++++++++++++++++++++++-------------- utils/searxng.sh | 6 ---- 6 files changed, 98 insertions(+), 76 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements-dev.txt diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..b089d3d7e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,8 @@ +[build-system] +requires = [ + "setuptools>=45", + "setuptools_scm[toml]>=6.2", + "wheel", + "pyaml" +] +build-backend = "setuptools.build_meta" diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 87c999c95..000000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,22 +0,0 @@ -mock==5.0.1 -nose2[coverage_plugin]==0.12.0 -cov-core==1.15.0 -black==22.12.0 -pylint==2.16.1 -splinter==0.19.0 -selenium==4.8.0 -twine==4.0.2 -Pallets-Sphinx-Themes==2.0.3 -Sphinx==5.3.0 -sphinx-issues==3.0.1 -sphinx-jinja==2.0.2 -sphinx-tabs==3.4.1 -sphinxcontrib-programoutput==0.17 -sphinx-autobuild==2021.3.14 -sphinx-notfound-page==0.8.3 -myst-parser==0.18.1 -linuxdoc==20221127 -aiounittest==1.4.2 -yamllint==1.29.0 -wlc==1.13 -coloredlogs==15.0.1 diff --git a/requirements.txt b/requirements.txt index a261a0488..82924cf1d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,18 +1,23 @@ -certifi==2022.12.7 -babel==2.11.0 -flask-babel==3.0.1 -flask==2.2.2 -jinja2==3.1.2 -lxml==4.9.2 -pygments==2.14.0 -python-dateutil==2.8.2 -pyyaml==6.0 -httpx[http2]==0.21.2 -Brotli==1.0.9 -uvloop==0.17.0 -httpx-socks[asyncio]==0.7.2 -setproctitle==1.3.2 -redis==4.5.1 -markdown-it-py==2.1.0 -typing_extensions==4.4.0 -fasttext-predict==0.9.2.1 +-e . +mock==5.0.1 +nose2[coverage_plugin]==0.12.0 +cov-core==1.15.0 +black==22.12.0 +pylint==2.16.1 +splinter==0.19.0 +selenium==4.8.0 +twine==4.0.2 +Pallets-Sphinx-Themes==2.0.3 +Sphinx==5.3.0 +sphinx-issues==3.0.1 +sphinx-jinja==2.0.2 +sphinx-tabs==3.4.1 +sphinxcontrib-programoutput==0.17 +sphinx-autobuild==2021.3.14 +sphinx-notfound-page==0.8.3 +myst-parser==0.18.1 +linuxdoc==20221127 +aiounittest==1.4.2 +yamllint==1.29.0 +wlc==1.13 +coloredlogs==15.0.1 \ No newline at end of file diff --git a/searx/settings_defaults.py b/searx/settings_defaults.py index 7baa23cac..529836350 100644 --- a/searx/settings_defaults.py +++ b/searx/settings_defaults.py @@ -11,9 +11,26 @@ import os import logging from base64 import b64decode from os.path import dirname, abspath +from importlib import metadata from searx.languages import language_codes as languages +try: + metadata = metadata.metadata('searxng') + project_urls = {} + for k, v in metadata.items(): + if k == 'Project-URL': + url_type, url = v.split(',') + project_urls[url_type.strip()] = url.strip() +except metadata.PackageNotFoundError: + project_urls = { + "Code": "https://github.com/searxng/searxng", + "Documentation": 'https://docs.searxng.org/', + "Issue tracker": 'https://github.com/searxng/searxng/issues', + "New issue": 'https://github.com/searxng/searxng/issues/new', + 'Public instances': 'https//searx.space', + } + searx_dir = abspath(dirname(__file__)) logger = logging.getLogger('searx') @@ -146,11 +163,10 @@ SCHEMA = { 'enable_metrics': SettingsValue(bool, True), }, 'brand': { - 'issue_url': SettingsValue(str, 'https://github.com/searxng/searxng/issues'), - 'new_issue_url': SettingsValue(str, 'https://github.com/searxng/searxng/issues/new'), - 'docs_url': SettingsValue(str, 'https://docs.searxng.org'), - 'public_instances': SettingsValue((False, str), 'https://searx.space'), - 'wiki_url': SettingsValue(str, 'https://github.com/searxng/searxng/wiki'), + 'issue_url': SettingsValue(str, project_urls['Issue tracker']), + 'new_issue_url': SettingsValue(str, project_urls['New issue']), + 'docs_url': SettingsValue(str, project_urls['Documentation']), + 'public_instances': SettingsValue((False, str), project_urls['Public instances']), }, 'search': { 'safe_search': SettingsValue((0, 1, 2), 0), diff --git a/setup.py b/setup.py index ffcdaf034..473f72662 100644 --- a/setup.py +++ b/setup.py @@ -1,31 +1,41 @@ # -*- coding: utf-8 -*- """Installer for SearXNG package.""" -from setuptools import setup -from setuptools import find_packages - -from searx.version import VERSION_TAG, GIT_URL -from searx import get_setting +from setuptools import setup, find_packages with open('README.rst', encoding='utf-8') as f: long_description = f.read() -with open('requirements.txt') as f: - requirements = [ l.strip() for l in f.readlines()] -with open('requirements-dev.txt') as f: - dev_requirements = [ l.strip() for l in f.readlines()] +def version_yyyymmdd_tag(): + from setuptools_scm.version import ScmVersion + + def custom_version_scheme(version: ScmVersion): + return f"{version.node_date.year}.{version.node_date.month}.{version.node_date.day}+{version.node}" + + def custom_local_scheme(version: ScmVersion): + return '.dirty' if version.dirty else '' + + return { + 'write_to': 'searx/_version.py', + 'version_scheme': custom_version_scheme, + 'local_scheme': custom_local_scheme + } + setup( name='searxng', python_requires=">=3.7", - version=VERSION_TAG, description="A privacy-respecting, hackable metasearch engine", long_description=long_description, - url=get_setting('brand.docs_url'), + use_scm_version=version_yyyymmdd_tag, + url='https://docs.searxng.org/', project_urls={ - "Code": GIT_URL, - "Issue tracker": get_setting('brand.issue_url') + "Code": 'https://github.com/searxng/searxng', + "Documentation": 'https://docs.searxng.org/', + "Issue tracker": 'https://github.com/searxng/searxng/issues', + "New issue": 'https://github.com/searxng/searxng/issues/new', + 'Public instances': 'https//searx.space', }, classifiers=[ "Development Status :: 4 - Beta", @@ -39,24 +49,38 @@ setup( author='SearXNG dev team', author_email='contact@searxng.org', license='GNU Affero General Public License', - packages=find_packages(exclude=["tests*", "searxng_extra"]), + packages=find_packages(exclude=["tests*", "searxng_extra*"]), zip_safe=False, - install_requires=requirements, - extras_require={ - 'test': dev_requirements - }, + install_requires=[ + 'certifi==2022.12.7', + 'babel==2.11.0', + 'flask-babel==3.0.1', + 'flask==2.2.2', + 'jinja2==3.1.2', + 'lxml==4.9.2', + 'pygments==2.14.0', + 'python-dateutil==2.8.2', + 'pyyaml==6.0', + 'httpx[http2]==0.21.2', + 'Brotli==1.0.9', + 'uvloop==0.17.0', + 'httpx-socks[asyncio]==0.7.2', + 'setproctitle==1.3.2', + 'redis==4.5.1', + 'markdown-it-py==2.1.0', + 'typing_extensions==4.4.0', + 'fasttext-predict==0.9.2.1', + ], entry_points={ 'console_scripts': [ - 'searx-run = searx.webapp:run', - 'searx-checker = searx.search.checker.__main__:main' + 'searxng = searx.webapp:run', + 'searxng-checker = searx.search.checker.__main__:main' ] }, package_data={ 'searx': [ 'settings.yml', '../README.rst', - '../requirements.txt', - '../requirements-dev.txt', 'data/*', 'info/*', 'info/*/*', @@ -68,9 +92,6 @@ setup( 'static/*/*/*/*/*.*', 'templates/*/*.*', 'templates/*/*/*.*', - 'tests/*', - 'tests/*/*', - 'tests/*/*/*', 'translations/*/*/*' ], }, diff --git a/utils/searxng.sh b/utils/searxng.sh index dee90bbf4..31bfb8923 100755 --- a/utils/searxng.sh +++ b/utils/searxng.sh @@ -488,9 +488,6 @@ EOF info_msg "install needed python packages" tee_stderr 0.1 <&1 | prefix_stdout "$_service_prefix" pip install -U pip -pip install -U setuptools -pip install -U wheel -pip install -U pyyaml cd ${SEARXNG_SRC} pip install -e . EOF @@ -558,9 +555,6 @@ cd ${SEARXNG_SRC} git fetch origin "$GIT_BRANCH" git reset --hard "origin/$GIT_BRANCH" pip install -U pip -pip install -U setuptools -pip install -U wheel -pip install -U pyyaml pip install -U -e . EOF rst_para "update instance's settings.yml from ${SEARXNG_SETTINGS_PATH}"