这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@dalf
Copy link
Contributor

@dalf dalf commented Dec 19, 2021

What does this PR do?

This PR is demo of black:

  • first commit black -l 120 -S searx searxng_extra : reformat except the simple quote.
  • second commit : black -l 120 searx searxng_extra: reformat including the simple quote.

Why is this change important?

Normalize code format.

How to test this PR locally?

Author's checklist

Related issues

@return42
Copy link
Member

return42 commented Dec 21, 2021

I started to implement https://github.com/return42/searxng/commits/black-code-style
/ but I struggle when adding a pyproject.toml file.

A pyproject.toml breaks our python installation procedure with a misleading error message ... I don't know why users of "black" are forced to change their build stack just to configure a tool .. I gave up.

Here is the error message, pyyaml is installed in the virtualenv, but with a pyproject.toml, pip reports that a yaml installation is missed .. very confusing.

$ make buildenv
...
BUILDENV  PYENV     [install] pip install -e 'searx[test]'
BUILDENV  Obtaining file:///x/share/searxng
BUILDENV    Installing build dependencies: started
BUILDENV    Installing build dependencies: finished with status 'done'
BUILDENV    Checking if build backend supports build_editable: started
BUILDENV    Checking if build backend supports build_editable: finished with status 'done'
BUILDENV    Getting requirements to build wheel: started
BUILDENV    Getting requirements to build wheel: finished with status 'error'
BUILDENV    ERROR: Command errored out with exit status 1:
BUILDENV     command: /x/share/searxng/local/py3/bin/python /x/share/searxng/local/py3/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpkffhqb23
BUILDENV         cwd: /x/share/searxng
BUILDENV    Complete output (22 lines):
BUILDENV    Traceback (most recent call last):
BUILDENV      File "/x/share/searxng/local/py3/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
BUILDENV        main()
BUILDENV      File "/x/share/searxng/local/py3/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
BUILDENV        json_out['return_val'] = hook(**hook_input['kwargs'])
BUILDENV      File "/x/share/searxng/local/py3/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
BUILDENV        return hook(config_settings)
BUILDENV      File "/tmp/pip-build-env-g39jipud/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 162, in get_requires_for_build_wheel
BUILDENV        return self._get_build_requires(
BUILDENV      File "/tmp/pip-build-env-g39jipud/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 143, in _get_build_requires
BUILDENV        self.run_setup()
BUILDENV      File "/tmp/pip-build-env-g39jipud/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 267, in run_setup
BUILDENV        super(_BuildMetaLegacyBackend,
BUILDENV      File "/tmp/pip-build-env-g39jipud/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 158, in run_setup
BUILDENV        exec(compile(code, __file__, 'exec'), locals())
BUILDENV      File "setup.py", line 7, in <module>
BUILDENV        from searx.version import VERSION_TAG, GIT_URL
BUILDENV      File "/x/share/searxng/searx/__init__.py", line 12, in <module>
BUILDENV        import searx.settings_loader
BUILDENV      File "/x/share/searxng/searx/settings_loader.py", line 8, in <module>
BUILDENV        import yaml
BUILDENV    ModuleNotFoundError: No module named 'yaml'
BUILDENV    ----------------------------------------
BUILDENV  WARNING: Discarding file:///x/share/searxng. Command errored out with exit status 1: /x/share/searxng/local/py3/bin/python /x/share/searxng/local/py3/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpkffhqb23 Check the logs for full command output.

@dalf
Copy link
Contributor Author

dalf commented Dec 21, 2021

pyaml is required to run setup.py, so it has be declared as such in project.toml:

But to make it simple why not run black with parameters:
black -l 120 --target-version py36
?

black is not very configurable, but as described, it would solve the code formatting discussion.

@return42
Copy link
Member

black is not very configurable, but as described, it would solve the code formatting discussion.

Personally I prefer a config file .. what can be read by other tools also. I don't know if we should reinvent our "requirements" setup to have such a toml file .. ?

@not-my-profile
Copy link
Contributor

not-my-profile commented Dec 22, 2021

How about using --skip-string-normalization? I don't think that string normalization adds much ... rather it needlessly produces a huge diff obscuring git blame ... (yes I know you can use git blame --skip-rev but normally you only use that after seeing that the autoformat commit changed the line you are interested in). So I think --skip-string-normalization would improve git blame ergonomics.

That is how about omitting the second commit?

@dalf
Copy link
Contributor Author

dalf commented Dec 24, 2021

I pushed a new version:

A first commit update ./manage:

  • make test.pep8 is replaced by test.black: black runs on ALL python files including linted by pylint.
  • make format.python calls black to format the Python code

A second commit contains the result of make format.python

A third one fixes some pylint issues (it can be improved, but at least the tests pass).

@return42
Copy link
Member

return42 commented Dec 24, 2021

I pushed a new version

fine, thanks .. I will have a look.

What do you think about pyproject.toml in our project, should I give it a try? If so I would take time for a research (its new to me).

[EDIT] now I see there is a --config option / no need to have a pyproject.toml ..

Comment on lines 27 to 37
HTML_TAGS = [
'embed', 'iframe', 'object', 'param', 'picture', 'source', 'svg', 'math', 'canvas', 'noscript', 'script',
'del', 'ins', 'area', 'audio', 'img', 'map', 'track', 'video', 'a', 'abbr', 'b', 'bdi', 'bdo', 'br', 'cite',
'code', 'data', 'dfn', 'em', 'i', 'kdb', 'mark', 'q', 'rb', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'small',
'span', 'strong', 'sub', 'sup', 'time', 'u', 'var', 'wbr', 'style', 'blockquote', 'dd', 'div', 'dl', 'dt',
'figcaption', 'figure', 'hr', 'li', 'ol', 'p', 'pre', 'ul', 'button', 'datalist', 'fieldset', 'form', 'input',
'label', 'legend', 'meter', 'optgroup', 'option', 'output', 'progress', 'select', 'textarea', 'applet',
'frame', 'frameset'
'embed',
'iframe',
'object',
'param',
'picture',
'source',
'svg',
'math',
'canvas',
'noscript',
'script',
'del',
'ins',
'area',
'audio',
'img',
'map',
'track',
'video',
'a',
'abbr',
'b',
'bdi',
'bdo',
'br',
'cite',
'code',
'data',
'dfn',
'em',
'i',
'kdb',
'mark',
'q',
'rb',
'rp',
'rt',
'rtc',
'ruby',
's',
'samp',
'small',
'span',
'strong',
'sub',
'sup',
'time',
'u',
'var',
'wbr',
'style',
'blockquote',
'dd',
'div',
'dl',
'dt',
'figcaption',
'figure',
'hr',
'li',
'ol',
'p',
'pre',
'ul',
'button',
'datalist',
'fieldset',
'form',
'input',
'label',
'legend',
'meter',
'optgroup',
'option',
'output',
'progress',
'select',
'textarea',
'applet',
'frame',
'frameset',
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Over all I think black formatting is good, but there are some exceptions like this one here.

In such cases we should use # fmt: off & # fmt: on.

@return42
Copy link
Member

FYI: I am in review with this PR, I will push some suggestions, please do not change the code while I am in review / thanks!

Copy link
Member

@return42 return42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM / thanks!

@dalf See my comment and the patches I pushed on top of your branch.

@return42 return42 marked this pull request as ready for review December 24, 2021 13:02
@return42
Copy link
Member

We should prioritize (merge) this PR over:

@dalf if you want I can rebase this branch, but first have a look at the commits I pushed on top of your branch.

@dalf
Copy link
Contributor Author

dalf commented Dec 27, 2021

first have a look at the commits I pushed on top of your branch.

if you want I can rebase this branch

it will be never a good time to change a lot of time files. So let's go now.

@return42
Copy link
Member

it will be never a good time to change a lot of time files. So let's go now.

OK, I will going to rebase this branch right now, please do not merge other PR with python code in the meantime ..

dalf and others added 5 commits December 27, 2021 08:58
"make test.black" checks for the code style
"make format.python" format the python code
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Disable the python code formatting from python-black, where the readability of
code suffers by formatting.

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This patch was generated by black [1]::

    make format.python

[1] https://github.com/psf/black

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Fix pylint issues from commit (3d96a98)

    [format.python] initial formatting of the python code

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
@return42
Copy link
Member

@dalf I rebased and reorder the branch / If you think PR is ready to merge, please merge.

FYI: the CI hangs for some reason I don't know, I restarted the jobs .. lets see if the tests pass now ...

@return42
Copy link
Member

Seems ./manage node.env does not work in the CI (see here) / not related to this PR I think.

@dalf dalf merged commit c6922ae into searxng:master Dec 27, 2021
@dalf dalf deleted the apply-black branch December 27, 2021 18:11
@dalf
Copy link
Contributor Author

dalf commented Dec 27, 2021

Thank you for the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants