setup.py: Re-add 'pylint' subcommand
We drop our hacky shell wrappers, and just track it all in setup.py
This commit is contained in:
parent
927bcc11cd
commit
aead0135b0
54
setup.py
54
setup.py
|
@ -1,5 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# pylint: disable=W0201
|
||||
# Attribute defined outside __init__: custom commands require breaking this
|
||||
|
||||
import glob
|
||||
import fnmatch
|
||||
import os
|
||||
|
@ -393,6 +396,56 @@ class TestURLFetch(TestBaseCommand):
|
|||
TestBaseCommand.run(self)
|
||||
|
||||
|
||||
class CheckPylint(Command):
|
||||
user_options = []
|
||||
description = "Check code using pylint and pep8"
|
||||
|
||||
def initialize_options(self):
|
||||
pass
|
||||
def finalize_options(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
files = ["setup.py", "virt-install", "virt-clone", "virt-image",
|
||||
"virt-convert", "virt-manager", "virt-manager-tui",
|
||||
"virtcli", "virtinst", "virtconv", "virtManager",
|
||||
"virtManagerTui", "tests"]
|
||||
|
||||
output_format = sys.stdout.isatty() and "colorized" or "text"
|
||||
pylint_skip = [
|
||||
"Design", # Things like 'too many arguments'
|
||||
"C0103", # C0103: Name doesn't match some style regex
|
||||
"C0111", # C0111: No docstring
|
||||
"C0301", # C0301: Line too long
|
||||
"C0302", # C0302: Too many lines in module
|
||||
"I0011", # I0011: Warn about locally disabled pylint msgs
|
||||
"R0201", # R0201: Method could be a function
|
||||
|
||||
"W0142", # W0142: *Used * or ** magic*
|
||||
"W0603", # W0603: Using the global statement
|
||||
"W0702", # W0702: No exception type specified for 'catch'
|
||||
"W0703", # W0703: Catch 'Exception'
|
||||
|
||||
|
||||
# May be useful to enable someday
|
||||
"W0511", # W0511: FIXME and XXX: messages
|
||||
"Similarities", # Finds duplicate code
|
||||
]
|
||||
|
||||
cmd = "pylint "
|
||||
cmd += "--ignore scriptimports "
|
||||
cmd += "--reports=n "
|
||||
cmd += "--output-format=%s " % output_format
|
||||
cmd += "--dummy-variables-rgx=\"ignore.*|.*_ignore\" "
|
||||
cmd += "--additional-builtins=_ "
|
||||
|
||||
for s in pylint_skip:
|
||||
cmd += "--disable=%s " % s
|
||||
cmd += " ".join(files)
|
||||
|
||||
os.system(cmd)
|
||||
|
||||
|
||||
setup(
|
||||
name = "virt-manager",
|
||||
version = cliconfig.__version__,
|
||||
|
@ -451,6 +504,7 @@ setup(
|
|||
|
||||
'configure': configure,
|
||||
|
||||
'pylint': CheckPylint,
|
||||
'rpm': my_rpm,
|
||||
'test': TestCommand,
|
||||
'test_urls' : TestURLFetch,
|
||||
|
|
|
@ -1,185 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# pylint doesn't work well with a file named xxx.py.xxx
|
||||
cp src/virt-manager.py.in src/_virt-manager
|
||||
cp src/virt-manager-tui.py.in src/_virt-manager-tui
|
||||
|
||||
cd src || exit 1
|
||||
|
||||
IGNOREFILES=""
|
||||
|
||||
##################
|
||||
# pylint Section #
|
||||
##################
|
||||
|
||||
PYLINT_FILES="virtManager/ _virt-manager virtManagerTui/ _virt-manager-tui"
|
||||
|
||||
# Deliberately ignored warnings:
|
||||
# Don't print pylint config warning
|
||||
NO_PYL_CONFIG=".*No config file found.*"
|
||||
|
||||
# Optional modules that may not be available
|
||||
UNABLE_IMPORT="Unable to import '(appindicator)"
|
||||
|
||||
# os._exit is needed for forked processes.
|
||||
OS_EXIT="protected member _exit of a client class"
|
||||
|
||||
GI_IMPORT="in module 'gi.repository'"
|
||||
|
||||
# False positives
|
||||
MAIN_NONETYPE="main:.*Raising NoneType while.*"
|
||||
STYLE_ATTACH="Class 'style' has no 'attach' member"
|
||||
VBOX_PACK="Class 'vbox' has no 'pack_start' member"
|
||||
|
||||
# Avahi API may have requirements on callback argument names, so ignore these
|
||||
# warnings
|
||||
BTYPE_LIST="(vmmConnect.add_service|vmmConnect.remove_service|vmmConnect.add_conn_to_list)"
|
||||
BUILTIN_TYPE="${BTYPE_LIST}.*Redefining built-in 'type'"
|
||||
|
||||
# Types can't be inferred errors
|
||||
INFER_LIST="(MenuItem|StatusIcon|.*storagePoolLookupByName)"
|
||||
INFER_ERRORS="Instance of '${INFER_LIST}.*not be inferred"
|
||||
|
||||
# Hacks for testing
|
||||
TEST_HACKS="protected member (_is_virtinst_test_uri|_open_test_uri)"
|
||||
|
||||
# cli/gui diff causes confusion
|
||||
STUBCLASS="Instance of 'stubclass'"
|
||||
DBUSINTERFACE="Instance of 'Interface'"
|
||||
|
||||
# Pylint can't tell sparkline has GtkWidget bits
|
||||
SPARKLINEWIDGET="Instance of '(CellRendererSparkline|Sparkline|AutoDrawer|OverBox|_errorDialog)' has no '(show|destroy|set_property|get_property|get_style_context|queue_draw|get_window|get_toplevel|set_child_packing|connect|get_realized|set_window|set_realized|get_parent_window|remove|add|queue_resize|get_events|get_visual|child_get_property|set_has_window|destroy|show_all|set_title|vbox|hide)'"
|
||||
|
||||
|
||||
DMSG=""
|
||||
skipmsg() {
|
||||
DMSG="${DMSG},$1"
|
||||
}
|
||||
|
||||
skipchecker() {
|
||||
DCHECKERS="${DCHECKERS},$1"
|
||||
}
|
||||
|
||||
skipmsg_checksupport() {
|
||||
out=`pylint --list-msgs 2>&1`
|
||||
if `echo $out | grep -q $1` ; then
|
||||
skipmsg "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Disabled unwanted messages
|
||||
skipmsg "C0103" # C0103: Name doesn't match some style regex
|
||||
skipmsg "C0111" # C0111: No docstring
|
||||
skipmsg "C0301" # C0301: Line too long
|
||||
skipmsg "C0302" # C0302: Too many lines in module
|
||||
skipmsg "R0201" # R0201: Method could be a function
|
||||
skipmsg "W1001" # W1001: Pylint can't tell that extending Gtk
|
||||
# classes allows use of 'property'
|
||||
skipmsg "W0141" # W0141: Complaining about 'map' and 'filter'
|
||||
skipmsg "W0142" # W0142: *Used * or ** magic*
|
||||
skipmsg "W0403" # W0403: Relative imports
|
||||
skipmsg "W0603" # W0603: Using the global statement
|
||||
skipmsg "W0702" # W0703: No exception type specified
|
||||
skipmsg "W0703" # W0703: Catch 'Exception'
|
||||
skipmsg "W0704" # W0704: Exception doesn't do anything
|
||||
skipchecker "Design" # Things like "Too many func arguments",
|
||||
# "Too man public methods"
|
||||
|
||||
# Potentially useful messages, disabled for now
|
||||
skipmsg "W0511" # W0511: FIXME and XXX: messages
|
||||
skipchecker "Similarities" # Finds duplicate code
|
||||
|
||||
# May want to enable this in the future
|
||||
SHOW_REPORT="n"
|
||||
|
||||
AWK=awk
|
||||
[ `uname -s` = 'SunOS' ] && AWK=nawk
|
||||
|
||||
format="colorized"
|
||||
[ ! -t 1 ] && format="text"
|
||||
|
||||
echo "Running pylint"
|
||||
pylint --ignore=$IGNOREFILES $PYLINT_FILES \
|
||||
--additional-builtins=_ \
|
||||
--reports=$SHOW_REPORT \
|
||||
--output-format=$format \
|
||||
--dummy-variables-rgx="dummy|ignore.*|.*_ignore" \
|
||||
--disable=${DMSG}\
|
||||
--disable=${DCHECKERS} 2>&1 | \
|
||||
egrep -ve "$NO_PYL_CONFIG" \
|
||||
-ve "$OS_EXIT" \
|
||||
-ve "$BUILTIN_TYPE" \
|
||||
-ve "$STUBCLASS" \
|
||||
-ve "$DBUSINTERFACE" \
|
||||
-ve "$MAIN_NONETYPE" \
|
||||
-ve "$TEST_HACKS" \
|
||||
-ve "$UNABLE_IMPORT" \
|
||||
-ve "$STYLE_ATTACH" \
|
||||
-ve "$VBOX_PACK" \
|
||||
-ve "$GI_IMPORT" \
|
||||
-ve "$SPARKLINEWIDGET" \
|
||||
-ve "$INFER_ERRORS" | \
|
||||
$AWK '\
|
||||
# Strip out any "*** Module name" lines if we dont list any errors for them
|
||||
BEGIN { found=0; cur_line="" }
|
||||
{
|
||||
if (found == 1) {
|
||||
if ( /\*\*\*/ ) {
|
||||
prev_line = $0
|
||||
} else {
|
||||
print prev_line
|
||||
print $0
|
||||
found = 0
|
||||
}
|
||||
} else if ( /\*\*\*/ ) {
|
||||
found = 1
|
||||
prev_line = $0
|
||||
} else {
|
||||
print $0
|
||||
}
|
||||
}'
|
||||
|
||||
################
|
||||
# pep8 section #
|
||||
################
|
||||
|
||||
SKIP_PEP8=""
|
||||
skip_pep8() {
|
||||
if [ ! -z ${SKIP_PEP8} ] ; then
|
||||
SKIP_PEP8="${SKIP_PEP8},"
|
||||
fi
|
||||
SKIP_PEP8="${SKIP_PEP8}$1"
|
||||
}
|
||||
|
||||
skip_pep8 "E121"
|
||||
skip_pep8 "E122"
|
||||
skip_pep8 "E124"
|
||||
skip_pep8 "E125"
|
||||
skip_pep8 "E126" # Continuation line indentation bits.
|
||||
skip_pep8 "E127" # doesn't work for function calls as parameters
|
||||
skip_pep8 "E128"
|
||||
|
||||
skip_pep8 "E203" # Space before : in dictionary defs
|
||||
skip_pep8 "E221" # Multiple spaces before operator (warns
|
||||
# about column aligning assigments
|
||||
skip_pep8 "E241" # Space after , column alignment nono
|
||||
skip_pep8 "E251" # No space around keyword
|
||||
skip_pep8 "E261" # 2 spaces before inline comment?
|
||||
skip_pep8 "E271" # Lining up 'foo = bar" statements
|
||||
skip_pep8 "E272" # Lining up 'from X import Y" statements
|
||||
|
||||
skip_pep8 "E301" # 1 blank line between methods
|
||||
skip_pep8 "E302" # 2 blank lines between function defs
|
||||
skip_pep8 "E303" # Too many blank lines
|
||||
skip_pep8 "E501" # Line too long
|
||||
|
||||
skip_pep8 "E711" # Comparison to False
|
||||
skip_pep8 "E712" # Comparison to None
|
||||
|
||||
echo "Running pep8"
|
||||
pep8 -r --exclude=$IGNOREFILES --ignore $SKIP_PEP8 \
|
||||
$PYLINT_FILES
|
||||
|
||||
cd - > /dev/null
|
||||
rm src/_virt-manager
|
||||
rm src/_virt-manager-tui
|
|
@ -1,206 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
FILES="setup.py tests/ virt-install virt-image virt-clone virt-convert virtinst/ virtconv virtconv/parsers/*.py"
|
||||
|
||||
# Don't print pylint config warning
|
||||
NO_PYL_CONFIG=".*No config file found.*"
|
||||
|
||||
# Exceptions: deliberately ignore these regex
|
||||
|
||||
# False positive: using the private excepthook is needed for custom exception
|
||||
# handler
|
||||
EXCEPTHOOK='__excepthook__'
|
||||
|
||||
# Following functions are in the public api which have argument names that
|
||||
# override builtin 'type'.
|
||||
BUILTIN_TYPE="(StoragePool.__init__|randomMAC|Capabilities.guestForOSType|acquireKernel|acquireBootDisk|DistroInstaller.__init__|PXEInstaller.__init__|Guest.list_os_variants|Guest.get_os_type_label|Guest.get_os_variant_label|FullVirtGuest.__init__|VirtualNetworkInterface.__init__|VirtualGraphics.__init__|Installer.__init__|Guest.__init__|LiveCDInstaller.__init__|ParaVirtGuest.__init__|VirtOptionParser.print_help|get_max_vcpus|setupLogging.exception_log|VirtualDisk.__init__|disk.__init__|netdev.__init__)|guest_lookup"
|
||||
BTYPE_TYPE="${BUILTIN_TYPE}.*Redefining built-in 'type'"
|
||||
|
||||
# Built-in type 'format'
|
||||
BUILTIN_FORMAT="(*Pool.__init__|*Volume.__init__|find_input)"
|
||||
BTYPE_FORMAT="${BUILTIN_FORMAT}.*Redefining built-in 'format'"
|
||||
|
||||
# Following functions are in the public api which have argument names that
|
||||
# override builtin 'str'.
|
||||
BUILTIN_STR="(xml_escape)"
|
||||
BTYPE_STR="${BUILTIN_STR}.*Redefining built-in 'str'"
|
||||
|
||||
# Following functions are in the public api which have argument names that
|
||||
# override builtin 'str'.
|
||||
BUILTIN_FILE="(VirtOptionParser.print_help)"
|
||||
BTYPE_FILE="${BUILTIN_FILE}.*Redefining built-in 'file'"
|
||||
|
||||
# Using os._exit is required in forked processes
|
||||
USE_OF__EXIT="member _exit"
|
||||
|
||||
# False positive: we install the _ function in the builtin namespace, but
|
||||
# pylint doesn't pick it up
|
||||
UNDEF_GETTEXT="Undefined variable '_'"
|
||||
|
||||
# Don't complain about 'ucred' or 'selinux' not being available
|
||||
UCRED="import 'ucred'"
|
||||
SELINUX="import 'selinux'"
|
||||
COVERAGE="import 'coverage'"
|
||||
OLDSELINUX="'selinux' has no "
|
||||
HASHLIB_CONFUSION="Module 'hashlib' has no 'sha.*"
|
||||
|
||||
# Public api error
|
||||
VD_MISMATCHED_ARGS="get_xml_config.*Arguments number differs"
|
||||
|
||||
# Pylint getting confused with XMLBuilder complication
|
||||
XMLBUILDER_CONFUSION="xml_property.*protected member _xml.*"
|
||||
|
||||
# urltest needs access to protected members for testing purposes
|
||||
URLTEST_ACCESS="TestURLFetch.*Access to a protected member"
|
||||
|
||||
# We use some hacks in the test driver to simulate remote libvirt URIs
|
||||
TEST_HACKS="TestClone.*protected member _util|testQEMUDriverName.*protected member _get_uri|Access to a protected member _util"
|
||||
|
||||
# Scattered examples of legitimately unused arguments
|
||||
UNUSED_ARGS="(SuseDistro|SolarisDistro|NetWareDistro).isValidStore.*Unused argument 'progresscb'|.*Installer.prepare.*Unused argument|post_install_check.*Unused argument 'guest'|Guest.__init__.*Unused argument 'type'|_get_bootdev"
|
||||
|
||||
# Outside __init__ checks throw false positives with distutils custom commands
|
||||
# tests.storage also invokes false positives using hasattr
|
||||
OUTSIDE_INIT="(.*Test.*|.*createPool.*)outside __init__"
|
||||
|
||||
# pylint complains about some of the subclass funkiness in chardev classes
|
||||
CHAR_SUBCLASS=".*VirtualCharDevice' has no '(source_mode|source_path)' member.*|.*Method '_char_xml' is abstract in class 'VirtualCharDevice'.*"
|
||||
|
||||
# FIXME: Everything skipped below are all bugs
|
||||
|
||||
# Libvirt connect() method is broken for getting an objects connection, this
|
||||
# workaround is required for now
|
||||
ACCESS__CONN="Access to a protected member _conn"
|
||||
|
||||
# There isn't a clean API way to access this functions from the API, but
|
||||
# they provide info that is needed. These need need to be fixed.
|
||||
PROT_MEM_BUGS="protected member (_lookup_osdict_key|_OS_TYPES|_prepare_install|_create_devices|_cleanup_install|_install_bootconfig|_channels|_get_caps|_open_test_uri|_set_rhel6)|'virtinst.FullVirtGuest' has no '_OS_TYPES'"
|
||||
|
||||
|
||||
# This doesn't belong here, but makes sure I don't break the test suite :)
|
||||
if grep -qIR crobinso tests --exclude pylint\* ; then
|
||||
echo "Test suite borked:"
|
||||
grep -IR crobinso tests --exclude pylint\*
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DMSG=""
|
||||
skipmsg() {
|
||||
DMSG="${DMSG},$1"
|
||||
}
|
||||
|
||||
DCHECKERS=""
|
||||
skipchecker() {
|
||||
DCHECKERS="${DCHECKERS},$1"
|
||||
}
|
||||
|
||||
skipmsg_checksupport() {
|
||||
out=`pylint --list-msgs 2>&1`
|
||||
if `echo $out | grep -q $1` ; then
|
||||
echo "adding!"
|
||||
skipmsg "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Disabled Messages:
|
||||
skipmsg "C0103" # C0103: Name doesn't match some style regex
|
||||
skipmsg "C0111" # C0111: No docstring
|
||||
skipmsg "C0301" # C0301: Line too long
|
||||
skipmsg "C0302" # C0302: Too many lines in module
|
||||
skipmsg "W0105" # W0105: String statement has no effect (annoying for docs)
|
||||
skipmsg "W0141" # W0141: Complaining about 'map' and 'filter'
|
||||
skipmsg "W0142" # W0142: Use of * or **
|
||||
skipmsg "W0603" # W0603: Using the global statement
|
||||
skipmsg "W0703" # W0703: Catch 'Exception'
|
||||
skipmsg "W0704" # W0704: Exception doesn't do anything
|
||||
skipmsg "W0702" # W0702: No exception type specified
|
||||
skipmsg "R0201" # R0201: Method could be a function
|
||||
skipchecker "Design" # Things like "Too many func arguments",
|
||||
# "Too man public methods"
|
||||
|
||||
# Possibly useful at some point
|
||||
skipmsg "W0403" # W0403: Relative imports
|
||||
skipmsg "W0511" # W0511: FIXME and XXX: messages
|
||||
skipmsg "R0401" # R0401: Cyclic imports
|
||||
skipchecker "Similarities" # Finds duplicate code
|
||||
|
||||
# Not supported in many pylint versions
|
||||
# Put new messages here with skipmsg_checksupport
|
||||
|
||||
|
||||
AWK=awk
|
||||
[ `uname -s` = 'SunOS' ] && AWK=nawk
|
||||
|
||||
pylint --ignore=coverage.py, $FILES \
|
||||
--reports=n \
|
||||
--output-format=colorized \
|
||||
--dummy-variables-rgx="dummy|ignore*|.*ignore" \
|
||||
--disable=${DMSG} \
|
||||
--disable=${DCHECKERS} 2>&1 | \
|
||||
egrep -ve "$EXCEPTHOOK" \
|
||||
-ve "$NO_PYL_CONFIG" \
|
||||
-ve "$BTYPE_TYPE" \
|
||||
-ve "$BTYPE_FILE" \
|
||||
-ve "$BTYPE_STR" \
|
||||
-ve "$BTYPE_FORMAT" \
|
||||
-ve "$UCRED" \
|
||||
-ve "$SELINUX" \
|
||||
-ve "$COVERAGE" \
|
||||
-ve "$OLDSELINUX" \
|
||||
-ve "$HASHLIB_CONFUSION" \
|
||||
-ve "$USE_OF__EXIT" \
|
||||
-ve "$UNDEF_GETTEXT" \
|
||||
-ve "$VD_MISMATCHED_ARGS" \
|
||||
-ve "$ACCESS__CONN" \
|
||||
-ve "$URLTEST_ACCESS" \
|
||||
-ve "$UNUSED_ARGS" \
|
||||
-ve "$TEST_HACKS" \
|
||||
-ve "$PROT_MEM_BUGS" \
|
||||
-ve "$CHAR_SUBCLASS" \
|
||||
-ve "$XMLBUILDER_CONFUSION" \
|
||||
-ve "$OUTSIDE_INIT" | \
|
||||
$AWK '\
|
||||
# Strip out any "*** Module name" lines if we dont list any errors for them
|
||||
BEGIN { found=0; cur_line="" }
|
||||
{
|
||||
if (found == 1) {
|
||||
if ( /\*\*\*/ ) {
|
||||
prev_line = $0
|
||||
} else {
|
||||
print prev_line
|
||||
print $0
|
||||
found = 0
|
||||
}
|
||||
} else if ( /\*\*\*/ ) {
|
||||
found = 1
|
||||
prev_line = $0
|
||||
} else {
|
||||
print $0
|
||||
}
|
||||
}'
|
||||
|
||||
################
|
||||
# pep8 section #
|
||||
################
|
||||
|
||||
SKIP_PEP8=""
|
||||
skip_pep8() {
|
||||
if [ ! -z ${SKIP_PEP8} ] ; then
|
||||
SKIP_PEP8="${SKIP_PEP8},"
|
||||
fi
|
||||
SKIP_PEP8="${SKIP_PEP8}$1"
|
||||
}
|
||||
|
||||
skip_pep8 "E201" # Spaces after [, before ]
|
||||
skip_pep8 "E203" # Space before : in dictionary defs
|
||||
skip_pep8 "E221" # Multiple spaces before operator (warns
|
||||
# about column aligning assigments
|
||||
skip_pep8 "E241" # Space after , column alignment nono
|
||||
skip_pep8 "E261" # 2 spaces before inline comment?
|
||||
skip_pep8 "E301" # 1 blank line between methods
|
||||
skip_pep8 "E302" # 2 blank lines between function defs
|
||||
skip_pep8 "E303" # Too many blank lines
|
||||
skip_pep8 "E501" # Line too long
|
||||
|
||||
echo "Running pep8"
|
||||
pep8 -r --ignore $SKIP_PEP8 $FILES
|
Loading…
Reference in New Issue