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 should enforce complexity checks #34

Closed
webknjaz opened this issue Dec 26, 2020 · 2 comments
Closed

flake8 should enforce complexity checks #34

webknjaz opened this issue Dec 26, 2020 · 2 comments

Comments

@webknjaz
Copy link
Contributor

flake8 supports checking the McCabe complexity metric but it's historically disabled by default.
https://flake8.pycqa.org/en/2.5.5/#quickstart and https://en.wikipedia.org/wiki/Cyclomatic_complexity suggest that it's recommended to set max-complexity=10 in the config.

I use it in many projects and I like how it helps to keep the code simple. Of course, it's harder to apply this against a legacy codebase but it's worth it. In case, when there's many violations, the strategy I normally use is applying it gradually: you can use per-file-ignores for temporary module-global exclusions and noqa markers when it makes sense to be more granular, and then I eliminate each of those over time.

P.S. There's other complexity checks that are provided via third-party plugins but cyclomatic complexity is a good start. See https://sobolevn.me/2019/10/complexity-waterfall.

@webknjaz
Copy link
Contributor Author

Here's a demo of what it'd mean for setuptools: pypa/setuptools#2518.

@jaraco
Copy link
Owner

jaraco commented Jan 9, 2021

Yes. Sounds good.

@jaraco jaraco closed this as completed in cc05202 Jan 9, 2021
jaraco added a commit that referenced this issue Jan 9, 2021
jaraco added a commit that referenced this issue Jan 9, 2021
* Use `extend-ignore` in flake8 config

This option allows to add extra ignored rules to the default list
instead of replacing it.

The default exclusions are: E121, E123, E126, E226, E24, E704,
W503 and W504.

Fixes #28.

Refs:
* https://github.com/pypa/setuptools/pull/2486/files#r541943356
* https://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-extend-ignore
*
https://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-ignore

* Enable complexity limit. Fixes #34.

* Replace pep517.build with build (#37)

* Replace pep517.build with build

Resolves #30

* Prefer simple usage

Co-authored-by: Jason R. Coombs <[email protected]>

* Use license_files instead of license_file in meta (#35)

Singular `license_file` is deprecated since wheel v0.32.0.

Refs:
* https://wheel.readthedocs.io/en/stable/news.html
* https://wheel.readthedocs.io/en/stable/user_guide.html#including-license-files-in-the-generated-wheel-file

Co-authored-by: Jason R. Coombs <[email protected]>
clrpackages pushed a commit to clearlinux-pkgs/setuptools that referenced this issue Jan 19, 2021
…on 51.3.3

Daniel Moore (1):
      Clarify Development Mode first paragraph

Drew (1):
      docs (build_meta): fix spelling mistake

Dustin Ingram (3):
      Move helper method out of class
      Add failing test
      Correctly handle normalized tags

Henry Schreiner (1):
      fix: suggest PyPA build instead of pep517.build

Jason R. Coombs (22):
      pre-commit autoupdate
      Rename 'Automated Tests' to simply 'tests'
      Add note about automatic merging of PRs and the requirements and limitations.
      Prefer pytest-enabler to jaraco.test
      Enable complexity limit. Fixes jaraco/skeleton#34.
      Add support for namespace packages. Closes jaraco/skeleton#40.
      Avoid hitting network during test_easy_install
      Point changelog at 2534 for more info
      Bump version: 51.1.2 → 51.2.0
      Point changelog at 2534 for more info
      Disable PIP_NO_INDEX for tests that override the index. Ref #2534.
      Exclude _distutils from flake8 also.
      Rely on tuple argument to endswith
      Remove unused variable
      Quick fix for #1390. Now description cannot contain a newline.
      Bump version: 51.2.0 → 51.3.0
      Revert "Merge pull request #2533 from pypa/fix/2529"
      Bump version: 51.3.0 → 51.3.1
      Repair Descriptions with newlines and emit a warning that the value will be disallowed in the future.
      Bump version: 51.3.1 → 51.3.2
      Fix AttributeError in Description validation. Fixes #2539.
      Bump version: 51.3.2 → 51.3.3

Jonathan E (1):
      Fix code typo in entry_point.rst

Miro Hrončok (1):
      Define create_module()/exec_module() in VendorImporter

Petr Viktorin (1):
      Avoid deprecated load_module() in pkg_resources namespace delaration

Sviatoslav Sydorenko (23):
      Migrate to `extend-exclude` in flake8 config
      Exclude `build/lib/` artifacts in flake8 config
      Fix misplaced/mistyped per-file-ignores in flake8
      Drop non-existing site-patch.py from flake8
      Drop unmached py*compat.py ignore rule from flake8
      Use `extend-ignore` in flake8 config
      Use license_files instead of license_file in meta
      Simplify `setuptools.archive_util.unpack_tarfile`
      Simplify `easy_install.install_eggs`
      Simplify `easy_install.update_pth`
      Simplify `command.easy_install.get_site_dirs`
      Simplify `command.easy_install.expand_paths`
      Simplify `egg_info.FileList.process_template_line`
      Simplify `dist.Distribution._parse_config_files`
      Simplify `setuptools.glob._iglob`
      Simplify `setuptools.installer.fetch_build_egg`
      Simplify `msvc.SystemInfo.find_reg_vs_vers`
      Simplify `PackageIndex.process_index`
      Apply noqa C901 comments to overly complex code
      Enable McCabe complexity check in flake8
      Replace pep517.build with build (#37)
      Use license_files instead of license_file in meta (#35)
      Use `extend-ignore` in flake8 config (#33)

Tim Hatch (2):
      Failing test for #2489
      Find .egg-info in zipimport too

YuanPei Li (3):
      fix typo
      Create 2525.doc.rst
      Update 2525.doc.rst
clrpackages pushed a commit to clearlinux-pkgs/keyring that referenced this issue Jan 26, 2021
…22.0.0

Jason R. Coombs (9):
      Rename 'Automated Tests' to simply 'tests'
      Add note about automatic merging of PRs and the requirements and limitations.
      Prefer pytest-enabler to jaraco.test
      Remove legacy __metaclass__
      Enable complexity limit. Fixes jaraco/skeleton#34.
      Refactor cli.CommandLineTool.run for simplicity.
      Switch to argparse
      Remove output_password, no longer used for its intended purpose.
      Rename macOS backend to reflect the modern name inclusive of macOS 11.

Sviatoslav Sydorenko (3):
      Replace pep517.build with build (#37)
      Use license_files instead of license_file in meta (#35)
      Use `extend-ignore` in flake8 config (#33)
clrpackages pushed a commit to clearlinux-pkgs/portend that referenced this issue Feb 16, 2021
….7.1

Jason R. Coombs (14):
      Honor TOX_WORK_DIR if set. Workaround for tox-dev/tox#20.
      Collapse skeleton history from archive/2020-12
      Update skeleton description to describe the periodic collapse. Fixes #27.
      Enable automerge
      Automatically inject project name in docs heading.
      pre-commit autoupdate
      Rename 'Automated Tests' to simply 'tests'
      Add note about automatic merging of PRs and the requirements and limitations.
      Prefer pytest-enabler to jaraco.test
      Enable complexity limit. Fixes jaraco/skeleton#34.
      Add support for namespace packages. Closes jaraco/skeleton#40.
      Normalize indentation
      ⚫ Fade to black.
      Update changelog.

Sviatoslav Sydorenko (3):
      Replace pep517.build with build (#37)
      Use license_files instead of license_file in meta (#35)
      Use `extend-ignore` in flake8 config (#33)

vasyl_lukashuk (1):
      Fix error message
clrpackages pushed a commit to clearlinux-pkgs/pytest-runner that referenced this issue Feb 16, 2021
…on 5.3.0

Diego Elio Pettenò (1):
      Fix README (and thus long_description).

Hugo (1):
      Fix AppVeyor typo

Hugo van Kemenade (2):
      Spelling and capitalisation (#8)
      Link badge to PyPI rather than static image

Jason R. Coombs (75):
      Add Tidelift template
      Rely on alabaster theme to support sidebar rendering.
      Use nicer, simpler phrasing
      Add support for automatic publishing of release notes
      Use technique for environment passing matching that found in jaraco/skeleton
      Move Tidelift token into Travis configuration
      Update badge URL
      Add funding reference to project
      List sidebars to avoid errors looking for template 't'
      Python 3 only
      Test/release on Python 3.8
      Apply black to docs/conf.py
      Update black version and links
      Expect flake8 3.6 or later and remove suppression of warnings from Flake8 prior to 3.6.
      Rely on pytest-checkdocs 1.2.3, eliminating workaround for docutils warning.
      Remove workaround for gitlab.com/PyCQA/flake8/issues/275, apparently no longer necessary.
      Normalize indentation
      Include keyring support from twine
      Rename 'build-docs' to simply 'docs' (matching more popular convention).
      Prefer 'path' to 'path.py'
      Cover Python 3.8 in Windows tests
      Update black in pre-commit and add blacken-docs.
      Test and release using Azure Pipelines
      Correct guidance on project creation.
      Rely on setuptools_scm 3.4 and setuptools 42. Now setup.py is optional. Remove setuptools from test environment.
      Finish dropping support for Python 2 (I hope).
      Normalize whitespace
      Revert "setup.cfg: let python-tag mirror python_requires"
      Update to bionic for Travis. Correct comment about IPv6 workaround.
      Suppress warnings in pytest-flake8, pytest-black, and pytest-checkdocs.
      Prefer pytest-black to pytest-black-multipy
      Test against Windows and Mac
      Define a default pool_vm_image
      Remove tox-venv and tox-pip-version. Tox-venv is discouraged (tox-dev/tox-venv#48 (comment)) and tox-pip-version was only there to support tox-venv. venv is dead; long live virtualenv.
      Remove more references to tox-venv
      Add workaround for warning emitted when junitxml is used. Ref pytest-dev/pytest#6178.
      Include mypy for type checking during tests.
      Ensure virtualenv is upgraded when installing tox. Fixes jaraco/path#188.
      Run tests on prereleases of Python on Windows. Fixes jaraco/skeleton#17.
      Add workaround for python/mypy#8627. Fixes jaraco/skeleton#18.
      Add 'refresh.svg' demonstrating an example of refreshing a project with the latest skeleton. Ref #7.
      Move workaround for python/mypy#8627 to tox.ini, as adding it to setup.cfg prevents releases to PyPI. Fixes jaraco/skeleton#19.
      Remove workaround for python/mypy#8627. Ref jaraco/skeleton#18.
      Create Github releases when releasing the package. Fixes jaraco/skeleton#23.
      Moved refresh.svg to another branch. Reference the animation from the docs. Ref jaraco/skeleton#7.
      Add the env var mapping too.
      Disable pytest-black and pytest-mypy on PyPy. Fixes jaraco/skeleton#22. Ref pytest-dev/pytest#7675.
      Bump black and blacken-docs to latest stable versions.
      Use enabled plugin configuration to enable mypy and black when the plugin is present. Ref jaraco/skeleton#22.
      Also enable flake8 and cov when the plugins are present.
      Add workflows for running tests. Ref jaraco/skeleton#24.
      Cut releases from Github Actions instead of Azure Pipelines. Ref jaraco/skeleton#24.
      Refresh docs to prefer Github Actions to Azure Pipelines. Ref jaraco/skeleton#24.
      Use RTD v2 config
      Test on Python 3.9. Skip 3.7 to avoid creating too many builds. Release on 3.9.
      Drop tests on Travis, Appveyor, and Azure Pipelines.
      use add-github-secrets, which infers the secrets needed from the github workflow.
      Use inline flags with local scope.
      Honor TOX_WORK_DIR if set. Workaround for tox-dev/tox#20.
      Collapse skeleton history from archive/2020-12
      Update skeleton description to describe the periodic collapse. Fixes #27.
      Enable automerge
      Automatically inject project name in docs heading.
      pre-commit autoupdate
      Rename 'Automated Tests' to simply 'tests'
      Add note about automatic merging of PRs and the requirements and limitations.
      Prefer pytest-enabler to jaraco.test
      Enable complexity limit. Fixes jaraco/skeleton#34.
      Add support for namespace packages. Closes jaraco/skeleton#40.
      Normalize indentation
      ⚫ Fade to black.
      Update changelog.
      Suppress test failures on Windows
      Use short link for issue
      Replace rwt with pip-run

Sviatoslav Sydorenko (3):
      Replace pep517.build with build (#37)
      Use license_files instead of license_file in meta (#35)
      Use `extend-ignore` in flake8 config (#33)

Vincent Fazio (1):
      setup.cfg: let python-tag mirror python_requires

johnthagen (1):
      Line wrap LICENSE file

layday (1):
      Require toml extra for setuptools_scm (#12)
clrpackages pushed a commit to clearlinux-pkgs/jaraco.functools that referenced this issue Feb 16, 2021
…version 3.2.0

Jason R. Coombs (9):
      Automatically inject project name in docs heading.
      pre-commit autoupdate
      Rename 'Automated Tests' to simply 'tests'
      Add note about automatic merging of PRs and the requirements and limitations.
      Prefer pytest-enabler to jaraco.test
      Enable complexity limit. Fixes jaraco/skeleton#34.
      Add support for namespace packages. Closes jaraco/skeleton#40.
      Switch to PEP 420 namespace package
      Disable doctests as workaround for pytest-dev/pytest#3396.

Sviatoslav Sydorenko (3):
      Replace pep517.build with build (#37)
      Use license_files instead of license_file in meta (#35)
      Use `extend-ignore` in flake8 config (#33)
clrpackages pushed a commit to clearlinux-pkgs/zipp that referenced this issue Mar 9, 2021
Jason R. Coombs (18):
      Use inline flags with local scope.
      Honor TOX_WORK_DIR if set. Workaround for tox-dev/tox#20.
      Collapse skeleton history from archive/2020-12
      Update skeleton description to describe the periodic collapse. Fixes #27.
      Enable automerge
      Automatically inject project name in docs heading.
      pre-commit autoupdate
      Rename 'Automated Tests' to simply 'tests'
      Add note about automatic merging of PRs and the requirements and limitations.
      Prefer pytest-enabler to jaraco.test
      Enable complexity limit. Fixes jaraco/skeleton#34.
      Add support for namespace packages. Closes jaraco/skeleton#40.
      Disable 2020-resolver. Workaround for pypa/pip#9143.
      Normalize indentation
      Exclude dist from discovered packages. Fixes jaraco/skeleton#46.
      It's no longer necessary to filter this warning and it's not a warning anymore.
      Bump minimum pytest
      Update changelog.

KOLANICH (1):
      Added an .editorconfig. Pull request jaraco/skeleton#43.

Sviatoslav Sydorenko (3):
      Replace pep517.build with build (#37)
      Use license_files instead of license_file in meta (#35)
      Use `extend-ignore` in flake8 config (#33)
clrpackages pushed a commit to clearlinux-pkgs/tempora that referenced this issue Apr 6, 2021
….0.2

Jason R. Coombs (16):
      Honor TOX_WORK_DIR if set. Workaround for tox-dev/tox#20.
      Collapse skeleton history from archive/2020-12
      Update skeleton description to describe the periodic collapse. Fixes #27.
      Enable automerge
      Automatically inject project name in docs heading.
      pre-commit autoupdate
      Rename 'Automated Tests' to simply 'tests'
      Add note about automatic merging of PRs and the requirements and limitations.
      Prefer pytest-enabler to jaraco.test
      Enable complexity limit. Fixes jaraco/skeleton#34.
      Add support for namespace packages. Closes jaraco/skeleton#40.
      Use pytest.mark to selectively skip test.
      Normalize indentation
      Exclude dist from discovered packages. Fixes jaraco/skeleton#46.
      Update changelog.
      Revert "Use pytest.mark to selectively skip test."

KOLANICH (1):
      Added an .editorconfig. Pull request jaraco/skeleton#43.

Sviatoslav Sydorenko (3):
      Replace pep517.build with build (#37)
      Use license_files instead of license_file in meta (#35)
      Use `extend-ignore` in flake8 config (#33)
clrpackages pushed a commit to clearlinux-pkgs/jaraco.text that referenced this issue Aug 19, 2021
…on 3.5.1

Brian Rutledge (1):
      Use shutil for rmtree

Hugo (1):
      Fix AppVeyor typo

Hugo van Kemenade (2):
      Spelling and capitalisation (#8)
      Link badge to PyPI rather than static image

Jason R. Coombs (74):
      Python 3 only
      Cover Python 3.8 in Windows tests
      Update black in pre-commit and add blacken-docs.
      Test and release using Azure Pipelines
      Correct guidance on project creation.
      Rely on setuptools_scm 3.4 and setuptools 42. Now setup.py is optional. Remove setuptools from test environment.
      Finish dropping support for Python 2 (I hope).
      Normalize whitespace
      Revert "setup.cfg: let python-tag mirror python_requires"
      Update to bionic for Travis. Correct comment about IPv6 workaround.
      Suppress warnings in pytest-flake8, pytest-black, and pytest-checkdocs.
      Prefer pytest-black to pytest-black-multipy
      Test against Windows and Mac
      Define a default pool_vm_image
      Remove tox-venv and tox-pip-version. Tox-venv is discouraged (tox-dev/tox-venv#48 (comment)) and tox-pip-version was only there to support tox-venv. venv is dead; long live virtualenv.
      Remove more references to tox-venv
      Add workaround for warning emitted when junitxml is used. Ref pytest-dev/pytest#6178.
      Include mypy for type checking during tests.
      Ensure virtualenv is upgraded when installing tox. Fixes jaraco/path#188.
      Run tests on prereleases of Python on Windows. Fixes jaraco/skeleton#17.
      Add workaround for python/mypy#8627. Fixes jaraco/skeleton#18.
      Add 'refresh.svg' demonstrating an example of refreshing a project with the latest skeleton. Ref #7.
      Move workaround for python/mypy#8627 to tox.ini, as adding it to setup.cfg prevents releases to PyPI. Fixes jaraco/skeleton#19.
      Remove workaround for python/mypy#8627. Ref jaraco/skeleton#18.
      Create Github releases when releasing the package. Fixes jaraco/skeleton#23.
      Moved refresh.svg to another branch. Reference the animation from the docs. Ref jaraco/skeleton#7.
      Add the env var mapping too.
      Disable pytest-black and pytest-mypy on PyPy. Fixes jaraco/skeleton#22. Ref pytest-dev/pytest#7675.
      Bump black and blacken-docs to latest stable versions.
      Use enabled plugin configuration to enable mypy and black when the plugin is present. Ref jaraco/skeleton#22.
      Also enable flake8 and cov when the plugins are present.
      Add workflows for running tests. Ref jaraco/skeleton#24.
      Cut releases from Github Actions instead of Azure Pipelines. Ref jaraco/skeleton#24.
      Refresh docs to prefer Github Actions to Azure Pipelines. Ref jaraco/skeleton#24.
      Use RTD v2 config
      🧎‍♀️ Genuflect to the types.
      Remove compatibility code.
      Update changelog.
      Test on Python 3.9. Skip 3.7 to avoid creating too many builds. Release on 3.9.
      Drop tests on Travis, Appveyor, and Azure Pipelines.
      use add-github-secrets, which infers the secrets needed from the github workflow.
      Use inline flags with local scope.
      Honor TOX_WORK_DIR if set. Workaround for tox-dev/tox#20.
      Collapse skeleton history from archive/2020-12
      Update skeleton description to describe the periodic collapse. Fixes #27.
      Enable automerge
      Add trim methods to WordSet
      🧎‍♀️ Genuflect to the types.
      Automatically inject project name in docs heading.
      pre-commit autoupdate
      Rename 'Automated Tests' to simply 'tests'
      Add note about automatic merging of PRs and the requirements and limitations.
      Prefer pytest-enabler to jaraco.test
      Enable complexity limit. Fixes jaraco/skeleton#34.
      Add support for namespace packages. Closes jaraco/skeleton#40.
      Normalize indentation
      Rely on PEP 420 for namespace package
      Update changelog.
      Exclude dist from discovered packages. Fixes jaraco/skeleton#46.
      It's no longer necessary to filter this warning and it's not a warning anymore.
      Bump minimum pytest
      Require twine 3 with keyring unconditionally required.
      Add comments indicating why the exclusions are present
      Exclude mypy on Python 3.10 as workaround for python/typed_ast#156.
      Bump minimums on pytest-checkdocs and pytest-enabler as found on Setuptools.
      Also deny black on Python 3.10 as workaround for python/typed_ast#156.
      Add leading */ to coverage.run.omit. Workaround for pytest-dev/pytest-cov#456.
      Remove automerge. Fixes jaraco/skeleton#49.
      Enable dependabot (#50)
      Replace md file with badge linking to documentation site. Fixes jaraco/skeleton#47.
      Test on Python 3.10
      Remove setup_requires, obviated by build-requires in pyproject.toml.
      Suppress deprecation warnings in flake8 and packaging.tags. Ref pypa/packaging#433.
      Fix syntax for in_. Closes #5.

KOLANICH (1):
      Added an .editorconfig. Pull request jaraco/skeleton#43.

Sviatoslav Sydorenko (4):
      Replace pep517.build with build (#37)
      Use license_files instead of license_file in meta (#35)
      Use `extend-ignore` in flake8 config (#33)
      Make sphinx fail on any warnings (#36)

Vincent Fazio (1):
      setup.cfg: let python-tag mirror python_requires

johnthagen (1):
      Line wrap LICENSE file

layday (1):
      Require toml extra for setuptools_scm (#12)
jaraco added a commit to jaraco/jaraco.vcs that referenced this issue Jun 20, 2023
* Use `extend-ignore` in flake8 config

This option allows to add extra ignored rules to the default list
instead of replacing it.

The default exclusions are: E121, E123, E126, E226, E24, E704,
W503 and W504.

Fixes #28.

Refs:
* https://github.com/pypa/setuptools/pull/2486/files#r541943356
* https://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-extend-ignore
*
https://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-ignore

* Enable complexity limit. Fixes jaraco/skeleton#34.

* Replace pep517.build with build (#37)

* Replace pep517.build with build

Resolves #30

* Prefer simple usage

Co-authored-by: Jason R. Coombs <[email protected]>

* Use license_files instead of license_file in meta (#35)

Singular `license_file` is deprecated since wheel v0.32.0.

Refs:
* https://wheel.readthedocs.io/en/stable/news.html
* https://wheel.readthedocs.io/en/stable/user_guide.html#including-license-files-in-the-generated-wheel-file

Co-authored-by: Jason R. Coombs <[email protected]>
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 a pull request may close this issue.

2 participants