[tor-commits] [tor/master] Improve #include counting func and move it to metrics.py.

nickm at torproject.org nickm at torproject.org
Wed Mar 13 13:30:09 UTC 2019


commit 371ea65c080471cb6e1a57d9f78e5beaaa4212b8
Author: George Kadianakis <desnacked at riseup.net>
Date:   Wed Feb 27 17:05:00 2019 +0200

    Improve #include counting func and move it to metrics.py.
---
 scripts/maint/practracker/metrics.py     | 8 ++++++++
 scripts/maint/practracker/practracker.py | 5 +----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/scripts/maint/practracker/metrics.py b/scripts/maint/practracker/metrics.py
index 43ec3f809..525a05840 100644
--- a/scripts/maint/practracker/metrics.py
+++ b/scripts/maint/practracker/metrics.py
@@ -8,6 +8,14 @@ def file_len(f):
         pass
     return i + 1
 
+def get_include_count(f):
+    """Get number of #include statements in the file"""
+    include_count = 0
+    for line in f:
+        if re.match(r' *# *include', line):
+            include_count += 1
+    return include_count
+
 def function_lines(f):
     """
     Return iterator which iterates over functions and returns (function name, function lines)
diff --git a/scripts/maint/practracker/practracker.py b/scripts/maint/practracker/practracker.py
index c95c432c3..c3b8a9783 100755
--- a/scripts/maint/practracker/practracker.py
+++ b/scripts/maint/practracker/practracker.py
@@ -57,10 +57,7 @@ def consider_file_size(fname, f, exceptions_str):
         print_violation_if_not_exception(violation_str, exceptions_str)
 
 def consider_includes(fname, f, exceptions_str):
-    include_count = 0
-    for _, line in enumerate(f):
-        if line.startswith("#include "):
-            include_count += 1
+    include_count = metrics.get_include_count(f)
 
     if include_count > MAX_INCLUDE_COUNT:
         violation_str = "violation include-count %s %d" % (fname, include_count)





More information about the tor-commits mailing list