Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Adding Windows Support And Other Code Improvements #4485

@Vizonex

Description

@Vizonex

It was never my intent to get involved here at all but as a Searx user myself
I decided to propose a few ideas to improve the code as well as give
Searxng full support for Windows. There's a few ways to go about this but something
I found annoying was downloading the library as well as the config script
being completely jacked mainly because I can't seem to point the path correctly
to some of the CSS Scripts Other than that I wanted to pitch a few ideas to the
table while I have a couple of months on my hands to help out.

Here are 3 of my proposals.

    1. We implement winloop library into the codebase for
      anybody using windows, luckily I saw a maintainer here take interest
      which was my original inspiration for wanting in (I'm also the founder of that project),
      I have some other ideas for keeping the requirements clean and rational.
      I can be very relentless when it comes to making things work on other
      operating systems.
    1. We update some of the internals with better scripts and more
      maintained libraries, an example might be migrating from flask to starlette
      which I'm surprised that nobody here has suggested yet.
      and making wrappers for it to have flask behavior would be pretty simple and would
      only require one subclass around the main Starlette Application class surprisingly if we wanted to implement our own method wrappers we could use that custom subclass to do so.

Now the reason I didn't propose Fastapi is because it installs Pydantic and msgspec is faster and I prefer msgspec more and I don't believe in adding more requirements that aren't needed to this software.

    1. My third was going to be better typehinting but you guys have done a
      fantastic job already with that. I guess I could go in and take some older
      modules and optimize them.

Here's an Example snippet for helping migrate from flask to Starlette that I described doing in my 2nd proposal if we decide to do so

from __future__ import annotations

from starlette.applications import Starlette
from starlette.requests import Request 
from starlette.routing import Route
from starlette.middleware import Middleware

from typing import (
    Callable,
    Any,
    Awaitable,
    Sequence,
)


# I got my inspiration from Flask and Fastapi for this approch.

class SearxAPI(Starlette):
    
    # Starlette plans to remove route functionality 
    # in a future update. However, the code I made retains that approch.
 
    def _route(
        self,
        path: str,
        methods: list[str] | None = None,
        name: str | None = None,
        include_in_schema: bool = True,
        middleware: Sequence[Middleware] | None = None,
    ):
        
        def wrapper(func: Callable[[Request], Awaitable[Any]]):
            self.routes.append(
                Route(
                    path,
                    endpoint=func,
                    methods=methods,
                    name=name,
                    include_in_schema=include_in_schema,
                    middleware=middleware,
                )
            )
            # Return the original function if we decide to use the function elsewhere...
            return func

        return wrapper

    def get(
        self,
        path: str,
        name: str | None = None,
        include_in_schema: bool = True,
        middleware: Sequence[Middleware] | None = None,
    ):
        """Creates a get request enpoint via function wrapper"""
        return self._route(path, ["GET"], name, include_in_schema, middleware)

    def post(
        self,
        path: str,
        name: str | None = None,
        include_in_schema: bool = True,
        middleware: Sequence[Middleware] | None = None,
    ):
        """Creates a post request enpoint via function wrapper"""
        return self._route(path, ["POST"], name, include_in_schema, middleware)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions