<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 16, 2014 at 8:53 PM, Morgan Fainberg <span dir="ltr"><<a href="mailto:morgan.fainberg@gmail.com" target="_blank">morgan.fainberg@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I agree we should use flake8 built-in if at all possible. I complexity checking will definitely help us in the long run keeping code maintainable.<br></blockquote><div><br></div><div>Well this is scary: </div><div><br></div><pre style="margin-top:0px;margin-bottom:0px;padding:5px 0px;font-family:'Bitstream Vera Sans Mono',monospace;font-size:13px;color:rgb(0,0,0)">./nova/virt/libvirt/driver.py:3736:1: C901 'LibvirtDriver._get_guest_config' is too complex (67)</pre><pre style="margin-top:0px;margin-bottom:0px;padding:5px 0px"><span style="color:rgb(34,34,34);font-family:arial;font-size:small;white-space:normal"><a href="http://git.openstack.org/cgit/openstack/nova/tree/nova/virt/libvirt/driver.py#n3736">http://git.openstack.org/cgit/openstack/nova/tree/nova/virt/libvirt/driver.py#n373</a></span></pre><pre style="margin-top:0px;margin-bottom:0px;padding:5px 0px">to</pre><pre style="margin-top:0px;margin-bottom:0px;padding:5px 0px"><font color="#1155cc" face="arial"><span style="white-space:normal"><u><a href="http://git.openstack.org/cgit/openstack/nova/tree/nova/virt/libvirt/driver.py#n4113">http://git.openstack.org/cgit/openstack/nova/tree/nova/virt/libvirt/driver.py#n4113</a></u></span></font></pre><div><span style="color:rgb(34,34,34);font-family:arial;font-size:small;white-space:normal"><br></span></div><div><span style="color:rgb(34,34,34);font-family:arial;font-size:small;white-space:normal"><br></span></div><div><span style="color:rgb(34,34,34);font-family:arial;font-size:small;white-space:normal"><br></span></div><div><span style="color:rgb(34,34,34);font-family:arial;font-size:small;white-space:normal">First step in fixing this, put a cap on it:<a href="goog_106984861"> </a></span><a href="https://review.openstack.org/129125">https://review.openstack.org/129125</a></div><div><span style="color:rgb(34,34,34);font-family:arial;font-size:small;white-space:normal"><br></span></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
+1 from me. <br>
<br>
<br>
—<br>
<span class=""><font color="#888888">Morgan Fainberg<br>
</font></span><span class="im"><br>
<br>
On October 16, 2014 at 20:45:35, Joe Gordon (<a href="mailto:joe.gordon0@gmail.com">joe.gordon0@gmail.com</a>) wrote:<br>
> On Thu, Oct 16, 2014 at 8:11 PM, Angus Salkeld<br>
</span><div class=""><div class="h5">> wrote:<br>
><br>
> > Hi all<br>
> ><br>
> > I came across some tools [1] & [2] that we could use to make sure we don't<br>
> > increase our code complexity.<br>
> ><br>
> > Has anyone had any experience with these or other tools?<br>
> ><br>
><br>
><br>
> Flake8 (and thus hacking) has built in McCabe Complexity checking.<br>
><br>
> flake8 --select=C --max-complexity 10<br>
><br>
> <a href="https://github.com/flintwork/mccabe" target="_blank">https://github.com/flintwork/mccabe</a><br>
> <a href="http://flake8.readthedocs.org/en/latest/warnings.html" target="_blank">http://flake8.readthedocs.org/en/latest/warnings.html</a><br>
><br>
> Example on heat: <a href="http://paste.openstack.org/show/121561" target="_blank">http://paste.openstack.org/show/121561</a><br>
> Example in nova (max complexity of 20):<br>
> <a href="http://paste.openstack.org/show/121562" target="_blank">http://paste.openstack.org/show/121562</a><br>
><br>
><br>
> ><br>
> > radon is the underlying reporting tool and xenon is a "monitor" - meaning<br>
> > it will fail if a threshold is reached.<br>
> ><br>
> > To save you the time:<br>
> > radon cc -nd heat<br>
> > heat/engine/stack.py<br>
> > M 809:4 Stack.delete - E<br>
> > M 701:4 Stack.update_task - D<br>
> > heat/engine/resources/server.py<br>
> > M 738:4 Server.handle_update - D<br>
> > M 891:4 Server.validate - D<br>
> > heat/openstack/common/jsonutils.py<br>
> > F 71:0 to_primitive - D<br>
> > heat/openstack/common/config/generator.py<br>
> > F 252:0 _print_opt - D<br>
> > heat/tests/v1_1/fakes.py<br>
> > M 240:4 FakeHTTPClient.post_servers_1234_action - F<br>
> ><br>
> > It ranks the complexity from A (best) upwards, the command above (-nd)<br>
> > says only show D or worse.<br>
> > If you look at these methods they are getting out of hand and are<br>
> > becoming difficult to understand.<br>
> > I like the idea of having a threshold that says we are not going to just<br>
> > keep adding to the complexity<br>
> > of these methods.<br>
> ><br>
> > This can be enforced with:<br>
> > xenon --max-absolute E heat<br>
> > ERROR:xenon:block "heat/tests/v1_1/fakes.py:240 post_servers_1234_action"<br>
> > has a rank of F<br>
> ><br>
> > [1] <a href="https://pypi.python.org/pypi/radon" target="_blank">https://pypi.python.org/pypi/radon</a><br>
> > [2] <a href="https://pypi.python.org/pypi/xenon" target="_blank">https://pypi.python.org/pypi/xenon</a><br>
> ><br>
> > If people are open to this, I'd like to add these to the test-requirements<br>
> > and trial this in Heat<br>
> > (as part of the pep8 tox target).<br>
> ><br>
><br>
> I think the idea of gating on complexity is a great idea and would like to<br>
> see nova adopt this as well. But why not just use flake8's built in stuff?<br>
><br>
><br>
> ><br>
> > Regards<br>
> > Angus<br>
> ><br>
> > _______________________________________________<br>
> > OpenStack-dev mailing list<br>
> > <a href="mailto:OpenStack-dev@lists.openstack.org">OpenStack-dev@lists.openstack.org</a><br>
> > <a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
> ><br>
> ><br>
> _______________________________________________<br>
> OpenStack-dev mailing list<br>
> <a href="mailto:OpenStack-dev@lists.openstack.org">OpenStack-dev@lists.openstack.org</a><br>
> <a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>