Create file to run pylint on all command modules (fix the issues found)

This commit is contained in:
Derek Bekoe 2016-03-25 17:14:35 -07:00
Родитель 8674e311ca
Коммит 8a54d5b93b
4 изменённых файлов: 54 добавлений и 5 удалений

Просмотреть файл

@ -9,5 +9,6 @@ install:
script:
- export PYTHONPATH=$PATHONPATH:./src
- python -m azure.cli
- pylint src/azure
- pylint -r n src/azure
- python scripts/pylint-command-modules.py
- python -m unittest discover -s src/azure/cli/tests --buffer

Просмотреть файл

@ -0,0 +1,42 @@
# Runs pylint on the command modules
from __future__ import print_function
import os
import sys
from subprocess import check_call, CalledProcessError
# The prefix for the command module folders
COMMAND_MODULE_PREFIX = 'azure-cli-'
PATH_TO_COMMAND_MODULES = os.path.abspath(os.path.join(os.path.abspath(__file__), '..', '..', 'src' , 'command_modules'))
all_command_modules = [(name, PATH_TO_COMMAND_MODULES+'/'+name)
for name in os.listdir(PATH_TO_COMMAND_MODULES)
if name.startswith(COMMAND_MODULE_PREFIX) and os.path.isdir(PATH_TO_COMMAND_MODULES+'/'+name)]
if not all_command_modules:
print("No command modules found. If there are no command modules. This file should not be loaded in .travis.yml", file=sys.stderr)
sys.exit(1)
print(str(len(all_command_modules))+" command module(s) found...")
print("Running pylint on each one.")
failed_modules = []
# It runs through all the modules
# If pylint fails on a module, we modify success to False and carry on
# so we show all errors in all modules.
for (name, fullpath) in all_command_modules:
path_to_module = os.path.join(fullpath, 'azure')
try:
check_call("pylint -r n "+path_to_module, shell=True)
except CalledProcessError as err:
failed_modules.append((name, err))
print(err, file=sys.stderr)
print()
print("SUMMARY")
print("-------")
if failed_modules:
print(str(len(failed_modules))+" module(s) FAILED pylint...", file=sys.stderr)
print("Failed modules: " + ', '.join([name for (name, err) in failed_modules]), file=sys.stderr)
sys.exit(1)
else:
print('\n'.join([name for (name, fullpath) in all_command_modules]))
print("ALL COMMAND MODULES OK")

Просмотреть файл

@ -7,7 +7,9 @@ from azure.cli._locale import L
@command('components list')
@description(L('List the installed components.'))
def list_components(args, unexpected): #pylint: disable=unused-argument
return sorted(["%s (%s)" % (dist.key.replace('azure-cli-', ''), dist.version) for dist in pip.get_installed_distributions(local_only=False) if dist.key.startswith('azure-cli-')])
return sorted(["%s (%s)" % (dist.key.replace('azure-cli-', ''), dist.version)
for dist in pip.get_installed_distributions(local_only=False)
if dist.key.startswith('azure-cli-')])
# @command('components check')
# @description(L('Check a component for an update'))
@ -46,7 +48,8 @@ def list_components(args, unexpected): #pylint: disable=unused-argument
# raise RuntimeError("Component already installed.")
# except ImportError:
# version_no = '=='+args.get('version') if args.get('version') else ''
# pip.main(['install', '--quiet', '--isolated', '--disable-pip-version-check', 'azure-cli-'+component_name+version_no,
# pip.main(['install', '--quiet', '--isolated', '--disable-pip-version-check',
# 'azure-cli-'+component_name+version_no,
# '--extra-index-url', 'http://40.112.211.51:8080/', '--trusted-host', '40.112.211.51'])
# @command('components update')
@ -58,7 +61,8 @@ def list_components(args, unexpected): #pylint: disable=unused-argument
# raise RuntimeError("Specify a component name.")
# try:
# __import__('azure.cli.command_modules.'+component_name+'.__main__')
# pip.main(['install', '--quiet', '--isolated', '--disable-pip-version-check', '--upgrade', 'azure-cli-'+component_name,
# pip.main(['install', '--quiet', '--isolated', '--disable-pip-version-check',
# '--upgrade', 'azure-cli-'+component_name,
# '--extra-index-url', 'http://40.112.211.51:8080/', '--trusted-host', '40.112.211.51'])
# except ImportError:
# raise RuntimeError("Component not installed.")

Просмотреть файл

@ -20,7 +20,9 @@ from azure.mgmt.network.operations import (ApplicationGatewaysOperations,
from azure.cli._locale import L
from azure.cli.commands._command_creation import get_mgmt_service_client
from azure.cli.commands._auto_command import build_operation, LongRunningOperation, GLOBALPARAMALIASES
from azure.cli.commands._auto_command import (build_operation,
LongRunningOperation,
GLOBALPARAMALIASES)
from azure.cli.commands import command, description, option
def _network_client_factory():