-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add searx/settings.py ? #2252
Comments
I agree, it would be nice to have some mechanism to check settings.yml. I think it could be something similar to the current If we add the ability to check the settings.yml, we could also add a subcommand or whatever to let instance admins check the configuration without starting searx. |
I don't fully agree. It's true, it would make settings handling better, but I think, there are much more important tasks to solve like engine fixes or other open bugs/enhancements. It generated quite a few issues over the years, so this is a low priority task for me.
Yeah, this could be a handy feature, but nobody asked for it in the past 6-7yrs, so I don't think that it would have so much added value.
I still don't get why is it a problem and how would it be solved by the proposed functionality. This is a single entry point application where every module initializes itself at import time. What is wrong with that in case of searx and what would be the added value of changing this behavior? |
By ..
and
IMO it is conceptional wrong; a. reading or writing files just because a module was imported at some point is programming by side effects (For me, it is a kind of antipattern) b. settings.yml are the settings of the (web) application, not the settings of ever single module. Each python module should stand for its own and the application assembles and parametrize them explicit, not by uncalled site effects (while importing).
This is what I mean in my other comment; its all backed together and not really modular ... I can't use a module stand alone, I always have to use the whole application .. and on the opposite .. I can't replace one component (e.g. how to handle the settings) in the application without touching various modules. This might be OK for small applications, but from my POV searx becomes more and more a real "server". |
Why? Print or socket write is also a side effect but both are very useful. From this point of view any kind of module initialization (like defining functions/classes/variables in a module) is also a side effect, it would be hard to avoid it. Also, I don't understand, that why is it a problem in case of searx that initialization happens in import time? Why would be better to create an
Settings is an importable module which is used by multiple other modules. How would you handle it? Would you write a config file for each module?
Yes, and it is perfectly fine, searx is an application it isn't a framework or a lib, modules are internal and there is no intent to use them outside of the application.
That's how dependency work, there are multiple modules depend on the settings module, just like there are multiple modules that depend on built-in modules or other external ones. If you want to replace a module that is used by an other module as a dependency, then you have to modify the importing module too, but this is true for every single dependency of every single module. Probably it is my fault, but I still can't see the added value. |
It is true, engine fixes should be the most important things on our TODO lists. I mean everyone can write a basic meta search engine from scratch. The real value of searx is the 70-80 engines which has been developed over the years. We should focus on that, because this sets us apart from other search engines.
It is indeed not an urgent/important feature.
I am not sure why this is a problem. Searx is a standalone web application. Why would someone want to use it as a library or framework or whatever? These use cases are not supported. |
See #2256 (comment) |
Not a fault, we have different views on this subject for practical reasons Even if we think there is only one single app today, we already have more. Building the docs is another application (better called "use case") and we do not know what our need is tomorrow. The future might introduce complete new use cases, we can't think of today. So it is good to decouple tasks from each other. (importing is one task, initializing is another task). In the following I will try to explain how I would decouple import from initialize ..
No. From my view, settings.yml is the settings file of the web-application. These settings should be loaded when the Flask App is initialized just before the app is started. With the current implementation, the Lines 1035 to 1043 in e78bfd4
The (new) settings.py should contain a loader function for tasks like this Lines 50 to 51 in e78bfd4
And other modules like autocomplete (to take just one simple example) should have a init method. Since there is no need for OOP in autocomplete and to keep things simple, this init is done by a function, which inits a global variable. To illustrate what I mean: settings=None
def get(*args, **kwargs):
if 'timeout' not in kwargs:
kwargs['timeout'] = settings['outgoing']['request_timeout']
return http_get(*args, **kwargs)
def init(app_settings):
global settings
settings = app_settings |
related to the issue,
The only usage of searx/searx/plugins/__init__.py Line 127 in f310305
This value is never used: Line 25 in f310305
Line 818 in f310305
|
For reference, see |
I cloned your add_settings_default branch and made a first review and some small tests .. looks good to me, what I really like is the cleanup of the |
Currently
searx/__init__.py
readssearx/settings.yml
intosearx.settings
.Then
searx.settings
is read directly in numerous places (not exhaustive) :searx/searx/webapp.py
Line 93 in da8b227
searx/searx/webapp.py
Line 115 in da8b227
searx/searx/preferences.py
Lines 318 to 375 in da8b227
searx/searx/utils.py
Lines 484 to 496 in da8b227
searx/searx/poolrequests.py
Lines 70 to 71 in da8b227
searx/searx/search.py
Lines 38 to 48 in 474d56c
Wouldn't it be better to:
* Add minimum safe search option based on #1392 #2251
* Implement #1209 #1278
?
The text was updated successfully, but these errors were encountered: