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

Reduce the cyclomatic complexity of our Python code #101

Open
cclauss opened this issue Mar 31, 2021 · 1 comment
Open

Reduce the cyclomatic complexity of our Python code #101

cclauss opened this issue Mar 31, 2021 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@cclauss
Copy link
Contributor

cclauss commented Mar 31, 2021

Our automated tests currently run ruff --max-complexity=101 when the recommended setting is 10, not 101. We do not need to reduce complexity all the way down to 10 but we should examine our worst offending functions and try to reduce their cyclomatic complexity.

Strong tests should be put in place before modifying these functions because at 101, we should expect severe spaghetti code with substantial corner cases and side effects. GenerateOutput() is one function that is 739 lines long!

Please modify only one file per pull request given the difficulty of reviewing changes to older yet crucial code.

% flake8 --ignore=E203,W503 --max-line-length=88 --statistics --max-complexity=20

./gyp/pylib/gyp/generator/xcode.py:641:1: C901 'GenerateOutput' is too complex (101)
./gyp/pylib/gyp/generator/cmake.py:624:1: C901 'WriteTarget' is too complex (78)
./gyp/pylib/gyp/generator/ninja.py:2207:1: C901 'GenerateOutputForConfig' is too complex (55)
./gyp/pylib/gyp/input.py:759:1: C901 'ExpandVariables' is too complex (48)
./gyp/pylib/gyp/__init__.py:316:1: C901 'gyp_main' is too complex (45)
./gyp/pylib/gyp/generator/make.py:1571:5: C901 'MakefileWriter.WriteTarget' is too complex (40)
./gyp/pylib/gyp/generator/ninja.py:1349:5: C901 'NinjaWriter.WriteLinkForArch' is too complex (35)
./gyp/pylib/gyp/generator/make.py:2230:1: C901 'GenerateOutput' is too complex (34)
./gyp/pylib/gyp/xcode_emulation.py:571:5: C901 'XcodeSettings.GetCflags' is too complex (32)
./gyp/pylib/gyp/input.py:2529:1: C901 'ProcessListFiltersInDict' is too complex (27)
./gyp/pylib/gyp/generator/ninja.py:1057:5: C901 'NinjaWriter.WriteSourcesForArch' is too complex (25)
./gyp/pylib/gyp/generator/xcode.py:138:5: C901 'XcodeProject.Finalize1' is too complex (25)
./gyp/pylib/gyp/generator/ninja.py:378:5: C901 'NinjaWriter.WriteSpec' is too complex (24)
./gyp/pylib/gyp/MSVSNew.py:230:5: C901 'MSVSSolution.Write' is too complex (21)
./gyp/pylib/gyp/input.py:2974:1: C901 'Load' is too complex (21)
./gyp/pylib/gyp/generator/ninja.py:686:5: C901 'NinjaWriter.WriteRules' is too complex (21)
16    C901 'GenerateOutput' is too complex (101)

Coincidence: Our most complex function has a McCabe complexity of 101 and this is issue #101.

@cclauss cclauss added enhancement New feature or request help wanted Extra attention is needed labels Mar 31, 2021
@cclauss
Copy link
Contributor Author

cclauss commented Feb 21, 2023

This setting is also in the tool.ruff.mccabe.max-complexity variable of our pyproject.toml file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant