I ran this tool on Keystone and liked the results - the two methods that
ranked D should certainly be refactored. It also matched a few methods in
openstack/common.

But flake8 supports complexity checking already, using mccabe. Just enable
complexity checking with:

  $ flake8 --max-complexity 20

It seems to function about the same as radon + xenon, where a D in that
tool is about a --max-complexity of 22. And flake8 obeys our existing tox
directives (such as ignoring openstack/common).

+1 for enabling complexity checking though.

On Thu, Oct 16, 2014 at 10:11 PM, Angus Salkeld <asalk...@mirantis.com>
wrote:

> Hi all
>
> I came across some tools [1] & [2] that we could use to make sure we don't
> increase our code complexity.
>
> Has anyone had any experience with these or other tools?
>
> radon is the underlying reporting tool and xenon is a "monitor" - meaning
> it will fail if a threshold is reached.
>
> To save you the time:
> radon cc -nd heat
> heat/engine/stack.py
>     M 809:4 Stack.delete - E
>     M 701:4 Stack.update_task - D
> heat/engine/resources/server.py
>     M 738:4 Server.handle_update - D
>     M 891:4 Server.validate - D
> heat/openstack/common/jsonutils.py
>     F 71:0 to_primitive - D
> heat/openstack/common/config/generator.py
>     F 252:0 _print_opt - D
> heat/tests/v1_1/fakes.py
>     M 240:4 FakeHTTPClient.post_servers_1234_action - F
>
> It ranks the complexity from A (best) upwards, the command above (-nd)
> says only show D or worse.
> If you look at these methods they are getting out of hand and are
> becoming difficult to understand.
> I like the idea of having a threshold that says we are not going to just
> keep adding to the complexity
> of these methods.
>
> This can be enforced with:
> xenon --max-absolute E heat
> ERROR:xenon:block "heat/tests/v1_1/fakes.py:240 post_servers_1234_action"
> has a rank of F
>
> [1] https://pypi.python.org/pypi/radon
> [2] https://pypi.python.org/pypi/xenon
>
> If people are open to this, I'd like to add these to the test-requirements
> and trial this in Heat
> (as part of the pep8 tox target).
>
> Regards
> Angus
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev@lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
>
_______________________________________________
OpenStack-dev mailing list
OpenStack-dev@lists.openstack.org
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

Reply via email to