Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flake8 is a little flaky #8255

Closed
garciadias opened this issue Dec 3, 2024 · 3 comments
Closed

Flake8 is a little flaky #8255

garciadias opened this issue Dec 3, 2024 · 3 comments

Comments

@garciadias
Copy link

garciadias commented Dec 3, 2024

I am refactoring some tests as described in #8231, and I noticed an odd issue with Flake 8. If I run ./runtests.sh --codeformat I get quite some errors, but if I run ./runtests.sh --autofix or ./runtests.sh --ruff there are no complaints.

I understand Flake8 is not run in ./runtests.sh --autofix or ./runtests.sh --ruff, but it is run in ./runtests.sh -f -u --net --coverage, which you recommend running before submitting a PR. I imagine this is a disagreement between Flake8 and ruff. It seems to me that we should either run Flake8 on all cases or never run it.

The issues raised by Flake8 are not coming from my changes but are in the code in the dev branch. Would you like me to solve those or ignore the Flake8 errors?

See below:

./runtests.sh --codeformat

Run tests under /home/rgd/kcl/MONAI
PYTHONPATH: /home/rgd/kcl/MONAI:
Python: /home/rgd/.cache/pypoetry/virtualenvs/monai-mfCICwbm-py3.12/bin/python
MONAI version: 1.4.0+49.g6e9c66e6
Numpy version: 1.26.4
Pytorch version: 2.4.1+cu121
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: 6e9c66e66369ecfbd4ea8d98b995d18a4fdf324d
MONAI __file__: /home/<username>/kcl/MONAI/monai/__init__.py

Optional dependencies:
Pytorch Ignite version: 0.4.11
ITK version: 5.4.0
Nibabel version: 5.2.1
scikit-image version: 0.24.0
scipy version: 1.14.1
Pillow version: 10.4.0
Tensorboard version: 2.18.0
gdown version: 5.2.0
TorchVision version: 0.19.1+cu121
tqdm version: 4.66.5
lmdb version: 1.5.1
psutil version: 5.9.8
pandas version: 2.2.3
einops version: 0.8.0
transformers version: NOT INSTALLED or UNKNOWN VERSION.
mlflow version: 2.16.2
pynrrd version: 1.0.0
clearml version: 1.16.5rc2

For details about installing the optional dependencies, please visit:
    https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies

Source code copyright headers checked (1244).
--------------------------------------------------------------------------------
isort

                 _                 _
                (_) ___  ___  _ __| |_
                | |/ _/ / _ \/ '__  _/
                | |\__ \/\_\/| |  | |_
                |_|\___/\___/\_/   \_/

      isort your imports, so you don't have to.

                    VERSION 5.13.2

Skipped 5 files
passed!
--------------------------------------------------------------------------------
black
python -m black, 24.10.0 (compiled: yes)
Python (CPython) 3.12.3
All done! ✨ 🍰 ✨
1208 files would be left unchanged.
passed!
--------------------------------------------------------------------------------
flake8
7.1.1 (flake8-bugbear: 24.2.6, flake8-comprehensions: 3.15.0, mccabe: 0.7.0, pep8-naming: 0.14.1, pycodestyle: 2.12.1, pyflakes: 3.2.0) CPython 3.12.3 on Linux
/home/rgd/kcl/MONAI/monai/apps/auto3dseg/bundle_gen.py:399:69: E226 missing whitespace around arithmetic operator
/home/rgd/kcl/MONAI/monai/apps/detection/networks/retinanet_detector.py:790:102: E231 missing whitespace after ','
/home/rgd/kcl/MONAI/monai/apps/detection/utils/anchor_utils.py:177:44: E226 missing whitespace around arithmetic operator
/home/rgd/kcl/MONAI/monai/apps/detection/utils/anchor_utils.py:183:44: E226 missing whitespace around arithmetic operator
/home/rgd/kcl/MONAI/monai/apps/detection/utils/detector_utils.py:94:88: E225 missing whitespace around operator
/home/rgd/kcl/MONAI/monai/apps/detection/utils/detector_utils.py:98:75: E225 missing whitespace around operator
/home/rgd/kcl/MONAI/monai/auto3dseg/analyzer.py:272:58: E226 missing whitespace around arithmetic operator
/home/rgd/kcl/MONAI/monai/auto3dseg/analyzer.py:353:69: E226 missing whitespace around arithmetic operator
/home/rgd/kcl/MONAI/monai/auto3dseg/analyzer.py:522:58: E226 missing whitespace around arithmetic operator
/home/rgd/kcl/MONAI/monai/auto3dseg/analyzer.py:900:47: E226 missing whitespace around arithmetic operator
/home/rgd/kcl/MONAI/monai/auto3dseg/analyzer.py:902:47: E226 missing whitespace around arithmetic operator
/home/rgd/kcl/MONAI/monai/data/wsi_reader.py:213:80: E226 missing whitespace around arithmetic operator
/home/rgd/kcl/MONAI/monai/losses/unified_focal_loss.py:220:91: E226 missing whitespace around arithmetic operator
/home/rgd/kcl/MONAI/monai/metrics/meandice.py:125:44: E226 missing whitespace around arithmetic operator
/home/rgd/kcl/MONAI/monai/networks/blocks/patchembedding.py:101:30: E226 missing whitespace around arithmetic operator
/home/rgd/kcl/MONAI/monai/networks/layers/factories.py:98:51: E225 missing whitespace around operator
/home/rgd/kcl/MONAI/monai/transforms/croppad/array.py:295:87: E226 missing whitespace around arithmetic operator
/home/rgd/kcl/MONAI/monai/transforms/regularization/array.py:44:72: E251 unexpected spaces around keyword / parameter equals
/home/rgd/kcl/MONAI/monai/transforms/regularization/array.py:44:74: E202 whitespace before '}'
/home/rgd/kcl/MONAI/monai/transforms/regularization/array.py:44:74: E251 unexpected spaces around keyword / parameter equals
1     E202 whitespace before '}'
3     E225 missing whitespace around operator
13    E226 missing whitespace around arithmetic operator
1     E231 missing whitespace after ','
2     E251 unexpected spaces around keyword / parameter equals
20
Check failed!
Please run auto style fixes: ./runtests.sh --autofix

./runtests.sh --autofix

Run tests under /home/rgd/kcl/MONAI
PYTHONPATH: /home/rgd/kcl/MONAI:
Python: /home/rgd/.cache/pypoetry/virtualenvs/monai-mfCICwbm-py3.12/bin/python
MONAI version: 1.4.0+49.g6e9c66e6
Numpy version: 1.26.4
Pytorch version: 2.4.1+cu121
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: 6e9c66e66369ecfbd4ea8d98b995d18a4fdf324d
MONAI __file__: /home/<username>/kcl/MONAI/monai/__init__.py

Optional dependencies:
Pytorch Ignite version: 0.4.11
ITK version: 5.4.0
Nibabel version: 5.2.1
scikit-image version: 0.24.0
scipy version: 1.14.1
Pillow version: 10.4.0
Tensorboard version: 2.18.0
gdown version: 5.2.0
TorchVision version: 0.19.1+cu121
tqdm version: 4.66.5
lmdb version: 1.5.1
psutil version: 5.9.8
pandas version: 2.2.3
einops version: 0.8.0
transformers version: NOT INSTALLED or UNKNOWN VERSION.
mlflow version: 2.16.2
pynrrd version: 1.0.0
clearml version: 1.16.5rc2

For details about installing the optional dependencies, please visit:
    https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies

Source code copyright headers checked (1244).
--------------------------------------------------------------------------------
isort-fix

                 _                 _
                (_) ___  ___  _ __| |_
                | |/ _/ / _ \/ '__  _/
                | |\__ \/\_\/| |  | |_
                |_|\___/\___/\_/   \_/

      isort your imports, so you don't have to.

                    VERSION 5.13.2

Skipped 5 files
passed!
--------------------------------------------------------------------------------
black-fix
python -m black, 24.10.0 (compiled: yes)
Python (CPython) 3.12.3
All done! ✨ 🍰 ✨
1208 files left unchanged.
passed!
--------------------------------------------------------------------------------
ruff-fix
ruff 0.7.4
All checks passed!
passed!

./runtests.sh --ruff

Run tests under /home/rgd/kcl/MONAI
PYTHONPATH: /home/rgd/kcl/MONAI:
Python: /home/rgd/.cache/pypoetry/virtualenvs/monai-mfCICwbm-py3.12/bin/python
MONAI version: 1.4.0+49.g6e9c66e6
Numpy version: 1.26.4
Pytorch version: 2.4.1+cu121
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: 6e9c66e66369ecfbd4ea8d98b995d18a4fdf324d
MONAI __file__: /home/<username>/kcl/MONAI/monai/__init__.py

Optional dependencies:
Pytorch Ignite version: 0.4.11
ITK version: 5.4.0
Nibabel version: 5.2.1
scikit-image version: 0.24.0
scipy version: 1.14.1
Pillow version: 10.4.0
Tensorboard version: 2.18.0
gdown version: 5.2.0
TorchVision version: 0.19.1+cu121
tqdm version: 4.66.5
lmdb version: 1.5.1
psutil version: 5.9.8
pandas version: 2.2.3
einops version: 0.8.0
transformers version: NOT INSTALLED or UNKNOWN VERSION.
mlflow version: 2.16.2
pynrrd version: 1.0.0
clearml version: 1.16.5rc2

For details about installing the optional dependencies, please visit:
    https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies

--------------------------------------------------------------------------------
ruff
ruff 0.7.4
All checks passed!
passed!
@garciadias garciadias changed the title Flake8 is a little flake Flake8 is a little flaky Dec 3, 2024
@KumoLiu
Copy link
Contributor

KumoLiu commented Dec 5, 2024

Hi @garciadias, thanks for reporting!

It seems there might be a mismatch in our results, and I suspect the difference could stem from the Python version. Different Python versions may trigger variations in rules. If running the checks within the MONAI container or using a lower Python version might cause these errors to disappear. However, upon reviewing the reported errors, some of them, like "E226: missing whitespace around arithmetic operator", appear straightforward to fix and should indeed be addressed.
Here is the output I get from ./runtests.sh --codeformat

flake8
7.1.1 (flake8-bugbear: 24.2.6, flake8-comprehensions: 3.15.0, mccabe: 0.7.0, pep8-naming: 0.14.1, pycodestyle:
2.12.1, pyflakes: 3.2.0) CPython 3.10.12 on Linux
0
passed!
--------------------------------------------------------------------------------
ruff
ruff 0.7.4
All checks passed!
passed!

@garciadias
Copy link
Author

Hi @KumoLiu, thank you for looking into it.

I wouldn't mind fixing it myself, but I was worried about fixing it for me, and other people started getting errors.
I don't mind using a lower version of Python, but I would prefer to fix this so we can have higher version compatibility.
I will fix the errors and some different python versions to see if it causes any issues.

Many thanks!

@KumoLiu
Copy link
Contributor

KumoLiu commented Dec 5, 2024

I wouldn't mind fixing it myself, but I was worried about fixing it for me, and other people started getting errors. I don't mind using a lower version of Python, but I would prefer to fix this so we can have higher version compatibility. I will fix the errors and some different python versions to see if it causes any issues.

Yes, we have only tested the code on Python 3.9. Therefore, we should ensure that it works correctly for this version at the very least. For support on higher versions, we can defer it for now and focus on fixing low-risk formatting issues only.

- name: Set up Python 3.9

Thanks!

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

No branches or pull requests

2 participants