Skip to content

Commit

Permalink
[CI] Move 1: Copy job SourceStaticPy from Travis to ADO (5/6) (Azure#…
Browse files Browse the repository at this point in the history
…1156)

* Enable flake8 on extension in ADO

* Enable pylint on CI scripts in ADO

* Enable flake8 on CI scripts in ADO

* Enable code owner and license checks in ADO

* Fix bug: pylint==1.9.5 didnt recognize disable=too-many-lines
  • Loading branch information
Jianhui Harold authored and Zim Kalinowski committed Dec 18, 2019
1 parent bea9d97 commit 7c5a7e2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 33 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ignore =
F401, # imported but unused, too many violations, to be removed in the future
F811, # redefinition of unused, to be removed in the future
C901 # code flow is too complex, too many violations, to be removed in the future
W504 # line break after binary operator effect on readability is subjective
exclude =
*/vendored_sdks
docs
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6
- bash: pip install wheel==0.30.0 pylint==1.9.5 flake8 requests
- bash: pip install wheel==0.30.0 pylint==1.9.5 flake8==3.5.0 requests
displayName: 'Install wheel, pylint, flake8, requests'
- bash: python scripts/ci/source_code_static_analysis.py
displayName: "Static Analysis"
Expand Down
3 changes: 0 additions & 3 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ reports=no
# too-many-arguments:
# Due to the nature of the CLI many commands have large arguments set which reflect in large arguments set in corresponding methods.
#
# too-many-lines:
# Due to unreasonable structure and history debut, files get expanding very large
#
# useless-object-inheritance:
# Due to some classes inherits from __builtin__.object(), can be safely removed from bases in python3
#
Expand Down
52 changes: 26 additions & 26 deletions scripts/ci/source_code_static_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

import os
import sys
import argparse
import multiprocessing

from pylint import lint
from flake8.main import application

from util import get_repo_root

# import argparse
# from verify_codeowners import main as _verify_codeowners
# from verify_license import main as _verify_license
from verify_codeowners import main as _verify_codeowners
from verify_license import main as _verify_license


SDK_FILE_MARKER = r"# Code generated by Microsoft (R) AutoRest Code Generator."
Expand Down Expand Up @@ -86,7 +86,7 @@ def _run_pylint(module_paths, ignored_modules=None, rcfile=None, cpu_count=1):
# 8: Refactor message issued
# 16: Convention message issued
# 32: Usage error
if se.code not in [0, 8, 16, 24]:
if se.code != 0:
sys.exit(se.code)


Expand Down Expand Up @@ -117,35 +117,35 @@ def main():
sdk_modules.append("vendored_sdks")
module_paths = _get_azext_module_paths(root_dir)

# scripts_dir = os.path.join(root_dir, "scripts")
# ci_files = _get_ci_py_file_paths(os.path.join(scripts_dir, "ci"))
scripts_dir = os.path.join(root_dir, "scripts")
ci_files = _get_ci_py_file_paths(os.path.join(scripts_dir, "ci"))

rc_file = os.path.join(root_dir, "pylintrc")
# config_file = os.path.join(root_dir, "flake8")
config_file = os.path.join(root_dir, ".flake8")

print("\nRunning pylint on extensions...")
_run_pylint(module_paths, ",".join(sdk_modules), rc_file, cpu_count)
print("Pylint OK.\n")

# print("Running flake8 on extensions...")
# _run_flake8(module_paths, config_file)
# print("Flake8 OK.\n")
#
# print("Running pylint on CI scripts...")
# _run_pylint(ci_files, rcfile=rcfile, cpu_count=cpu_count)
# print("Pylint OK.\n")
#
# print("Running flake8 on CI scripts...")
# _run_flake8(ci_files, config_file=config_file)
# print("Pylint OK.\n")
#
# print("Other Static checks...")
#
# _verify_codeowners()
#
# parser = argparse.ArgumentParser()
# parser.add_argument('excluded_paths', nargs='*')
# _verify_license(parser.parse_args())
print("Running flake8 on extensions...")
_run_flake8(module_paths, config_file)
print("Flake8 OK.\n")

print("Running pylint on CI scripts...")
_run_pylint(ci_files, rcfile=rc_file, cpu_count=cpu_count)
print("Pylint OK.\n")

print("Running flake8 on CI scripts...")
_run_flake8(ci_files, config_file=config_file)
print("Pylint OK.\n")

print("Other Static checks...")

_verify_codeowners()

parser = argparse.ArgumentParser()
parser.add_argument('excluded_paths', nargs='*')
_verify_license(parser.parse_args())

print("All static checks successful!")

Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/verify_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def main(args):
continue
file_itr = (os.path.join(current_dir, p) for p in files if p.endswith('.py'))
for python_file in file_itr:
with open(python_file, 'r') as f:
with open(python_file, 'r', encoding='utf-8') as f:
file_text = f.read().replace('\r\n', '\n')
file_text = file_text.replace('\n#', '')
if file_text and (LICENSE_HEADER not in file_text):
Expand Down
3 changes: 1 addition & 2 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# pylint: disable=too-many-lines
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=too-many-lines

from __future__ import print_function

import binascii
Expand Down

0 comments on commit 7c5a7e2

Please sign in to comment.