on master help sign in
Merge branch 'master' of https://github.com/asciimoo/searx into dos2unix

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commit9988cdcbc514f799c5a2d2a111c82b8a123bbae3 authorMarkus Heiser <markus.heiser@darmarit.de> dateTue 10 Dec 2019, 17:35 (7 years ago) parent56b7e0550e1fca
22 files changed+1317−313
.dir-locals.el+133 .gitignore+3 .pylintrc+444 AUTHORS.rst+3−1 Makefile+62 searx/engines/google.py+7−14 searx/templates/oscar/advanced.html+5−4 searx/templates/oscar/base.html+12−9 searx/templates/oscar/categories.html+9−9 searx/templates/oscar/infobox.html+17−16 searx/templates/oscar/languages.html+7−7 searx/templates/oscar/macros.html+23−23 searx/templates/oscar/navbar.html+8−8 searx/templates/oscar/result_templates/default.html+14−14 searx/templates/oscar/result_templates/images.html+33−46 searx/templates/oscar/results.html+62−62 searx/templates/oscar/search.html+3−3 searx/templates/oscar/time-range.html+11−11 setup.py+6−6 tests/unit/engines/test_google.py+37−80 utils/makefile.include+128 utils/makefile.python+290
.dir-locals.elnew file+133
@@ -0,0 +1,133 @@
1+;;; .dir-locals.el
2+;;
3+;; If you get ``*** EPC Error ***`` (even after a jedi:install-server) in your
4+;; emacs session, mostly you have jedi-mode enabled but the python enviroment is
5+;; missed. The python environment has to be next to the
6+;; ``<repo>/.dir-locals.el`` in::
7+;;
8+;; ./local/py3
9+;;
10+;; In Emacs, some buffer locals are referencing the project environment:
11+;;
12+;; - prj-root --> <repo>/
13+;; - python-environment-directory --> <repo>/local
14+;; - python-environment-default-root-name --> py3
15+;; - python-shell-virtualenv-root --> <repo>/local/py3
16+;; When this variable is set with the path of the virtualenv to use,
17+;; `process-environment' and `exec-path' get proper values in order to run
18+;; shells inside the specified virtualenv, example::
19+;; (setq python-shell-virtualenv-root "/path/to/env/")
20+;;
21+;; To setup such an environment build target 'pyenv' or 'pyenvinstall'::
22+;;
23+;; $ make pyenvinstall
24+;;
25+;; Alternatively create the virtualenv, source it and install jedi + epc
26+;; (required by `emacs-jedi <https://tkf.github.io/emacs-jedi>`_)::
27+;;
28+;; $ virtualenv --python=python3 "--no-site-packages" ./local/py3
29+;; ...
30+;; $ source ./local/py3/bin/activate
31+;; (py3)$ # now install into the activated 'py3' environment ..
32+;; (py3)$ pip install jedi epc
33+;; ...
34+;;
35+;; Here is what also I found useful to add to my .emacs::
36+;;
37+;; (global-set-key [f6] 'flycheck-mode)
38+;; (add-hook 'python-mode-hook 'my:python-mode-hook)
39+;;
40+;; (defun my:python-mode-hook ()
41+;; (add-to-list 'company-backends 'company-jedi)
42+;; (require 'jedi-core)
43+;; (jedi:setup)
44+;; (define-key python-mode-map (kbd "C-c C-d") 'jedi:show-doc)
45+;; (define-key python-mode-map (kbd "M-.") 'jedi:goto-definition)
46+;; (define-key python-mode-map (kbd "M-,") 'jedi:goto-definition-pop-marker)
47+;; )
48+;;
49+
50+((nil
51+ . ((fill-column . 80)
52+ ))
53+ (python-mode
54+ . ((indent-tabs-mode . nil)
55+
56+ ;; project root folder is where the `.dir-locals.el' is located
57+ (eval . (setq-local
58+ prj-root (locate-dominating-file default-directory ".dir-locals.el")))
59+
60+ (eval . (setq-local
61+ python-environment-directory (expand-file-name "./local" prj-root)))
62+
63+ ;; use 'py3' enviroment as default
64+ (eval . (setq-local
65+ python-environment-default-root-name "py3"))
66+
67+ (eval . (setq-local
68+ python-shell-virtualenv-root
69+ (concat python-environment-directory
70+ "/"
71+ python-environment-default-root-name)))
72+
73+ ;; python-shell-virtualenv-path is obsolete, use python-shell-virtualenv-root!
74+ ;; (eval . (setq-local
75+ ;; python-shell-virtualenv-path python-shell-virtualenv-root))
76+
77+ (eval . (setq-local
78+ python-shell-interpreter
79+ (expand-file-name "bin/python" python-shell-virtualenv-root)))
80+
81+ (eval . (setq-local
82+ python-environment-virtualenv
83+ (list (expand-file-name "bin/virtualenv" python-shell-virtualenv-root)
84+ ;;"--system-site-packages"
85+ "--quiet")))
86+
87+ (eval . (setq-local
88+ pylint-command
89+ (expand-file-name "bin/pylint" python-shell-virtualenv-root)))
90+
91+ ;; pylint will find the '.pylintrc' file next to the CWD
92+ ;; https://pylint.readthedocs.io/en/latest/user_guide/run.html#command-line-options
93+ (eval . (setq-local
94+ flycheck-pylintrc ".pylintrc"))
95+
96+ ;; flycheck & other python stuff should use the local py3 environment
97+ (eval . (setq-local
98+ flycheck-python-pylint-executable python-shell-interpreter))
99+
100+ ;; use 'M-x jedi:show-setup-info' and 'M-x epc:controller' to inspect jedi server
101+
102+ ;; https://tkf.github.io/emacs-jedi/latest/#jedi:environment-root -- You
103+ ;; can specify a full path instead of a name (relative path). In that case,
104+ ;; python-environment-directory is ignored and Python virtual environment
105+ ;; is created at the specified path.
106+ (eval . (setq-local jedi:environment-root python-shell-virtualenv-root))
107+
108+ ;; https://tkf.github.io/emacs-jedi/latest/#jedi:server-command
109+ (eval .(setq-local
110+ jedi:server-command
111+ (list python-shell-interpreter
112+ jedi:server-script)
113+ ))
114+
115+ ;; jedi:environment-virtualenv --> see above 'python-environment-virtualenv'
116+ ;; is set buffer local! No need to setup jedi:environment-virtualenv:
117+ ;;
118+ ;; Virtualenv command to use. A list of string. If it is nil,
119+ ;; python-environment-virtualenv is used instead. You must set non-nil
120+ ;; value to jedi:environment-root in order to make this setting work.
121+ ;;
122+ ;; https://tkf.github.io/emacs-jedi/latest/#jedi:environment-virtualenv
123+ ;;
124+ ;; (eval . (setq-local
125+ ;; jedi:environment-virtualenv
126+ ;; (list (expand-file-name "bin/virtualenv" python-shell-virtualenv-root)
127+ ;; ;;"--python"
128+ ;; ;;"/usr/bin/python3.4"
129+ ;; )))
130+
131+ ;; jedi:server-args
132+
133+ )))
.gitignore+3
@@ -18,3 +18,6 @@ setup.cfg
1818node_modules/
1919
2020.tx/
21+
22+local/
23+searx.egg-info/
.pylintrcnew file+444
@@ -0,0 +1,444 @@
1+# -*- coding: utf-8; mode: conf -*-
2+# lint Python modules using external checkers.
3+#
4+# This is the main checker controlling the other ones and the reports
5+# generation. It is itself both a raw checker and an astng checker in order
6+# to:
7+# * handle message activation / deactivation at the module level
8+# * handle some basic but necessary stats'data (number of classes, methods...)
9+#
10+[MASTER]
11+
12+# A comma-separated list of package or module names from where C extensions may
13+# be loaded. Extensions are loading into the active Python interpreter and may
14+# run arbitrary code
15+extension-pkg-whitelist=
16+
17+# Add files or directories to the blacklist. They should be base names, not
18+# paths.
19+ignore=CVS, .git, .svn
20+
21+# Add files or directories matching the regex patterns to the blacklist. The
22+# regex matches against base names, not paths.
23+ignore-patterns=
24+
25+# Python code to execute, usually for sys.path manipulation such as
26+# pygtk.require().
27+#init-hook=
28+
29+# Use multiple processes to speed up Pylint.
30+jobs=1
31+
32+# List of plugins (as comma separated values of python modules names) to load,
33+# usually to register additional checkers.
34+load-plugins=
35+
36+# Pickle collected data for later comparisons.
37+persistent=yes
38+
39+# Specify a configuration file.
40+#rcfile=
41+
42+# Allow loading of arbitrary C extensions. Extensions are imported into the
43+# active Python interpreter and may run arbitrary code.
44+unsafe-load-any-extension=no
45+
46+
47+[MESSAGES CONTROL]
48+
49+# Only show warnings with the listed confidence levels. Leave empty to show
50+# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED
51+confidence=
52+
53+# Disable the message, report, category or checker with the given id(s). You
54+# can either give multiple identifiers separated by comma (,) or put this
55+# option multiple times (only on the command line, not in the configuration
56+# file where it should appear only once).You can also use "--disable=all" to
57+# disable everything first and then reenable specific checks. For example, if
58+# you want to run only the similarities checker, you can use "--disable=all
59+# --enable=similarities". If you want to run only the classes checker, but have
60+# no Warning level messages displayed, use"--disable=all --enable=classes
61+# --disable=W"
62+disable=bad-whitespace, duplicate-code
63+
64+# Enable the message, report, category or checker with the given id(s). You can
65+# either give multiple identifier separated by comma (,) or put this option
66+# multiple time (only on the command line, not in the configuration file where
67+# it should appear only once). See also the "--disable" option for examples.
68+enable=
69+
70+
71+[REPORTS]
72+
73+# Python expression which should return a note less than 10 (10 is the highest
74+# note). You have access to the variables errors warning, statement which
75+# respectively contain the number of errors / warnings messages and the total
76+# number of statements analyzed. This is used by the global evaluation report
77+# (RP0004).
78+evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
79+
80+# Template used to display messages. This is a python new-style format string
81+# used to format the message information. See doc for all details
82+
83+# HINT: do not set this here, use argument --msg-template=...
84+#msg-template={path}:{line}: [{msg_id}({symbol}),{obj}] {msg}
85+
86+# Set the output format. Available formats are text, parseable, colorized, json
87+# and msvs (visual studio).You can also give a reporter class, eg
88+# mypackage.mymodule.MyReporterClass.
89+
90+# HINT: do not set this here, use argument --output-format=...
91+#output-format=text
92+
93+# Tells whether to display a full report or only the messages
94+reports=no
95+
96+# Activate the evaluation score.
97+score=yes
98+
99+
100+[REFACTORING]
101+
102+# Maximum number of nested blocks for function / method body
103+max-nested-blocks=5
104+
105+
106+[BASIC]
107+
108+# List of builtins function names that should not be used, separated by a comma
109+bad-functions=map,filter,apply,input
110+
111+# Naming hint for argument names
112+argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
113+
114+# Regular expression matching correct argument names
115+argument-rgx=(([a-z][a-zA-Z0-9_]{2,30})|(_[a-z0-9_]*))$
116+
117+# Naming hint for attribute names
118+attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
119+
120+# Regular expression matching correct attribute names
121+attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*)|([A-Z0-9_]*))$
122+
123+# Bad variable names which should always be refused, separated by a comma
124+bad-names=foo,bar,baz,toto,tutu,tata
125+
126+# Naming hint for class attribute names
127+class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
128+
129+# Regular expression matching correct class attribute names
130+class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
131+
132+# Naming hint for class names
133+class-name-hint=[A-Z_][a-zA-Z0-9]+$
134+
135+# Regular expression matching correct class names
136+class-rgx=[A-Z_][a-zA-Z0-9]+$
137+
138+# Naming hint for constant names
139+const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$
140+
141+# Regular expression matching correct constant names
142+const-rgx=(([a-zA-Z_][a-zA-Z0-9_]*)|(__.*__))$
143+#const-rgx=[f]?[A-Z_][a-zA-Z0-9_]{2,30}$
144+
145+# Minimum line length for functions/classes that require docstrings, shorter
146+# ones are exempt.
147+docstring-min-length=-1
148+
149+# Naming hint for function names
150+function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
151+
152+# Regular expression matching correct function names
153+function-rgx=(([a-z][a-zA-Z0-9_]{2,30})|(_[a-z0-9_]*))$
154+
155+# Good variable names which should always be accepted, separated by a comma
156+good-names=i,j,k,ex,Run,_,log,cfg,id
157+
158+# Include a hint for the correct naming format with invalid-name
159+include-naming-hint=no
160+
161+# Naming hint for inline iteration names
162+inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$
163+
164+# Regular expression matching correct inline iteration names
165+inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
166+
167+# Naming hint for method names
168+method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
169+
170+# Regular expression matching correct method names
171+method-rgx=(([a-z][a-zA-Z0-9_]{2,30})|(_[a-z0-9_]*))$
172+
173+# Naming hint for module names
174+module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
175+
176+# Regular expression matching correct module names
177+#module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
178+module-rgx=([a-z_][a-z0-9_]*)$
179+
180+# Colon-delimited sets of names that determine each other's naming style when
181+# the name regexes allow several styles.
182+name-group=
183+
184+# Regular expression which should only match function or class names that do
185+# not require a docstring.
186+no-docstring-rgx=^_
187+
188+# List of decorators that produce properties, such as abc.abstractproperty. Add
189+# to this list to register other decorators that produce valid properties.
190+property-classes=abc.abstractproperty
191+
192+# Naming hint for variable names
193+variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
194+
195+# Regular expression matching correct variable names
196+variable-rgx=(([a-z][a-zA-Z0-9_]{2,30})|(_[a-z0-9_]*)|([a-z]))$
197+
198+
199+[FORMAT]
200+
201+# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
202+expected-line-ending-format=
203+
204+# Regexp for a line that is allowed to be longer than the limit.
205+ignore-long-lines=^\s*(# )?<?https?://\S+>?$
206+
207+# Number of spaces of indent required inside a hanging or continued line.
208+indent-after-paren=4
209+
210+# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
211+# tab).
212+indent-string=' '
213+
214+# Maximum number of characters on a single line.
215+max-line-length=120
216+
217+# Maximum number of lines in a module
218+max-module-lines=2000
219+
220+# List of optional constructs for which whitespace checking is disabled. `dict-
221+# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
222+# `trailing-comma` allows a space between comma and closing bracket: (a, ).
223+# `empty-line` allows space-only lines.
224+no-space-check=trailing-comma,dict-separator
225+
226+# Allow the body of a class to be on the same line as the declaration if body
227+# contains single statement.No config file found, using default configuration
228+
229+single-line-class-stmt=no
230+
231+# Allow the body of an if to be on the same line as the test if there is no
232+# else.
233+single-line-if-stmt=no
234+
235+
236+[LOGGING]
237+
238+# Logging modules to check that the string format arguments are in logging
239+# function parameter format
240+logging-modules=logging
241+
242+
243+[MISCELLANEOUS]
244+
245+# List of note tags to take in consideration, separated by a comma.
246+notes=FIXME,XXX,TODO
247+
248+
249+[SIMILARITIES]
250+
251+# Ignore comments when computing similarities.
252+ignore-comments=yes
253+
254+# Ignore docstrings when computing similarities.
255+ignore-docstrings=yes
256+
257+# Ignore imports when computing similarities.
258+ignore-imports=no
259+
260+# Minimum lines number of a similarity.
261+min-similarity-lines=4
262+
263+
264+[SPELLING]
265+
266+# Spelling dictionary name. Available dictionaries: none. To make it working
267+# install python-enchant package.
268+spelling-dict=
269+
270+# List of comma separated words that should not be checked.
271+spelling-ignore-words=
272+
273+# A path to a file that contains private dictionary; one word per line.
274+spelling-private-dict-file=
275+
276+# Tells whether to store unknown words to indicated private dictionary in
277+# --spelling-private-dict-file option instead of raising a message.
278+spelling-store-unknown-words=no
279+
280+
281+[TYPECHECK]
282+
283+# List of decorators that produce context managers, such as
284+# contextlib.contextmanager. Add to this list to register other decorators that
285+# produce valid context managers.
286+contextmanager-decorators=contextlib.contextmanager
287+
288+# List of members which are set dynamically and missed by pylint inference
289+# system, and so shouldn't trigger E1101 when accessed. Python regular
290+# expressions are accepted.
291+generated-members=
292+
293+# Tells whether missing members accessed in mixin class should be ignored. A
294+# mixin class is detected if its name ends with "mixin" (case insensitive).
295+ignore-mixin-members=yes
296+
297+# This flag controls whether pylint should warn about no-member and similar
298+# checks whenever an opaque object is returned when inferring. The inference
299+# can return multiple potential results while evaluating a Python object, but
300+# some branches might not be evaluated, which results in partial inference. In
301+# that case, it might be useful to still emit no-member and other checks for
302+# the rest of the inferred objects.
303+ignore-on-opaque-inference=yes
304+
305+# List of class names for which member attributes should not be checked (useful
306+# for classes with dynamically set attributes). This supports the use of
307+# qualified names.
308+ignored-classes=optparse.Values,thread._local,_thread._local
309+
310+# List of module names for which member attributes should not be checked
311+# (useful for modules/projects where namespaces are manipulated during runtime
312+# and thus existing member attributes cannot be deduced by static analysis. It
313+# supports qualified module names, as well as Unix pattern matching.
314+ignored-modules=
315+
316+# Show a hint with possible names when a member name was not found. The aspect
317+# of finding the hint is based on edit distance.
318+missing-member-hint=yes
319+
320+# The minimum edit distance a name should have in order to be considered a
321+# similar match for a missing member name.
322+missing-member-hint-distance=1
323+
324+# The total number of similar names that should be taken in consideration when
325+# showing a hint for a missing member.
326+missing-member-max-choices=1
327+
328+
329+[VARIABLES]
330+
331+# List of additional names supposed to be defined in builtins. Remember that
332+# you should avoid to define new builtins when possible.
333+additional-builtins=
334+
335+# Tells whether unused global variables should be treated as a violation.
336+allow-global-unused-variables=yes
337+
338+# List of strings which can identify a callback function by name. A callback
339+# name must start or end with one of those strings.
340+callbacks=cb_,_cb
341+
342+# A regular expression matching the name of dummy variables (i.e. expectedly
343+# not used).
344+dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_
345+
346+# Argument names that match this expression will be ignored. Default to name
347+# with leading underscore
348+ignored-argument-names=_.*|^ignored_|^unused_
349+
350+# Tells whether we should check for unused import in __init__ files.
351+init-import=no
352+
353+# List of qualified module names which can have objects that can redefine
354+# builtins.
355+redefining-builtins-modules=six.moves,future.builtins
356+
357+
358+[CLASSES]
359+
360+# List of method names used to declare (i.e. assign) instance attributes.
361+defining-attr-methods=__init__,__new__,setUp
362+
363+# List of member names, which should be excluded from the protected access
364+# warning.
365+exclude-protected=_asdict,_fields,_replace,_source,_make
366+
367+# List of valid names for the first argument in a class method.
368+valid-classmethod-first-arg=cls
369+
370+# List of valid names for the first argument in a metaclass class method.
371+valid-metaclass-classmethod-first-arg=mcs
372+
373+
374+[DESIGN]
375+
376+# Maximum number of arguments for function / method
377+max-args=8
378+
379+# Maximum number of attributes for a class (see R0902).
380+max-attributes=20
381+
382+# Maximum number of boolean expressions in a if statement
383+max-bool-expr=5
384+
385+# Maximum number of branch for function / method body
386+max-branches=12
387+
388+# Maximum number of locals for function / method body
389+max-locals=20
390+
391+# Maximum number of parents for a class (see R0901).
392+max-parents=7
393+
394+# Maximum number of public methods for a class (see R0904).
395+max-public-methods=20
396+
397+# Maximum number of return / yield for function / method body
398+max-returns=6
399+
400+# Maximum number of statements in function / method body
401+max-statements=50
402+
403+# Minimum number of public methods for a class (see R0903).
404+min-public-methods=2
405+
406+
407+[IMPORTS]
408+
409+# Allow wildcard imports from modules that define __all__.
410+allow-wildcard-with-all=no
411+
412+# Analyse import fallback blocks. This can be used to support both Python 2 and
413+# 3 compatible code, which means that the block might have code that exists
414+# only in one or another interpreter, leading to false positives when analysed.
415+analyse-fallback-blocks=no
416+
417+# Deprecated modules which should not be used, separated by a comma
418+deprecated-modules=optparse,tkinter.tix
419+
420+# Create a graph of external dependencies in the given file (report RP0402 must
421+# not be disabled)
422+ext-import-graph=
423+
424+# Create a graph of every (i.e. internal and external) dependencies in the
425+# given file (report RP0402 must not be disabled)
426+import-graph=
427+
428+# Create a graph of internal dependencies in the given file (report RP0402 must
429+# not be disabled)
430+int-import-graph=
431+
432+# Force import order to recognize a module as part of the standard
433+# compatibility libraries.
434+known-standard-library=
435+
436+# Force import order to recognize a module as part of a third party library.
437+known-third-party=enchant
438+
439+
440+[EXCEPTIONS]
441+
442+# Exceptions that will emit a warning when being caught. Defaults to
443+# "Exception"
444+overgeneral-exceptions=Exception
AUTHORS.rst+3−1
@@ -1,4 +1,4 @@
1−Searx was created by Adam Tauber and is maintained by Adam Tauber, Alexandre Flament and Noémi Ványi.
1+Searx was created by Adam Tauber and is maintained by Adam Tauber, Alexandre Flament, Noémi Ványi, @pofilo and Markus Heiser.
22
33Major contributing authors:
44
@@ -9,6 +9,8 @@ Major contributing authors:
99- @Cqoicebordel
1010- Noémi Ványi
1111- Marc Abonce Seguin @a01200356
12+- @pofilo
13+- Markus Heiser @return42
1214
1315People who have submitted patches/translates, reported bugs, consulted features or
1416generally made searx better:
Makefilenew file+62
@@ -0,0 +1,62 @@
1+# -*- coding: utf-8; mode: makefile-gmake -*-
2+
3+PYOBJECTS = searx
4+PY_SETUP_EXTRAS ?= \[test\]
5+
6+include utils/makefile.include
7+include utils/makefile.python
8+
9+all: clean install
10+
11+PHONY += help
12+help:
13+ @echo ' test - run developer tests'
14+ @echo ' run - run developer instance'
15+ @echo ' install - developer install (./local)'
16+ @echo ' uninstall - uninstall (./local)'
17+ @echo ''
18+ @$(MAKE) -s -f utils/makefile.include make-help
19+ @echo ''
20+ @$(MAKE) -s -f utils/makefile.python python-help
21+
22+PHONY += install
23+install: pyenvinstall
24+
25+PHONY += uninstall
26+uninstall: pyenvuninstall
27+
28+PHONY += clean
29+clean: pyclean
30+ $(call cmd,common_clean)
31+
32+PHONY += run
33+run: pyenvinstall
34+ $(Q) ( \
35+ sed -i -e "s/debug : False/debug : True/g" ./searx/settings.yml ; \
36+ sleep 2 ; \
37+ xdg-open http://127.0.0.1:8888/ ; \
38+ sleep 3 ; \
39+ sed -i -e "s/debug : True/debug : False/g" ./searx/settings.yml ; \
40+ ) &
41+ $(PY_ENV)/bin/python ./searx/webapp.py
42+
43+# test
44+# ----
45+
46+PHONY += test test.pylint test.pep8 test.unit test.robot
47+
48+# TODO: balance linting with pylint
49+test: test.pep8 test.unit test.robot
50+ - make pylint
51+
52+test.pep8: pyenvinstall
53+ $(PY_ENV_ACT); ./manage.sh pep8_check
54+
55+test.unit: pyenvinstall
56+ $(PY_ENV_ACT); ./manage.sh unit_tests
57+
58+test.robot: pyenvinstall
59+ $(PY_ENV_ACT); ./manage.sh install_geckodriver
60+ $(PY_ENV_ACT); ./manage.sh robot_tests
61+
62+.PHONY: $(PHONY)
searx/engines/google.py+7−14
@@ -107,13 +107,12 @@ images_path = '/images'
107107supported_languages_url = 'https://www.google.com/preferences?#languages'
108108
109109# specific xpath variables
110−results_xpath = '//div[@class="g"]'
111−url_xpath = './/h3/a/@href'
112−title_xpath = './/h3'
113−content_xpath = './/span[@class="st"]'
114−content_misc_xpath = './/div[@class="f slp"]'
115−suggestion_xpath = '//p[@class="_Bmc"]'
116−spelling_suggestion_xpath = '//a[@class="spell"]'
110+results_xpath = '//div[contains(@class, "ZINbbc")]'
111+url_xpath = './/div[@class="kCrYT"][1]/a/@href'
112+title_xpath = './/div[@class="kCrYT"][1]/a/div[1]'
113+content_xpath = './/div[@class="kCrYT"][2]//div[contains(@class, "BNeawe")]//div[contains(@class, "BNeawe")]'
114+suggestion_xpath = '//div[contains(@class, "ZINbbc")][last()]//div[@class="rVLSBd"]/a//div[contains(@class, "BNeawe")]'
115+spelling_suggestion_xpath = '//div[@id="scc"]//a'
117116
118117# map : detail location
119118map_address_xpath = './/div[@class="s"]//table//td[2]/span/text()'
@@ -199,10 +198,6 @@ def request(query, params):
199198 params['headers']['Accept-Language'] = language + ',' + language + '-' + country
200199 params['headers']['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
201200
202− # Force Safari 3.1 on Mac OS X (Leopard) user agent to avoid loading the new UI that Searx can't parse
203− params['headers']['User-Agent'] = ("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_4)"
204− "AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1")
205−
206201 params['google_hostname'] = google_hostname
207202
208203 return params
@@ -274,9 +269,7 @@ def response(resp):
274269 content = extract_text_from_dom(result, content_xpath)
275270 if content is None:
276271 continue
277− content_misc = extract_text_from_dom(result, content_misc_xpath)
278− if content_misc is not None:
279− content = content_misc + "<br />" + content
272+
280273 # append result
281274 results.append({'url': url,
282275 'title': title,
searx/templates/oscar/advanced.html+5−4
@@ -1,16 +1,17 @@
11<input type="checkbox" name="advanced_search" id="check-advanced" {% if advanced_search %} checked="checked"{% endif %}>
2−<label for="check-advanced">
2+<label for="check-advanced">{{- "" -}}
33 <span class="glyphicon glyphicon-cog"></span>
4− {{ _('Advanced settings') }}
4+ {{- _('Advanced settings') -}}
55</label>
66<div id="advanced-search-container">
77 {% include 'oscar/categories.html' %}
8+
89 <div class="row">
910 <div class="col-xs-6">
10− {% include 'oscar/time-range.html' %}
11+ {%- include 'oscar/time-range.html' -%}
1112 </div>
1213 <div class="col-xs-6">
13− {% include 'oscar/languages.html' %}
14+ {%- include 'oscar/languages.html' -%}
1415 </div>
1516 </div>
1617</div>
searx/templates/oscar/base.html+12−9
@@ -10,16 +10,17 @@
1010 <meta name="referrer" content="no-referrer">
1111 <meta name="viewport" content="width=device-width, initial-scale=1 , maximum-scale=1.0, user-scalable=1" />
1212 {% block meta %}{% endblock %}
13− <title>{% block title %}{% endblock %}{{ instance_name }}</title>
1413
14+ <title>{% block title %}{% endblock %}{{ instance_name }}</title>
1515 <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}" type="text/css" />
16− {% if preferences.get_value('oscar-style') %}
17− <link rel="stylesheet" href="{{ url_for('static', filename='css/'+preferences.get_value('oscar-style')+'.min.css') }}" type="text/css" />
18− {% else %}
19− <link rel="stylesheet" href="{{ url_for('static', filename='css/logicodev.min.css') }}" type="text/css" />
20− {% endif %}
16+ {% if preferences.get_value('oscar-style') -%}
17+ {{' '}}<link rel="stylesheet" href="{{ url_for('static', filename='css/'+preferences.get_value('oscar-style')+'.min.css') }}" type="text/css" />
18+ {%- else -%}
19+ {{' '}}<link rel="stylesheet" href="{{ url_for('static', filename='css/logicodev.min.css') }}" type="text/css" />
20+ {%- endif %}
21+
2122 <link rel="stylesheet" href="{{ url_for('static', filename='css/leaflet.min.css') }}" type="text/css" />
22− {% for css in styles %}
23+ {%- for css in styles %}
2324 <link rel="stylesheet" href="{{ url_for('static', filename=css) }}" type="text/css" />
2425 {% endfor %}
2526
@@ -48,6 +49,7 @@
4849</head>
4950<body>
5051 {% include 'oscar/navbar.html' %}
52+
5153 <div class="container">
5254 {% if errors %}
5355 <div class="alert alert-danger fade in" role="alert">
@@ -93,13 +95,14 @@
9395 </div>
9496 <script src="{{ url_for('static', filename='js/jquery-1.11.1.min.js') }}"></script>
9597 <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
96− {% if autocomplete %}<script src="{{ url_for('static', filename='js/typeahead.bundle.min.js') }}"></script>{% endif %}
98+ {% if autocomplete %} <script src="{{ url_for('static', filename='js/typeahead.bundle.min.js') }}"></script>{% endif %}
99+
97100 <script src="{{ url_for('static', filename='js/require-2.1.15.min.js') }}"></script>
98101 <script src="{{ url_for('static', filename='js/searx.min.js') }}"
99102 data-method="{{ method or 'POST' }}"
100103 data-autocompleter="{% if autocomplete %}true{% else %}false{% endif %}"></script>
101104 {% for script in scripts %}
102− <script src="{{ url_for('static', filename=script) }}"></script>
105+ {{""}}<script src="{{ url_for('static', filename=script) }}"></script>
103106 {% endfor %}
104107 <noscript>
105108 <style>
searx/templates/oscar/categories.html+9−9
@@ -1,13 +1,13 @@
11<div id="categories">
2−{% if rtl %}
3− {% for category in categories | reverse %}
4− <input class="hidden" type="checkbox" id="checkbox_{{ category|replace(' ', '_') }}" name="category_{{ category }}" {% if category in selected_categories %}checked="checked"{% endif %} />
2+{%- if rtl -%}
3+ {% for category in categories | reverse -%}
4+ <input class="hidden" type="checkbox" id="checkbox_{{ category|replace(' ', '_') }}" name="category_{{ category }}" {% if category in selected_categories %}checked="checked"{% endif %} />{{- '' -}}
55 <label for="checkbox_{{ category|replace(' ', '_') }}">{{ _(category) }}</label>
6− {% endfor %}
7−{% else %}
8− {% for category in categories %}
9− <input class="hidden" type="checkbox" id="checkbox_{{ category|replace(' ', '_') }}" name="category_{{ category }}" {% if category in selected_categories %}checked="checked"{% endif %} />
6+ {%- endfor %}
7+{%- else -%}
8+ {% for category in categories -%}
9+ <input class="hidden" type="checkbox" id="checkbox_{{ category|replace(' ', '_') }}" name="category_{{ category }}" {% if category in selected_categories %}checked="checked"{% endif %} />{{- '' -}}
1010 <label for="checkbox_{{ category|replace(' ', '_') }}">{{ _(category) }}</label>
11− {% endfor %}
12−{% endif %}
11+ {%- endfor %}
12+{%- endif -%}
1313</div>
searx/templates/oscar/infobox.html+17−16
@@ -1,34 +1,35 @@
11{% from 'oscar/macros.html' import result_link with context %}
22<div class="panel panel-default infobox">
3− <div class="panel-heading">
4− <h4 class="panel-title infobox_part"><bdi>{{ infobox.infobox }}</bdi></h4>
3+ <div class="panel-heading">{{- "" -}}
4+ <h4 class="panel-title infobox_part"><bdi>{{ infobox.infobox }}</bdi></h4>{{- "" -}}
55 </div>
66 <div class="panel-body">
77 {% if infobox.img_src %}<img class="img-responsive center-block infobox_part" src="{{ image_proxify(infobox.img_src) }}" alt="{{ infobox.infobox }}" />{% endif %}
8− {% if infobox.content %}<bdi><p class="infobox_part">{{ infobox.content }}</bdi></p>{% endif %}
98
10− {% if infobox.attributes %}
9+ {% if infobox.content %}<bdi><p class="infobox_part">{{ infobox.content }}</p></bdi>{% endif %}
10+
11+ {% if infobox.attributes -%}
1112 <table class="table table-striped infobox_part">
12− {% for attribute in infobox.attributes %}
13− <tr>
13+ {% for attribute in infobox.attributes -%}
14+ <tr>{{- "" -}}
1415 <td><bdi>{{ attribute.label }}</bdi></td>
15− {% if attribute.image %}
16+ {%- if attribute.image -%}
1617 <td><img class="img-responsive" src="{{ image_proxify(attribute.image.src) }}" alt="{{ attribute.image.alt }}" /></td>
17− {% else %}
18+ {%- else -%}
1819 <td><bdi>{{ attribute.value }}</bdi></td>
19− {% endif %}
20+ {%- endif -%}
2021 </tr>
21− {% endfor %}
22+ {% endfor -%}
2223 </table>
2324 {% endif %}
2425
25− {% if infobox.urls %}
26− <div class="infobox_part">
26+ {% if infobox.urls -%}
27+ <div class="infobox_part">{{- "\n" -}}
2728 <bdi>
28− {% for url in infobox.urls %}
29− <p class="btn btn-default btn-xs">{{ result_link(url.url, url.title) }}</a></p>
30− {% endfor %}
31− </bdi>
29+ {%- for url in infobox.urls -%}
30+ <p class="btn btn-default btn-xs">{{ result_link(url.url, url.title) }}</p>
31+ {% endfor -%}
32+ </bdi>{{- "" -}}
3233 </div>
3334 {% endif %}
3435 </div>
searx/templates/oscar/languages.html+7−7
@@ -1,12 +1,12 @@
1−{% if preferences %}
1+{% if preferences -%}
22<select class="custom-select form-control" name='language'>
3−{% else %}
3+{%- else -%}
44<select class="time_range custom-select form-control" id='language' name='language'>
5−{% endif %}
5+{%- endif -%}
66 <option value="all" {% if current_language == 'all' %}selected="selected"{% endif %}>{{ _('Default language') }}</option>
7− {% for lang_id,lang_name,country_name,english_name in language_codes | sort(attribute=1) %}
7+ {%- for lang_id,lang_name,country_name,english_name in language_codes | sort(attribute=1) -%}
88 <option value="{{ lang_id }}" {% if lang_id == current_language %}selected="selected"{% endif %}>
9− {{ lang_name }} {% if country_name %}({{ country_name }}) {% endif %}- {{ lang_id }}
9+ {{- lang_name }} {% if country_name %}({{ country_name }}) {% endif %}- {{ lang_id -}}
1010 </option>
11− {% endfor %}
12−</select>
11+ {%- endfor -%}
12+</select>
searx/templates/oscar/macros.html+23−23
@@ -26,38 +26,38 @@
2626
2727<!-- Draw result footer -->
2828{% macro result_footer(result) -%}
29− <div class="clearfix"></div>
29+ <div class="clearfix"></div>{{- "" -}}
3030 <div class="pull-right">
31− {% for engine in result.engines %}
32− <span class="label label-default">{{ engine }}</span>
33− {% endfor %}
34− {% if result.url %}
35− <small>{{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info") }}</small>
36− {% endif %}
37− {% if proxify %}
38− <small>{{ result_link(proxify(result.url), icon('sort') + _('proxied'), "text-info") }}</small>
39− {% endif %}
40−</div>
41−{% if result.pretty_url %}
42−<div class="external-link">{{ result.pretty_url }}</div>
43−{% endif %}
31+ {%- for engine in result.engines -%}
32+ <span class="label label-default">{{ engine }}</span>
33+ {%- endfor -%}
34+ {%- if result.url -%}
35+ <small>{{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info") }}</small>
36+ {%- endif -%}
37+ {%- if proxify -%}
38+ <small>{{ result_link(proxify(result.url), icon('sort') + _('proxied'), "text-info") }}</small>
39+ {%- endif -%}
40+ </div>
41+ {%- if result.pretty_url -%}
42+ <div class="external-link">{{ result.pretty_url }}</div>
43+ {%- endif -%}
4444{%- endmacro %}
4545
4646<!-- Draw result footer -->
4747{% macro result_footer_rtl(result) -%}
48− <div class="clearfix"></div>
49− {% for engine in result.engines %}
48+ <div class="clearfix"></div>{{- "" -}}
49+ {% for engine in result.engines -%}
5050 <span class="label label-default">{{ engine }}</span>
51− {% endfor %}
52− {% if result.url %}
51+ {%- endfor %}
52+ {%- if result.url -%}
5353 <small>{{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info") }}</small>
54− {% endif %}
55− {% if proxify %}
54+ {%- endif -%}
55+ {% if proxify -%}
5656 <small>{{ result_link(proxify(result.url), icon('sort') + _('proxied'), "text-info") }}</small>
57− {% endif %}
58− {% if result.pretty_url %}
57+ {%- endif %}
58+ {%- if result.pretty_url -%}
5959 <div class="external-link">{{ result.pretty_url }}</div>
60− {% endif %}
60+ {%- endif %}
6161{%- endmacro %}
6262
6363{% macro preferences_item_header(info, label, rtl) -%}
searx/templates/oscar/navbar.html+8−8
@@ -1,9 +1,9 @@
1−<div class="searx-navbar">
2− <span class="instance {% if rtl %}pull-right{% else %}pull-left{% endif%}">
3− <a href="{{ url_for('index') }}">{{ instance_name }}</a>
4− </span>
5− <span class="{% if rtl %}pull-left{% else %}pull-right{% endif %}">
6− <a href="{{ url_for('about') }}">{{ _('about') }}</a>
7− <a href="{{ url_for('preferences') }}">{{ _('preferences') }}</a>
8− </span>
1+<div class="searx-navbar">{{- "" -}}
2+ <span class="instance {% if rtl %}pull-right{% else %}pull-left{% endif%}">{{- "" -}}
3+ <a href="{{ url_for('index') }}">{{ instance_name }}</a>{{- "" -}}
4+ </span>{{- "" -}}
5+ <span class="{% if rtl %}pull-left{% else %}pull-right{% endif %}">{{- "" -}}
6+ <a href="{{ url_for('about') }}">{{ _('about') }}</a>{{- "" -}}
7+ <a href="{{ url_for('preferences') }}">{{ _('preferences') }}</a>{{- "" -}}
8+ </span>{{- "" -}}
99</div>
searx/templates/oscar/result_templates/default.html+14−14
@@ -1,31 +1,31 @@
11{% from 'oscar/macros.html' import result_header, result_sub_header, result_footer, result_footer_rtl, icon with context %}
22
3−{{ result_header(result, favicons) }}
4−{{ result_sub_header(result) }}
3+{{- result_header(result, favicons) -}}
4+{{- result_sub_header(result) -}}
55
6−{% if result.embedded %}
6+{%- if result.embedded -%}
77 <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer media-loader disabled_if_nojs" data-toggle="collapse" data-target="#result-media-{{ index }}" data-btn-text-collapsed="{{ _('show media') }}" data-btn-text-not-collapsed="{{ _('hide media') }}">{{ icon('music') }} {{ _('show media') }}</a></small>
8−{% endif %}
8+{%- endif -%}
99
10−{% if result.embedded %}
10+{%- if result.embedded -%}
1111<div id="result-media-{{ index }}" class="collapse">
1212 {{ result.embedded|safe }}
1313</div>
14−{% endif %}
14+{%- endif -%}
1515
16−{% if result.img_src %}
16+{%- if result.img_src -%}
1717<div class="container-fluid">
1818 <div class="row">
1919<img src="{{ image_proxify(result.img_src) }}" alt="{{ result.title|striptags }}" title="{{ result.title|striptags }}" style="width: auto; max-height: 60px; min-height: 60px;" class="col-xs-2 col-sm-4 col-md-4 result-content">
20−{% if result.content %}<p class="result-content col-xs-8 col-sm-8 col-md-8">{{ result.content|safe }}</p>{% endif %}
20+{% if result.content %}<p class="result-content col-xs-8 col-sm-8 col-md-8">{{ result.content|safe }}</p>{% endif -%}
2121 </div>
2222</div>
23−{% else %}
24−{% if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif %}
25−{% endif %}
23+{%- else -%}
24+{%- if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif -%}
25+{%- endif -%}
2626
27−{% if rtl %}
27+{%- if rtl -%}
2828{{ result_footer_rtl(result) }}
29−{% else %}
29+{%- else -%}
3030{{ result_footer(result) }}
31−{% endif %}
31+{%- endif -%}
searx/templates/oscar/result_templates/images.html+33−46
@@ -1,49 +1,36 @@
1−{% from 'oscar/macros.html' import draw_favicon %}
1+{%- from 'oscar/macros.html' import draw_favicon -%}
22
3−<a href="{{ result.img_src }}" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} data-toggle="modal" data-target="#modal-{{ index }}-{{pageno}}">
4− <img src="{% if result.thumbnail_src %}{{ image_proxify(result.thumbnail_src) }}{% else %}{{ image_proxify(result.img_src) }}{% endif %}" alt="{{ result.title|striptags }}" title="{{ result.title|striptags }}" class="img-thumbnail">
3+<a href="{{ result.img_src }}" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} data-toggle="modal" data-target="#modal-{{ index }}-{{pageno}}">{{- "" -}}
4+ <img src="{% if result.thumbnail_src %}{{ image_proxify(result.thumbnail_src) }}{% else %}{{ image_proxify(result.img_src) }}{% endif %}" alt="{{ result.title|striptags }}" title="{{ result.title|striptags }}" class="img-thumbnail">{{- "" -}}
55</a>
6−
7−<div class="modal fade" id="modal-{{ index }}-{{ pageno }}" tabindex="-1" role="dialog" aria-hidden="true">
8− <div class="modal-dialog">
9− <div class="modal-wrapper">
10− <div class="modal-header">
11− <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
12− <h4 class="modal-title">{% if result.engine~".png" in favicons %}{{ draw_favicon(result.engine) }} {% endif %}{{ result.title|striptags }}</h4>
13− </div>
14− <div class="modal-body">
6+<div class="modal fade" id="modal-{{ index }}-{{ pageno }}" tabindex="-1" role="dialog" aria-hidden="true">{{- "" -}}
7+ <div class="modal-dialog">{{- "" -}}
8+ <div class="modal-wrapper">{{- "" -}}
9+ <div class="modal-header">{{- "" -}}
10+ <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>{{- "" -}}
11+ <h4 class="modal-title">{% if result.engine~".png" in favicons %}{{ draw_favicon(result.engine) }} {% endif %}{{ result.title|striptags }}</h4>{{- "" -}}
12+ </div>{{- "" -}}
13+ <div class="modal-body">{{- "" -}}
1514 <img class="img-responsive center-block" src="{% if result.thumbnail_src %}{{ image_proxify(result.thumbnail_src) }}{% else %}{{ image_proxify(result.img_src) }}{% endif %}" alt="{{ result.title|striptags }}">
16− {% if result.author %}<span class="photo-author">{{ result.author }}</span><br />{% endif %}
17− {% if result.content %}
18− <p class="result-content">
19− {{ result.content|striptags }}
20− </p>
21− {% endif %}
22− {% if result.img_format %}
23− <p class="result-format">
24− {{ result.img_format }}
25− </p>
26− {% endif %}
27− {% if result.source %}
28− <p class="result-source">
29− {{ result.source }}
30− </p>
31− {% endif %}
32− </div>
33− <div class="modal-footer">
34− <div class="clearfix"></div>
35− <span class="label label-default pull-right">{{ result.engine }}</span>
36− <p class="text-muted pull-left">{{ result.pretty_url }}</p>
37− <div class="clearfix"></div>
38− <div class="row">
39− <div class="col-md-6">
40− <a href="{{ result.img_src }}" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} class="btn btn-default">{{ _('Get image') }}</a>
41− </div>
42− <div class="col-md-6">
43− <a href="{{ result.url }}" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} class="btn btn-default">{{ _('View source') }}</a>
44− </div>
45− </div>
46− </div>
47− </div>
48− </div>
49−</div>
15+ {%- if result.author %}<span class="photo-author">{{ result.author }}</span><br />{% endif -%}
16+ {%- if result.content %}<p class="result-content">{{ result.content|striptags }}</p>{% endif -%}
17+ {%- if result.img_format %}<p class="result-format">{{ result.img_format }}</p>{% endif -%}
18+ {%- if result.source %}<p class="result-source">{{ result.source }}</p>{% endif -%}
19+ </div>{{- "" -}}
20+ <div class="modal-footer">{{- "" -}}
21+ <div class="clearfix"></div>{{- "" -}}
22+ <span class="label label-default pull-right">{{ result.engine }}</span>{{- "" -}}
23+ <p class="text-muted pull-left">{{ result.pretty_url }}</p>{{- "" -}}
24+ <div class="clearfix"></div>{{- "" -}}
25+ <div class="row">{{- "" -}}
26+ <div class="col-md-6">{{- "" -}}
27+ <a href="{{ result.img_src }}" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} class="btn btn-default">{{ _('Get image') }}</a>{{- "" -}}
28+ </div>{{- "" -}}
29+ <div class="col-md-6">{{- "" -}}
30+ <a href="{{ result.url }}" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} class="btn btn-default">{{ _('View source') }}</a>{{- "" -}}
31+ </div>{{- "" -}}
32+ </div>{{- "" -}}
33+ </div>{{- "" -}}
34+ </div>{{- "" -}}
35+ </div>{{- "" -}}
36+</div>{{- "" -}}
searx/templates/oscar/results.html+62−62
@@ -1,89 +1,90 @@
11{% extends "oscar/base.html" %}
22{% macro search_form_attrs(pageno) -%}
3− {% for category in selected_categories %}<input type="hidden" name="category_{{ category }}" value="1"/>{% endfor %}
4− <input type="hidden" name="q" value="{{ q|e }}" />
5− <input type="hidden" name="pageno" value="{{ pageno }}" />
6− <input type="hidden" name="time_range" value="{{ time_range }}" />
7− <input type="hidden" name="language" value="{{ current_language }}" />
8− {% if timeout_limit %}<input type="hidden" name="timeout_limit" value="{{ timeout_limit|e }}" />{% endif %}
3+ {%- for category in selected_categories -%}<input type="hidden" name="category_{{ category }}" value="1"/>{%- endfor -%}
4+ <input type="hidden" name="q" value="{{ q|e }}" />{{- "" -}}
5+ <input type="hidden" name="pageno" value="{{ pageno }}" />{{- "" -}}
6+ <input type="hidden" name="time_range" value="{{ time_range }}" />{{- "" -}}
7+ <input type="hidden" name="language" value="{{ current_language }}" />{{- "" -}}
8+ {% if timeout_limit %}<input type="hidden" name="timeout_limit" value="{{ timeout_limit|e }}" />{% endif -%}
99{%- endmacro %}
1010{%- macro search_url() %}{{ base_url }}?q={{ q|urlencode }}{% if selected_categories %}&amp;categories={{ selected_categories|join(",") | replace(' ','+') }}{% endif %}{% if pageno > 1 %}&amp;pageno={{ pageno }}{% endif %}{% if time_range %}&amp;time_range={{ time_range }}{% endif %}{% if current_language != 'all' %}&amp;language={{ current_language }}{% endif %}{% endmacro -%}
1111
1212{% block title %}{{ q|e }} - {% endblock %}
13−{% block meta %}<link rel="alternate" type="application/rss+xml" title="Searx search: {{ q|e }}" href="{{ search_url() }}&amp;format=rss">{% endblock %}
13+{% block meta %}{{" "}}<link rel="alternate" type="application/rss+xml" title="Searx search: {{ q|e }}" href="{{ search_url() }}&amp;format=rss">{% endblock %}
1414{% block content %}
1515 {% include 'oscar/search.html' %}
16+
1617 <div class="row">
1718 <div class="col-sm-8" id="main_results">
1819 <h1 class="sr-only">{{ _('Search results') }}</h1>
1920
20− {% if corrections %}
21+ {% if corrections -%}
2122 <div class="result">
2223 <span class="result_header text-muted form-inline pull-left suggestion_item">{{ _('Try searching for:') }}</span>
23− {% for correction in corrections %}
24− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" role="navigation" class="form-inline pull-left suggestion_item">
25− <input type="hidden" name="q" value="{{ correction.url }}">
26− <button type="submit" class="btn btn-default btn-xs">{{ correction.title }}</button>
24+ {% for correction in corrections -%}
25+ <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" role="navigation" class="form-inline pull-left suggestion_item">{{- "" -}}
26+ <input type="hidden" name="q" value="{{ correction.url }}">{{- "" -}}
27+ <button type="submit" class="btn btn-default btn-xs">{{ correction.title }}</button>{{- "" -}}
2728 </form>
2829 {% endfor %}
2930 </div>
30− {% endif %}
31+ {%- endif %}
3132
32− {% if answers %}
33− {% for answer in answers %}
33+ {% if answers -%}
34+ {%- for answer in answers %}
3435 <div class="result well">
3536 <span>{{ answer }}</span>
3637 </div>
37− {% endfor %}
38− {% endif %}
38+ {%- endfor %}
39+ {%- endif %}
3940
40− {% for result in results %}
41+ {% for result in results -%}
4142 <div class="result {% if result['template'] %}result-{{ result.template|replace('.html', '') }}{% else %}result-default{% endif %}">
42− {% set index = loop.index %}
43− {% if result.template %}
43+ {%- set index = loop.index -%}
44+ {%- if result.template -%}
4445 {% include get_result_template('oscar', result['template']) %}
45− {% else %}
46+ {%- else -%}
4647 {% include 'oscar/result_templates/default.html' %}
47− {% endif %}
48+ {%- endif -%}
4849 </div>
4950 {% endfor %}
5051
51− {% if not results and not answers %}
52+ {% if not results and not answers -%}
5253 {% include 'oscar/messages/no_results.html' %}
5354 {% endif %}
5455
5556 <div class="clearfix"></div>
5657
57− {% if paging %}
58+ {% if paging -%}
5859 {% if rtl %}
5960 <div id="pagination">
60− <div class="pull-left">
61+ <div class="pull-left">{{- "" -}}
6162 <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" class="pull-left">
62− {{ search_form_attrs(pageno+1) }}
63− <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-backward"></span> {{ _('next page') }}</button>
64− </form>
63+ {{- search_form_attrs(pageno+1) -}}
64+ <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-backward"></span> {{ _('next page') }}</button>{{- "" -}}
65+ </form>{{- "" -}}
6566 </div>
66− <div class="pull-right">
67+ <div class="pull-right">{{- "" -}}
6768 <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" class="pull-left">
68− {{ search_form_attrs(pageno-1) }}
69− <button type="submit" class="btn btn-default" {% if pageno == 1 %}disabled{% endif %}><span class="glyphicon glyphicon-forward"></span> {{ _('previous page') }}</button>
70− </form>
69+ {{- search_form_attrs(pageno-1) -}}
70+ <button type="submit" class="btn btn-default" {% if pageno == 1 %}disabled{% endif %}><span class="glyphicon glyphicon-forward"></span> {{ _('previous page') }}</button>{{- "" -}}
71+ </form>{{- "" -}}
7172 </div>
7273 </div><!-- /#pagination -->
7374 <div class="clearfix"></div>
7475 {% else %}
7576 <div id="pagination">
76− <div class="pull-left">
77+ <div class="pull-left">{{- "" -}}
7778 <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" class="pull-left">
78− {{ search_form_attrs(pageno-1) }}
79− <button type="submit" class="btn btn-default" {% if pageno == 1 %}disabled{% endif %}><span class="glyphicon glyphicon-backward"></span> {{ _('previous page') }}</button>
80− </form>
79+ {{- search_form_attrs(pageno-1) -}}
80+ <button type="submit" class="btn btn-default" {% if pageno == 1 %}disabled{% endif %}><span class="glyphicon glyphicon-backward"></span> {{ _('previous page') }}</button>{{- "" -}}
81+ </form>{{- "" -}}
8182 </div>
82− <div class="pull-right">
83+ <div class="pull-right">{{- "" -}}
8384 <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" class="pull-left">
84− {{ search_form_attrs(pageno+1) }}
85− <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-forward"></span> {{ _('next page') }}</button>
86− </form>
85+ {{- search_form_attrs(pageno+1) -}}
86+ <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-forward"></span> {{ _('next page') }}</button>{{- "" -}}
87+ </form>{{- "" -}}
8788 </div>
8889 </div><!-- /#pagination -->
8990 <div class="clearfix"></div>
@@ -92,24 +93,24 @@
9293 </div><!-- /#main_results -->
9394
9495 <div class="col-sm-4" id="sidebar_results">
95− {% if number_of_results != '0' %}
96+ {% if number_of_results != '0' -%}
9697 <p><small>{{ _('Number of results') }}: {{ number_of_results }}</small></p>
97− {% endif %}
98+ {%- endif %}
9899
99− {% if unresponsive_engines and results|length >= 1 %}
100+ {% if unresponsive_engines and results|length >= 1 -%}
100101 <div class="alert alert-danger fade in" role="alert">
101102 <p>{{ _('Engines cannot retrieve results') }}:</p>
102− {% for engine_name, error_type in unresponsive_engines %}
103− {{ engine_name }} ({{ error_type }}){% if not loop.last %}, {% endif %}
104− {% endfor %}
103+ {%- for engine_name, error_type in unresponsive_engines -%}AAAA
104+ {{- engine_name }} ({{ error_type }}){% if not loop.last %}, {% endif %}{{- "" -}}
105+ {%- endfor -%}
105106 </div>
106− {% endif %}
107+ {%- endif %}
107108
108− {% if infoboxes %}
109+ {% if infoboxes -%}
109110 {% for infobox in infoboxes %}
110− {% include 'oscar/infobox.html' %}
111+ {% include 'oscar/infobox.html' %}{{- "\n\n" -}}
111112 {% endfor %}
112− {% endif %}
113+ {%- endif %}
113114
114115 {% if suggestions %}
115116 <div class="panel panel-default">
@@ -125,27 +126,26 @@
125126 {% endfor %}
126127 </div>
127128 </div>
128− {% endif %}
129+ {%- endif %}
129130
130131 <div class="panel panel-default">
131− <div class="panel-heading">
132− <h4 class="panel-title">{{ _('Links') }}</h4>
132+ <div class="panel-heading">{{- "" -}}
133+ <h4 class="panel-title">{{ _('Links') }}</h4>{{- "" -}}
133134 </div>
134135 <div class="panel-body">
135− <form role="form">
136− <div class="form-group">
137− <label for="search_url">{{ _('Search URL') }}</label>
138− <input id="search_url" type="url" class="form-control select-all-on-click cursor-text" name="search_url" value="{{ search_url() }}" readonly>
139− </div>
136+ <form role="form">{{- "" -}}
137+ <div class="form-group">{{- "" -}}
138+ <label for="search_url">{{ _('Search URL') }}</label>{{- "" -}}
139+ <input id="search_url" type="url" class="form-control select-all-on-click cursor-text" name="search_url" value="{{ search_url() }}" readonly>{{- "" -}}
140+ </div>{{- "" -}}
140141 </form>
141−
142142 <label>{{ _('Download results') }}</label>
143143 <div class="clearfix"></div>
144144 {% for output_type in ('csv', 'json', 'rss') %}
145145 <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" class="form-inline pull-{% if rtl %}right{% else %}left{% endif %} result_download">
146− {{ search_form_attrs(pageno) }}
147− <input type="hidden" name="format" value="{{ output_type }}">
148− <button type="submit" class="btn btn-default">{{ output_type }}</button>
146+ {{- search_form_attrs(pageno) -}}
147+ <input type="hidden" name="format" value="{{ output_type }}">{{- "" -}}
148+ <button type="submit" class="btn btn-default">{{ output_type }}</button>{{- "" -}}
149149 </form>
150150 {% endfor %}
151151 <div class="clearfix"></div>
searx/templates/oscar/search.html+3−3
@@ -10,15 +10,15 @@
1010 </div>
1111 </div>
1212 <div class="col-xs-6 col-md-2 search-margin">
13− {% include 'oscar/time-range.html' %}
13+ {%- include 'oscar/time-range.html' -%}
1414 </div>
1515 <div class="col-xs-6 col-md-2 search-margin">
16− {% include 'oscar/languages.html' %}
16+ {%- include 'oscar/languages.html' -%}
1717 </div>
1818 </div>
1919 <div class="row">
2020 <div class="col-sm-12">
21− {% include 'oscar/categories.html' %}
21+ {%- include 'oscar/categories.html' -%}
2222 </div>
2323 </div>
2424</form><!-- / #search_form_full -->
searx/templates/oscar/time-range.html+11−11
@@ -1,17 +1,17 @@
1−<select name="time_range" id="time-range" class="custom-select form-control">
1+<select name="time_range" id="time-range" class="custom-select form-control">{{- "" -}}
22 <option id="time-range-anytime" value="" {{ "selected" if time_range=="" or not time_range else ""}}>
3− {{ _('Anytime') }}
4− </option>
3+ {{- _('Anytime') -}}
4+ </option>{{- "" -}}
55 <option id="time-range-day" value="day" {{ "selected" if time_range=="day" else ""}}>
6− {{ _('Last day') }}
7− </option>
6+ {{- _('Last day') -}}
7+ </option>{{- "" -}}
88 <option id="time-range-week" value="week" {{ "selected" if time_range=="week" else ""}}>
9− {{ _('Last week') }}
10− </option>
9+ {{- _('Last week') -}}
10+ </option>{{- "" -}}
1111 <option id="time-range-month" value="month" {{ "selected" if time_range=="month" else ""}}>
12− {{ _('Last month') }}
13− </option>
12+ {{- _('Last month') -}}
13+ </option>{{- "" -}}
1414 <option id="time-range-year" value="year" {{ "selected" if time_range=="year" else ""}}>
15− {{ _('Last year') }}
16− </option>
15+ {{- _('Last year') -}}
16+ </option>{{- "" -}}
1717</select>
setup.py+6−6
@@ -11,14 +11,14 @@ import sys
1111sys.path.insert(0, './searx')
1212from version import VERSION_STRING
1313
14+with open('README.rst') as f:
15+ long_description = f.read()
1416
15−def read(*rnames):
16− return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
17+with open('requirements.txt') as f:
18+ requirements = [ l.strip() for l in f.readlines()]
1719
18−
19−long_description = read('README.rst')
20−requirements = map(str.strip, open('requirements.txt').readlines())
21−dev_requirements = map(str.strip, open('requirements-dev.txt').readlines())
20+with open('requirements-dev.txt') as f:
21+ dev_requirements = [ l.strip() for l in f.readlines()]
2222
2323setup(
2424 name='searx',
tests/unit/engines/test_google.py+37−80
@@ -58,93 +58,50 @@ class TestGoogleEngine(SearxTestCase):
5858 self.assertEqual(google.response(response), [])
5959
6060 html = """
61− <div class="g">
62− <h3 class="r">
63− <a href="http://this.should.be.the.link/">
64− <b>This</b> is <b>the</b> title
65− </a>
66− </h3>
67− <div class="s">
68− <div class="kv" style="margin-bottom:2px">
69− <cite>
70− <b>test</b>.psychologies.com/
71− </cite>
72− <div class="_nBb"><U+200E>
73− <div style="display:inline" onclick="google.sham(this);" aria-expanded="false"
74− aria-haspopup="true" tabindex="0" data-ved="0CBUQ7B0wAA">
75− <span class="_O0">
76− </span>
61+ <div class="ZINbbc xpd O9g5cc uUPGi">
62+ <div>
63+ <div class="kCrYT">
64+ <a href="/url?q=http://this.should.be.the.link/">
65+ <div class="BNeawe">
66+ <b>This</b> is <b>the</b> title
7767 </div>
78− <div style="display:none" class="am-dropdown-menu" role="menu" tabindex="-1">
79− <ul>
80− <li class="_Ykb">
81− <a class="_Zkb" href="http://www.google.fr/url?url=http://webcache.googleusercontent
82− .com/search%3Fcache:R1Z_4pGXjuIJ:http://test.psychologies.com/">
83− En cache
84− </a>
85− </li>
86− <li class="_Ykb">
87− <a class="_Zkb" href="/search?safe=off&amp;q=related:test.psy.com/">
88− Pages similaires
89− </a>
90− </li>
91− </ul>
68+ <div class="BNeawe">
69+ http://website
70+ </div>
71+ </a>
72+ </div>
73+ <div class="kCrYT">
74+ <div>
75+ <div class="BNeawe">
76+ <div>
77+ <div class="BNeawe">
78+ This should be the content.
79+ </div>
80+ </div>
9281 </div>
9382 </div>
9483 </div>
95− <span class="st">
96− This should be the content.
97− </span>
98− <br>
99− <div class="osl"><U+200E>
100− <a href="http://www.google.fr/url?url=http://test.psychologies.com/tests/">
101− Test Personnalité
102− </a> - <U+200E>
103− <a href="http://www.google.fr/url?url=http://test.psychologies.com/test/">
104− Tests - Moi
105− </a> - <U+200E>
106− <a href="http://www.google.fr/url?url=http://test.psychologies.com/test/tests-couple">
107− Test Couple
108− </a>
109− - <U+200E>
110− <a href="http://www.google.fr/url?url=http://test.psychologies.com/tests/tests-amour">
111− Test Amour
84+ </div>
85+ </p>
86+ <div class="ZINbbc xpd O9g5cc uUPGi">
87+ <div>
88+ <div class="kCrYT">
89+ <span>
90+ <div class="BNeawe">
91+ Related searches
92+ </div>
93+ </span>
94+ </div>
95+ <div class="rVLSBd">
96+ <a>
97+ <div>
98+ <div class="BNeawe">
99+ suggestion title
100+ </div>
101+ </div>
112102 </a>
113103 </div>
114104 </div>
115− </div>
116− <div class="g">
117− <h3 class="r">
118− <a href="http://www.google.com/images?q=toto">
119− <b>This</b>
120− </a>
121− </h3>
122− </div>
123− <div class="g">
124− <h3 class="r">
125− <a href="http://www.google.com/search?q=toto">
126− <b>This</b> is
127− </a>
128− </h3>
129− </div>
130− <div class="g">
131− <h3 class="r">
132− <a href="€">
133− <b>This</b> is <b>the</b>
134− </a>
135− </h3>
136− </div>
137− <div class="g">
138− <h3 class="r">
139− <a href="/url?q=url">
140− <b>This</b> is <b>the</b>
141− </a>
142− </h3>
143− </div>
144− <p class="_Bmc" style="margin:3px 8px">
145− <a href="/search?num=20&amp;safe=off&amp;q=t&amp;revid=1754833769&amp;sa=X&amp;ei=-&amp;ved=">
146− suggestion <b>title</b>
147− </a>
148105 </p>
149106 """
150107 response = self.mock_response(html)
utils/makefile.includenew file+128
@@ -0,0 +1,128 @@
1+# -*- coding: utf-8; mode: makefile-gmake -*-
2+
3+make-help:
4+ @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
5+ @echo ' make V=2 [targets] 2 => give reason for rebuild of target'
6+
7+quiet_cmd_common_clean = CLEAN $@
8+ cmd_common_clean = \
9+ rm -rf tests/build ;\
10+ find . -name '*.orig' -exec rm -f {} + ;\
11+ find . -name '*.rej' -exec rm -f {} + ;\
12+ find . -name '*~' -exec rm -f {} + ;\
13+ find . -name '*.bak' -exec rm -f {} + ;\
14+
15+FMT = cat
16+ifeq ($(shell which fmt >/dev/null 2>&1; echo $$?), 0)
17+FMT = fmt
18+endif
19+
20+# MS-Windows
21+#
22+# For a minimal *make-environment*, I'am using the gnu-tools from:
23+#
24+# - GNU MCU Eclipse Windows Build Tools, which brings 'make', 'rm' etc.
25+# https://github.com/gnu-mcu-eclipse/windows-build-tools/releases
26+#
27+# - git for Windows, which brings 'find', 'grep' etc.
28+# https://git-scm.com/download/win
29+
30+
31+# normpath
32+#
33+# System-dependent normalization of the path name
34+#
35+# usage: $(call normpath,/path/to/file)
36+
37+normpath = $1
38+ifeq ($(OS),Windows_NT)
39+ normpath = $(subst /,\,$1)
40+endif
41+
42+
43+# stolen from linux/Makefile
44+#
45+
46+ifeq ("$(origin V)", "command line")
47+ KBUILD_VERBOSE = $(V)
48+endif
49+ifndef KBUILD_VERBOSE
50+ KBUILD_VERBOSE = 0
51+endif
52+
53+ifeq ($(KBUILD_VERBOSE),1)
54+ quiet =
55+ Q =
56+else
57+ quiet=quiet_
58+ Q = @
59+endif
60+
61+# stolen from linux/scripts/Kbuild.include
62+#
63+
64+# Convenient variables
65+comma := ,
66+quote := "
67+#" this comment is only for emacs highlighting
68+squote := '
69+#' this comment is only for emacs highlighting
70+empty :=
71+space := $(empty) $(empty)
72+space_escape := _-_SPACE_-_
73+
74+# Find any prerequisites that is newer than target or that does not exist.
75+# PHONY targets skipped in both cases.
76+any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
77+#
78+###
79+# why - tell why a a target got build
80+# enabled by make V=2
81+# Output (listed in the order they are checked):
82+# (1) - due to target is PHONY
83+# (2) - due to target missing
84+# (3) - due to: file1.h file2.h
85+# (4) - due to command line change
86+# (5) - due to missing .cmd file
87+# (6) - due to target not in $(targets)
88+# (1) PHONY targets are always build
89+# (2) No target, so we better build it
90+# (3) Prerequisite is newer than target
91+# (4) The command line stored in the file named dir/.target.cmd
92+# differed from actual command line. This happens when compiler
93+# options changes
94+# (5) No dir/.target.cmd file (used to store command line)
95+# (6) No dir/.target.cmd file and target not listed in $(targets)
96+# This is a good hint that there is a bug in the kbuild file
97+ifeq ($(KBUILD_VERBOSE),2)
98+why = \
99+ $(if $(filter $@, $(PHONY)),- due to target is PHONY, \
100+ $(if $(wildcard $@), \
101+ $(if $(strip $(any-prereq)),- due to: $(any-prereq), \
102+ $(if $(arg-check), \
103+ $(if $(cmd_$@),- due to command line change, \
104+ $(if $(filter $@, $(targets)), \
105+ - due to missing .cmd file, \
106+ - due to $(notdir $@) not in $$(targets) \
107+ ) \
108+ ) \
109+ ) \
110+ ), \
111+ - due to target missing \
112+ ) \
113+ )
114+
115+echo-why = $(call escsq, $(strip $(why)))
116+endif
117+#
118+###
119+# Escape single quote for use in echo statements
120+escsq = $(subst $(squote),'\$(squote)',$1)
121+#
122+# echo command.
123+# Short version is used, if $(quiet) equals `quiet_', otherwise full one.
124+echo-cmd = $(if $($(quiet)cmd_$(1)),echo '$(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
125+#
126+# printing commands
127+cmd = @$(echo-cmd) $(cmd_$(1))
128+
utils/makefile.pythonnew file+290
@@ -0,0 +1,290 @@
1+# -*- coding: utf-8; mode: makefile-gmake -*-
2+
3+# list of python packages (folders) or modules (files) of this build
4+PYOBJECTS ?=
5+
6+SITE_PYTHON ?=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))site-python
7+export PYTHONPATH := $(SITE_PYTHON):$$PYTHONPATH
8+
9+# folder where the python distribution takes place
10+PYDIST ?= ./py_dist
11+# folder where the python intermediate build files take place
12+PYBUILD ?= ./py_build
13+# python version to use
14+PY ?=3
15+PYTHON ?= python$(PY)
16+PIP ?= pip$(PY)
17+PIP_INST ?= --user
18+
19+# https://www.python.org/dev/peps/pep-0508/#extras
20+#PY_SETUP_EXTRAS ?= \[develop,test\]
21+PY_SETUP_EXTRAS ?=
22+
23+PYDEBUG ?= --pdb
24+PYLINT_RC ?= .pylintrc
25+
26+TEST_FOLDER ?= ./tests
27+TEST ?= .
28+
29+VTENV_OPTS = "--no-site-packages"
30+PY_ENV = ./local/py$(PY)
31+PY_ENV_BIN = $(PY_ENV)/bin
32+PY_ENV_ACT = . $(PY_ENV_BIN)/activate
33+
34+ifeq ($(OS),Windows_NT)
35+ PYTHON = python
36+ PY_ENV_BIN = $(PY_ENV)/Scripts
37+ PY_ENV_ACT = $(PY_ENV_BIN)/activate
38+endif
39+
40+ifeq ($(PYTHON),python)
41+ VIRTUALENV = virtualenv
42+else
43+ VIRTUALENV = virtualenv --python=$(PYTHON)
44+endif
45+
46+ifeq ($(KBUILD_VERBOSE),1)
47+ PIP_VERBOSE =
48+ VIRTUALENV_VERBOSE =
49+else
50+ PIP_VERBOSE = "-q"
51+ VIRTUALENV_VERBOSE = "-q"
52+endif
53+
54+python-help::
55+ @echo 'makefile.python:'
56+ @echo ' pyenv | pyenv[un]install'
57+ @echo ' build $(PY_ENV) & [un]install python objects'
58+ @echo ' targts using pyenv $(PY_ENV):'
59+ @echo ' pylint - run pylint *linting*'
60+ @echo ' pytest - run *tox* test on python objects'
61+ @echo ' pydebug - run tests within a PDB debug session'
62+ @echo ' pybuild - build python packages'
63+ @echo ' pyclean - clean intermediate python objects'
64+ @echo ' targets using system users environment:'
65+ @echo ' py[un]install - [un]install python objects in editable mode'
66+ @echo ' upload-pypi - upload $(PYDIST)/* files to PyPi'
67+ @echo 'options:'
68+ @echo ' make PY=2 [targets] => to eval targets with python 2 ($(PY))'
69+ @echo ' make PIP_INST= => to set/unset pip install options ($(PIP_INST))'
70+ @echo ' make TEST=. => choose test from $(TEST_FOLDER) (default "." runs all)'
71+ @echo ' make DEBUG= => target "debug": do not invoke PDB on errors'
72+ @echo ' make PY_SETUP_EXTRAS => also install extras_require from setup.py \[develop,test\]'
73+ @echo ' when using target "pydebug", set breakpoints within py-source by adding::'
74+ @echo ' DEBUG()'
75+
76+# ------------------------------------------------------------------------------
77+# OS requirements
78+# ------------------------------------------------------------------------------
79+
80+PHONY += msg-python-exe python-exe
81+msg-python-exe:
82+ @echo "\n $(PYTHON) is required\n\n\
83+ Make sure you have $(PYTHON) installed, grab it from\n\
84+ https://www.python.org or install it from your package\n\
85+ manager. On debian based OS these requirements are\n\
86+ installed by::\n\n\
87+ sudo -H apt-get install $(PYTHON)\n" | $(FMT)
88+
89+ifeq ($(shell which $(PYTHON) >/dev/null 2>&1; echo $$?), 1)
90+python-exe: msg-python-exe
91+ $(error The '$(PYTHON)' command was not found)
92+else
93+python-exe:
94+ @:
95+endif
96+
97+msg-pip-exe:
98+ @echo "\n $(PIP) is required\n\n\
99+ Make sure you have updated pip installed, grab it from\n\
100+ https://pip.pypa.io or install it from your package\n\
101+ manager. On debian based OS these requirements are\n\
102+ installed by::\n\n\
103+ sudo -H apt-get install python$(PY)-pip\n" | $(FMT)
104+
105+ifeq ($(shell which $(PIP) >/dev/null 2>&1; echo $$?), 1)
106+pip-exe: msg-pip-exe
107+ $(error The '$(PIP)' command was not found)
108+else
109+pip-exe:
110+ @:
111+endif
112+
113+PHONY += msg-virtualenv-exe virtualenv-exe
114+msg-virtualenv-exe:
115+ @echo "\n virtualenv is required\n\n\
116+ Make sure you have an updated virtualenv installed, grab it from\n\
117+ https://virtualenv.pypa.io/en/stable/installation/ or install it\n\
118+ via pip by::\n\n\
119+ pip install --user https://github.com/pypa/virtualenv/tarball/master\n" | $(FMT)
120+
121+ifeq ($(shell which virtualenv >/dev/null 2>&1; echo $$?), 1)
122+virtualenv-exe: msg-virtualenv-exe
123+ $(error The 'virtualenv' command was not found)
124+else
125+virtualenv-exe:
126+ @:
127+endif
128+
129+# ------------------------------------------------------------------------------
130+# commands
131+# ------------------------------------------------------------------------------
132+
133+# $2 path to folder with setup.py, this uses pip from the OS
134+quiet_cmd_pyinstall = INSTALL $2
135+ cmd_pyinstall = $(PIP) $(PIP_VERBOSE) install $(PIP_INST) -e $2$(PY_SETUP_EXTRAS)
136+
137+# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
138+quiet_cmd_pyenvinstall = PYENV install $2
139+ cmd_pyenvinstall = $(PY_ENV_BIN)/pip $(PIP_VERBOSE) install -e $2$(PY_SETUP_EXTRAS)
140+
141+# Uninstall the package. Since pip does not uninstall the no longer needed
142+# depencies (something like autoremove) the depencies remain.
143+
144+# $2 package name to uninstall, this uses pip from the OS.
145+quiet_cmd_pyuninstall = UNINSTALL $2
146+ cmd_pyuninstall = $(PIP) $(PIP_VERBOSE) uninstall --yes $2
147+
148+# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
149+quiet_cmd_pyenvuninstall = PYENV uninstall $2
150+ cmd_pyenvuninstall = $(PY_ENV_BIN)/pip $(PIP_VERBOSE) uninstall --yes $2
151+
152+# $2 path to folder where virtualenv take place
153+quiet_cmd_virtualenv = PYENV usage: $ source ./$@/bin/activate
154+ cmd_virtualenv = \
155+ if [ ! -d "./$(PY_ENV)" ];then \
156+ $(VIRTUALENV) $(VIRTUALENV_VERBOSE) $(VTENV_OPTS) $2; \
157+ else \
158+ echo " PYENV using virtualenv from $2"; \
159+ fi
160+
161+# $2 path to lint
162+quiet_cmd_pylint = LINT $@
163+ cmd_pylint = $(PY_ENV_BIN)/pylint --rcfile $(PYLINT_RC) $2
164+
165+quiet_cmd_pytest = TEST $@
166+ cmd_pytest = $(PY_ENV_BIN)/tox -vv
167+
168+# setuptools, pip, easy_install its a mess full of cracks, a documentation hell
169+# and broken by design ... all sucks, I really, really hate all this ... aaargh!
170+#
171+# About python packaging see `Python Packaging Authority`_. Most of the names
172+# here are mapped to ``setup(<name1>=..., <name2>=...)`` arguments in
173+# ``setup.py``. See `Packaging and distributing projects`_ about ``setup(...)``
174+# arguments. If this is all new for you, start with `PyPI Quick and Dirty`_.
175+#
176+# Further read:
177+#
178+# - pythonwheels_
179+# - setuptools_
180+# - packaging_
181+# - sdist_
182+# - installing_
183+#
184+# .. _`Python Packaging Authority`: https://www.pypa.io
185+# .. _`Packaging and distributing projects`: https://packaging.python.org/guides/distributing-packages-using-setuptools/
186+# .. _`PyPI Quick and Dirty`: https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/
187+# .. _pythonwheels: https://pythonwheels.com/
188+# .. _setuptools: https://setuptools.readthedocs.io/en/latest/setuptools.html
189+# .. _packaging: https://packaging.python.org/guides/distributing-packages-using-setuptools/#packaging-and-distributing-projects
190+# .. _sdist: https://packaging.python.org/guides/distributing-packages-using-setuptools/#source-distributions
191+# .. _bdist_wheel: https://packaging.python.org/guides/distributing-packages-using-setuptools/#pure-python-wheels
192+# .. _installing: https://packaging.python.org/tutorials/installing-packages/
193+#
194+quiet_cmd_pybuild = BUILD $@
195+ cmd_pybuild = $(PY_ENV_BIN)/$(PYTHON) setup.py \
196+ sdist -d $(PYDIST) \
197+ bdist_wheel --bdist-dir $(PYBUILD) -d $(PYDIST)
198+
199+quiet_cmd_pyclean = CLEAN $@
200+# remove 'build' folder since bdist_wheel does not care the --bdist-dir
201+ cmd_pyclean = \
202+ rm -rf $(PYDIST) $(PYBUILD) ./local ./.tox *.egg-info ;\
203+ find . -name '*.pyc' -exec rm -f {} + ;\
204+ find . -name '*.pyo' -exec rm -f {} + ;\
205+ find . -name __pycache__ -exec rm -rf {} +
206+
207+# ------------------------------------------------------------------------------
208+# targets
209+# ------------------------------------------------------------------------------
210+
211+# for installation use the pip from the OS!
212+PHONY += pyinstall
213+pyinstall: pip-exe
214+ $(call cmd,pyinstall,.)
215+
216+PHONY += pyuninstall
217+pyuninstall: pip-exe
218+ $(call cmd,pyuninstall,$(PYOBJECTS))
219+
220+# for installation use the pip from PY_ENV (not the OS)!
221+PHONY += pyenvinstall
222+pyenvinstall: $(PY_ENV)
223+ $(call cmd,pyenvinstall,.)
224+
225+PHONY += pyenvuninstall
226+pyenvuninstall: $(PY_ENV)
227+ $(call cmd,pyenvuninstall,$(PYOBJECTS))
228+
229+PHONY += pyclean
230+pyclean:
231+ $(call cmd,pyclean)
232+
233+# to build *local* environment, python and virtualenv from the OS is needed!
234+pyenv: $(PY_ENV)
235+$(PY_ENV): virtualenv-exe python-exe
236+ $(call cmd,virtualenv,$(PY_ENV))
237+ @$(PY_ENV_BIN)/pip install $(PIP_VERBOSE) -r requirements.txt
238+
239+PHONY += pylint-exe
240+pylint-exe: $(PY_ENV)
241+ @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) install pylint
242+
243+PHONY += pylint
244+pylint: pylint-exe
245+ $(call cmd,pylint,$(PYOBJECTS))
246+
247+PHONY += pybuild
248+pybuild: $(PY_ENV)
249+ $(call cmd,pybuild)
250+
251+PHONY += pytest
252+pytest: $(PY_ENV)
253+ $(call cmd,pytest)
254+
255+PHONY += pydebug
256+# set breakpoint with:
257+# DEBUG()
258+# e.g. to run tests in debug mode in emacs use:
259+# 'M-x pdb' ... 'make pydebug'
260+pydebug: $(PY_ENV)
261+ DEBUG=$(DEBUG) $(PY_ENV_BIN)/pytest $(DEBUG) -v $(TEST_FOLDER)/$(TEST)
262+
263+# install / uninstall python objects into virtualenv (PYENV)
264+pyenv-install: $(PY_ENV)
265+ @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) install -e .
266+ @echo " ACTIVATE $(call normpath,$(PY_ENV_ACT)) "
267+
268+pyenv-uninstall: $(PY_ENV)
269+ @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) uninstall --yes .
270+
271+# runs python interpreter from ./local/py<N>/bin/python
272+pyenv-python: pyenv-install
273+ cd ./local; ../$(PY_ENV_BIN)/python -i
274+
275+# With 'dependency_links=' setuptools supports dependencies on packages hosted
276+# on other reposetories then PyPi, see "Packages Not On PyPI" [1]. The big
277+# drawback is, due to security reasons (I don't know where the security gate on
278+# PyPi is), this feature is not supported by pip [2]. Thats why an upload to
279+# PyPi is required and since uploads via setuptools is not recommended, we have
280+# to imstall / use twine ... its really a mess.
281+#
282+# [1] http://python-packaging.readthedocs.io/en/latest/dependencies.html#packages-not-on-pypi
283+# [2] https://github.com/pypa/pip/pull/1519
284+
285+# https://github.com/pypa/twine
286+PHONY += upload-pypi
287+upload-pypi: pyclean pybuild
288+ @$(PY_ENV_BIN)/twine upload $(PYDIST)/*
289+
290+.PHONY: $(PHONY)