nodejs / nodejs/gyp-next

Reduce the cyclomatic complexity of our Python code

Open
#101 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
Python
Stars
155
Forks
101
Avg merge
6d 2h
Merged PRs (30d)
4

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with gyp/pylib/gyp/generator/xcode.py and the 739-line GenerateOutput function, or choose another function from the listed complexity report. Establish strong tests before changing the selected function, then run the existing test suite and complexity check. Done means reduced cyclomatic complexity with behavior preserved and changes limited to one file.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.