[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sbws/master] Add dev dependency to check unused code



commit f81b0e0aaaa22bce22fd11e668991f8cc9840a72
Author: juga0 <juga@xxxxxxxxxx>
Date:   Tue Sep 18 15:19:14 2018 +0000

    Add dev dependency to check unused code
    
    remove included script that does that
---
 scripts/maint/find-dead-funcs | 81 -------------------------------------------
 setup.py                      |  3 +-
 2 files changed, 2 insertions(+), 82 deletions(-)

diff --git a/scripts/maint/find-dead-funcs b/scripts/maint/find-dead-funcs
deleted file mode 100755
index aa81d68..0000000
--- a/scripts/maint/find-dead-funcs
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/usr/bin/env bash
-
-SOURCE_DIR=sbws
-TESTS_DIR=tests
-
-UNUSED_LOG=unused-funcs.txt
-USED_LOG=used-funcs.txt
-
-cat > $USED_LOG <<EOF
-# This file was generated by a script on $(date).
-# It is not going to be perfectly accurate.
-# For example, it thinks that all @property are functions that are never called.
-EOF
-cp $USED_LOG $UNUSED_LOG
-
-function get_all_funcs {
-    # Finds all unique function names in $SOURCE_DIR.
-    # Both of the following functions 'foo' and 'bar' will be found and
-    # returned
-    #     def foo(a, b='c'):
-    #         pass
-    #     class Something:
-    #         def bar(self):
-    #             pass
-    find "$SOURCE_DIR" -type f -name '*.py' |
-        xargs grep --only-matching -E 'def [A-Za-z0-9_]+\(' |
-        cut -d ' ' -f 2 |
-        cut -d '(' -f 1 |
-        sort -u
-}
-
-function conditionally_print_usage_info {
-    # Expects a FUNC name as the only argument.
-    # Expects a stream of FILENAME:COUNT pairs on stdin.
-    #
-    # If a FILENAME has FUNC in it one time or less, it assumes it is unused
-    # and does nothing.
-    #
-    # If a FILENAME has FUNC in it more than once, then it prints FILENAME and
-    # goes on to print the exact lines that have the function on them.
-    FUNC="$1"
-    while read ITEM
-    do
-        FILENAME="$(echo "$ITEM" | cut -d ':' -f 1)"
-        COUNT="$(echo "$ITEM" | cut -d ':' -f 2)"
-        (( "$COUNT" <= 1 )) && continue
-        printf "    %s\n" $ITEM
-        grep --line-number -E "${FUNC}\(" "$FILENAME" |
-            while read USAGE
-            do
-                printf "        %s\n" "$USAGE"
-            done
-    done
-}
-
-function get_func_usage_count {
-    # Expects a stream of function names on stdin.
-    #
-    # Finds out whether or not a function is **probably** used or not by
-    # calling conditionally_print_usage_info and capturing its output. If there
-    # is no output, then the function is assumed to be unused and put into the
-    # UNUSED_LOG. Otherwise put its info in the USED_LOG.
-    PY_FILES=( $(find "$SOURCE_DIR" "$TESTS_DIR" -type f -name '*.py') )
-    while read FUNC
-    do
-        USAGE_INFO="$(grep --count -E "${FUNC}\(" "${PY_FILES[@]}" |
-            conditionally_print_usage_info ${FUNC})"
-        if [[ "$USAGE_INFO" == "" ]]
-        then
-            echo "$FUNC" >> $UNUSED_LOG
-        else
-            echo "$FUNC" >> $USED_LOG
-            echo "$USAGE_INFO" >> $USED_LOG
-        fi
-    done
-}
-
-echo "Writing unused function names to $UNUSED_LOG"
-echo "Writing used function names and information to $USED_LOG"
-
-get_all_funcs | get_func_usage_count
diff --git a/setup.py b/setup.py
index 9db8731..d704d92 100755
--- a/setup.py
+++ b/setup.py
@@ -81,7 +81,8 @@ setup(
         "git+https://git.torproject.org/stem.git#egg=stem-1.6.0.dev0";,
     ],
     extras_require={
-        'dev': ['flake8'],
+        # vulture: find unused code
+        'dev': ['flake8', 'vulture'],
         'test': ['tox', 'pytest', 'coverage'],
         # recommonmark: to make sphinx render markdown
         'doc': ['sphinx', 'recommonmark', 'pylint'],



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits