Re: [Toaster] [PATCH] toaster: add tox.ini file to execute flake8 and test suite

Tim Orling <[email protected]> Mon, 23 Oct 2023 11:28:24 -0700
Newsgroups org.yoctoproject.lists.toaster,org.openembedded.lists.bitbake-devel
Message-ID <CANx9H-BM8q5K1UjdO2g=wGpPR8TmbbaOKzDviYPaitnV9M6OdA@mail.gmail.com>
I was able to set up an environment where I could at least get tox to run.
See comments below for changes to the tox.ini

My steps:
Create and cd into a directory /path/to/workspace-review-toaster/
Clone bitbake and openembedded-core into
/path/to/workspace-review-toaster/layers/
(in /path/to/workspace-review-toaster):
python3 -m venv venv
source venv/bin/activate
pip install tox
source layers/openembedded-core/oe-init-buildenv
(now in build/)
$ TOX_WORKDIR=${PWD}/.tox tox
--conf=/path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tox.ini

I'm not sure if it is my environment or that the tests do not pass yet, but
out of 44 tests, 20 FAILED. I have attached my 1-install_deps.log and my
2-command[0].log
(my actual path is sanitized in the above steps and in the log files).

On Wed, Oct 18, 2023 at 12:46 PM Marlon Rodriguez Garcia <
[email protected]> wrote:

> Added configuration file for tox https://tox.wiki/en/4.11.3/ that
> includes flake8 and the test suite.
> This file can be execute using the command 'tox tox.ini' and can be used
> in autobuilder.
>
> By adding flake8 to the validation of toaster the following aspects have
> to be take into consideration:
> Objective
> - To comply with PEP8 standards, we propose to utilize a linting
> tool(Flake8) that checks toaster's codebase for errors, styling issues and
> complexity
>
> Ruleset
> - See complete list of rules : https://www.flake8rules.com/
>
> Assumptions
> - We are aware that not all Flake8 rules can be applied to current
> codebase (those determined to be more troublesome can be excluded).
> - The patches can be integrated gradually by sections and/or rules.
> - The tox.ini will include the execution of the test suite.
>
> Pros
> - Standardized codebase for future integrations.
> - Majority of the patches will be syntax modifications and not affecting
> application logic.
>
> Cons
> - Major refactor of the codebase.
>
> Signed-off-by: Marlon Rodriguez Garcia <
> [email protected]>
> ---
>  lib/toaster/tox.ini | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
>  create mode 100644 lib/toaster/tox.ini
>
> diff --git a/lib/toaster/tox.ini b/lib/toaster/tox.ini
> new file mode 100644
> index 00000000..bcdfdb4f
> --- /dev/null
> +++ b/lib/toaster/tox.ini
> @@ -0,0 +1,25 @@
> +[tox]
> +envlist = py310
>

Our current minimum Python requirement is 3.8 (this is why the
toaster-container GitHub actions are running python 3.8 environment)
https://git.openembedded.org/bitbake/tree/lib/bb/__init__.py#n15

+skipsdist = True
> +toxworkdir = {env:TOX_WORKDIR:.tox}
> +passenv = *
> +
> +[testenv]
> +setenv =
> +    DJANGO_SETTINGS_MODULE=toastermain.settings_test
> +    TOASTER_BUILDSERVER=1
> +    EVENTREPLAY_DIR={toxinidir}/../../../build/
>

We CANNOT hard code the build path like this. Not everyone will be running
in poky/build and in fact not everyone will be running Toaster with the
poky distro. Therefore, the tests should also pass even if we are running
with DISTRO="" (no-distro).

+    BUILDDIR={toxinidir}/../../../build/
>
source openembedded-core/oe-init-buildenv already sets this as an
environment variable.

Instead, I set:
    BUILDIR = {env:BUILDDIR}
    EVENTREPLAY_DIR = {env:EVENTREPLAY_DIR:BUILDDIR}

+commands =
> +    flake8
>
This fails horribly so I had to comment flake8 out.

I think we should separate out the tox.ini for the django tests first. The
flake8 test should be added in a separate thread with all the changes
needed to bitbake/lib/toaster in order to make it pass, assuming we as a
community want to decide to make passing flake8 a requirement for Toaster.


> +    python3 {toxinidir}/manage.py test tests.db tests.commands
> tests.builds tests.browser tests.functional tests.views
> +deps =
> +    -r ../../toaster-requirements.txt
>
This also needs to be relative to {toxinidir}:
-r {toxinidir}/../../toaster-requirements.txt


> +    -r {toxinidir}/tests/toaster-tests-requirements.txt
> +    flake8
> +
> +[flake8]
> +ignore = E501, F403
> +
> +[testenv:chrome]
> +commands={[testenv]commands} --splinter-webdriver=chrome
> \ No newline at end of file
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#5873):
> https://lists.yoctoproject.org/g/toaster/message/5873
> Mute This Topic: https://lists.yoctoproject.org/mt/102046799/924729
> Group Owner: [email protected]
> Unsubscribe: https://lists.yoctoproject.org/g/toaster/unsub [
> [email protected]]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>
1-install_deps.log (text/x-log, 11.5 KB)
name: py310
run_id: install_deps
env HOME: /home/ttorling
env LANG: en_US.UTF-8
env TERM: xterm-256color
env PATH: /path/to/workspace-toaster-review/build/.tox/py310/bin:/path/to/workspace-toaster-review/layers/openembedded-core/scripts:/path/to/workspace-toaster-review/layers/bitbake/bin:/path/to/workspace-toaster-review/venv/bin:/home/ttorling/.nvm/versions/node/v16.18.1/bin:/home/ttorling/.local/bin:/home/ttorling/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ttorling/.local/share/JetBrains/Toolbox/scripts:/home/ttorling/.nsccli/bin
env PYTHONHASHSEED: 3294293323
env PIP_DISABLE_PIP_VERSION_CHECK: 1
env PYTHONIOENCODING: utf-8
env DJANGO_SETTINGS_MODULE: toastermain.settings_test
env TOASTER_BUILDSERVER: 1
env BUILDIR: /path/to/workspace-toaster-review/build
env EVENTREPLAY_DIR: BUILDDIR
env TOX_ENV_NAME: py310
env TOX_WORK_DIR: /path/to/workspace-toaster-review/build/.tox
env TOX_ENV_DIR: /path/to/workspace-toaster-review/build/.tox/py310
env VIRTUAL_ENV: /path/to/workspace-toaster-review/build/.tox/py310
env COLUMNS: 133
env LINES: 70
metadata pid: 1451462
cwd: /path/to/workspace-toaster-review/layers/bitbake/lib/toaster
allow: /path/to/workspace-toaster-review/build/.tox/py310/bin/*
cmd: python -I -m pip install flake8 -r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/../../toaster-requirements.txt -r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt
exit_code: 0
Collecting flake8
  Obtaining dependency information for flake8 from https://files.pythonhosted.org/packages/b0/24/bbf7175ffc47cb3d3e1eb523ddb23272968359dfcf2e1294707a2bf12fc4/flake8-6.1.0-py2.py3-none-any.whl.metadata
  Using cached flake8-6.1.0-py2.py3-none-any.whl.metadata (3.8 kB)
Collecting Django<4.3,>4.2 (from -r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/../../toaster-requirements.txt (line 1))
  Obtaining dependency information for Django<4.3,>4.2 from https://files.pythonhosted.org/packages/b9/45/707dfc56f381222c1c798503546cb390934ab246fc45b5051ef66e31099c/Django-4.2.6-py3-none-any.whl.metadata
  Using cached Django-4.2.6-py3-none-any.whl.metadata (4.1 kB)
Collecting beautifulsoup4>=4.4.0 (from -r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/../../toaster-requirements.txt (line 2))
  Using cached beautifulsoup4-4.12.2-py3-none-any.whl (142 kB)
Collecting pytz (from -r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/../../toaster-requirements.txt (line 3))
  Obtaining dependency information for pytz from https://files.pythonhosted.org/packages/32/4d/aaf7eff5deb402fd9a24a1449a8119f00d74ae9c2efa79f8ef9994261fc2/pytz-2023.3.post1-py2.py3-none-any.whl.metadata
  Using cached pytz-2023.3.post1-py2.py3-none-any.whl.metadata (22 kB)
Collecting django-log-viewer==1.1.7 (from -r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/../../toaster-requirements.txt (line 4))
  Using cached django_log_viewer-1.1.7-py2.py3-none-any.whl
Collecting selenium>=4.13.0 (from -r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Obtaining dependency information for selenium>=4.13.0 from https://files.pythonhosted.org/packages/fc/df/a8972c41279fc9e9404cad87bc1f4d6d3d824b84c5c072dca0e986a89680/selenium-4.14.0-py3-none-any.whl.metadata
  Using cached selenium-4.14.0-py3-none-any.whl.metadata (6.9 kB)
Collecting mccabe<0.8.0,>=0.7.0 (from flake8)
  Using cached mccabe-0.7.0-py2.py3-none-any.whl (7.3 kB)
Collecting pycodestyle<2.12.0,>=2.11.0 (from flake8)
  Obtaining dependency information for pycodestyle<2.12.0,>=2.11.0 from https://files.pythonhosted.org/packages/b1/90/a998c550d0ddd07e38605bb5c455d00fcc177a800ff9cc3dafdcb3dd7b56/pycodestyle-2.11.1-py2.py3-none-any.whl.metadata
  Using cached pycodestyle-2.11.1-py2.py3-none-any.whl.metadata (4.5 kB)
Collecting pyflakes<3.2.0,>=3.1.0 (from flake8)
  Obtaining dependency information for pyflakes<3.2.0,>=3.1.0 from https://files.pythonhosted.org/packages/00/e9/1e1fd7fae559bfd07704991e9a59dd1349b72423c904256c073ce88a9940/pyflakes-3.1.0-py2.py3-none-any.whl.metadata
  Using cached pyflakes-3.1.0-py2.py3-none-any.whl.metadata (3.5 kB)
Collecting asgiref<4,>=3.6.0 (from Django<4.3,>4.2->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/../../toaster-requirements.txt (line 1))
  Obtaining dependency information for asgiref<4,>=3.6.0 from https://files.pythonhosted.org/packages/9b/80/b9051a4a07ad231558fcd8ffc89232711b4e618c15cb7a392a17384bbeef/asgiref-3.7.2-py3-none-any.whl.metadata
  Using cached asgiref-3.7.2-py3-none-any.whl.metadata (9.2 kB)
Collecting sqlparse>=0.3.1 (from Django<4.3,>4.2->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/../../toaster-requirements.txt (line 1))
  Using cached sqlparse-0.4.4-py3-none-any.whl (41 kB)
Collecting soupsieve>1.2 (from beautifulsoup4>=4.4.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/../../toaster-requirements.txt (line 2))
  Obtaining dependency information for soupsieve>1.2 from https://files.pythonhosted.org/packages/4c/f3/038b302fdfbe3be7da016777069f26ceefe11a681055ea1f7817546508e3/soupsieve-2.5-py3-none-any.whl.metadata
  Using cached soupsieve-2.5-py3-none-any.whl.metadata (4.7 kB)
Collecting urllib3[socks]<3,>=1.26 (from selenium>=4.13.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Obtaining dependency information for urllib3[socks]<3,>=1.26 from https://files.pythonhosted.org/packages/d2/b2/b157855192a68541a91ba7b2bbcb91f1b4faa51f8bae38d8005c034be524/urllib3-2.0.7-py3-none-any.whl.metadata
  Using cached urllib3-2.0.7-py3-none-any.whl.metadata (6.6 kB)
Collecting trio~=0.17 (from selenium>=4.13.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Obtaining dependency information for trio~=0.17 from https://files.pythonhosted.org/packages/a3/dd/b61fa61b186d3267ef3903048fbee29132963ae762fb70b08d4a3cd6f7aa/trio-0.22.2-py3-none-any.whl.metadata
  Using cached trio-0.22.2-py3-none-any.whl.metadata (4.7 kB)
Collecting trio-websocket~=0.9 (from selenium>=4.13.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Obtaining dependency information for trio-websocket~=0.9 from https://files.pythonhosted.org/packages/48/be/a9ae5f50cad5b6f85bd2574c2c923730098530096e170c1ce7452394d7aa/trio_websocket-0.11.1-py3-none-any.whl.metadata
  Using cached trio_websocket-0.11.1-py3-none-any.whl.metadata (4.7 kB)
Collecting certifi>=2021.10.8 (from selenium>=4.13.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Obtaining dependency information for certifi>=2021.10.8 from https://files.pythonhosted.org/packages/4c/dd/2234eab22353ffc7d94e8d13177aaa050113286e93e7b40eae01fbf7c3d9/certifi-2023.7.22-py3-none-any.whl.metadata
  Using cached certifi-2023.7.22-py3-none-any.whl.metadata (2.2 kB)
Collecting typing-extensions>=4 (from asgiref<4,>=3.6.0->Django<4.3,>4.2->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/../../toaster-requirements.txt (line 1))
  Obtaining dependency information for typing-extensions>=4 from https://files.pythonhosted.org/packages/24/21/7d397a4b7934ff4028987914ac1044d3b7d52712f30e2ac7a2ae5bc86dd0/typing_extensions-4.8.0-py3-none-any.whl.metadata
  Using cached typing_extensions-4.8.0-py3-none-any.whl.metadata (3.0 kB)
Collecting attrs>=20.1.0 (from trio~=0.17->selenium>=4.13.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Using cached attrs-23.1.0-py3-none-any.whl (61 kB)
Collecting sortedcontainers (from trio~=0.17->selenium>=4.13.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Using cached sortedcontainers-2.4.0-py2.py3-none-any.whl (29 kB)
Collecting idna (from trio~=0.17->selenium>=4.13.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting outcome (from trio~=0.17->selenium>=4.13.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Obtaining dependency information for outcome from https://files.pythonhosted.org/packages/fa/63/0807d3bc1742adffd2bac458829f3f71ce3aa29bec44a8ac008aed2b467c/outcome-1.3.0-py2.py3-none-any.whl.metadata
  Using cached outcome-1.3.0-py2.py3-none-any.whl.metadata (2.4 kB)
Collecting sniffio (from trio~=0.17->selenium>=4.13.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Using cached sniffio-1.3.0-py3-none-any.whl (10 kB)
Collecting exceptiongroup>=1.0.0rc9 (from trio~=0.17->selenium>=4.13.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Obtaining dependency information for exceptiongroup>=1.0.0rc9 from https://files.pythonhosted.org/packages/ad/83/b71e58666f156a39fb29417e4c8ca4bc7400c0dd4ed9e8842ab54dc8c344/exceptiongroup-1.1.3-py3-none-any.whl.metadata
  Using cached exceptiongroup-1.1.3-py3-none-any.whl.metadata (6.1 kB)
Collecting wsproto>=0.14 (from trio-websocket~=0.9->selenium>=4.13.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Using cached wsproto-1.2.0-py3-none-any.whl (24 kB)
Collecting pysocks!=1.5.7,<2.0,>=1.5.6 (from urllib3[socks]<3,>=1.26->selenium>=4.13.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Using cached PySocks-1.7.1-py3-none-any.whl (16 kB)
Collecting h11<1,>=0.9.0 (from wsproto>=0.14->trio-websocket~=0.9->selenium>=4.13.0->-r /path/to/workspace-toaster-review/layers/bitbake/lib/toaster/tests/toaster-tests-requirements.txt (line 1))
  Using cached h11-0.14.0-py3-none-any.whl (58 kB)
Using cached flake8-6.1.0-py2.py3-none-any.whl (58 kB)
Using cached Django-4.2.6-py3-none-any.whl (8.0 MB)
Using cached pytz-2023.3.post1-py2.py3-none-any.whl (502 kB)
Using cached selenium-4.14.0-py3-none-any.whl (9.9 MB)
Using cached asgiref-3.7.2-py3-none-any.whl (24 kB)
Using cached certifi-2023.7.22-py3-none-any.whl (158 kB)
Using cached pycodestyle-2.11.1-py2.py3-none-any.whl (31 kB)
Using cached pyflakes-3.1.0-py2.py3-none-any.whl (62 kB)
Using cached soupsieve-2.5-py3-none-any.whl (36 kB)
Using cached trio-0.22.2-py3-none-any.whl (400 kB)
Using cached trio_websocket-0.11.1-py3-none-any.whl (17 kB)
Using cached exceptiongroup-1.1.3-py3-none-any.whl (14 kB)
Using cached typing_extensions-4.8.0-py3-none-any.whl (31 kB)
Using cached outcome-1.3.0-py2.py3-none-any.whl (10 kB)
Using cached urllib3-2.0.7-py3-none-any.whl (124 kB)
Installing collected packages: sortedcontainers, pytz, django-log-viewer, urllib3, typing-extensions, sqlparse, soupsieve, sniffio, pysocks, pyflakes, pycodestyle, mccabe, idna, h11, exceptiongroup, certifi, attrs, wsproto, outcome, flake8, beautifulsoup4, asgiref, trio, Django, trio-websocket, selenium
Successfully installed Django-4.2.6 asgiref-3.7.2 attrs-23.1.0 beautifulsoup4-4.12.2 certifi-2023.7.22 django-log-viewer-1.1.7 exceptiongroup-1.1.3 flake8-6.1.0 h11-0.14.0 idna-3.4 mccabe-0.7.0 outcome-1.3.0 pycodestyle-2.11.1 pyflakes-3.1.0 pysocks-1.7.1 pytz-2023.3.post1 selenium-4.14.0 sniffio-1.3.0 sortedcontainers-2.4.0 soupsieve-2.5 sqlparse-0.4.4 trio-0.22.2 trio-websocket-0.11.1 typing-extensions-4.8.0 urllib3-2.0.7 wsproto-1.2.0
2-commands[0].log (text/x-log, 724.5 KB) - not displayed