-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Rewrite Pylint Check Without Tox #42757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b9f65c6
add pylint check
JennyPng 1d5f104
minor fix
JennyPng 16bcc86
remove creating new package installation
JennyPng 321e1b3
clean imports
JennyPng cec6310
clean mypy imports
JennyPng 9bbc41f
Merge branch 'main' into jennypng-pylint-check
JennyPng 9e0d566
merge updates
JennyPng 84486c4
Merge branch 'main' into jennypng-pylint-check
JennyPng 819c5d0
merge updates and remove package install
JennyPng 85ceb86
use pip_install
JennyPng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import argparse | ||
| import os | ||
| import sys | ||
|
|
||
| from typing import Optional, List | ||
| from subprocess import CalledProcessError, check_call | ||
|
|
||
| from .Check import Check | ||
| from ci_tools.functions import pip_install | ||
| from ci_tools.variables import discover_repo_root, in_ci, set_envvar_defaults, in_ci, set_envvar_defaults | ||
| from ci_tools.environment_exclusions import is_check_enabled | ||
| from ci_tools.logging import logger | ||
|
|
||
| REPO_ROOT = discover_repo_root() | ||
| PYLINT_VERSION = "3.2.7" | ||
|
|
||
| class pylint(Check): | ||
| def __init__(self) -> None: | ||
| super().__init__() | ||
|
|
||
| def register(self, subparsers: "argparse._SubParsersAction", parent_parsers: Optional[List[argparse.ArgumentParser]] = None) -> None: | ||
| """Register the pylint check. The pylint check installs pylint and runs pylint against the target package. | ||
| """ | ||
| parents = parent_parsers or [] | ||
| p = subparsers.add_parser("pylint", parents=parents, help="Run the pylint check") | ||
| p.set_defaults(func=self.run) | ||
|
|
||
| p.add_argument( | ||
| "--next", | ||
| default=False, | ||
| help="Next version of pylint is being tested.", | ||
| required=False, | ||
|
scbedd marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| def run(self, args: argparse.Namespace) -> int: | ||
| """Run the pylint check command.""" | ||
| logger.info("Running pylint check...") | ||
|
|
||
| set_envvar_defaults() | ||
| targeted = self.get_targeted_directories(args) | ||
|
|
||
| results: List[int] = [] | ||
|
|
||
| for parsed in targeted: | ||
| package_dir = parsed.folder | ||
| package_name = parsed.name | ||
| executable, staging_directory = self.get_executable(args.isolate, args.command, sys.executable, package_dir) | ||
| logger.info(f"Processing {package_name} for pylint check") | ||
|
|
||
| # install dependencies | ||
| try: | ||
| pip_install([ | ||
| "azure-pylint-guidelines-checker==0.5.6", "--index-url=https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/" | ||
| ], True, executable, package_dir) | ||
| except CalledProcessError as e: | ||
| logger.error("Failed to install dependencies:", e) | ||
| return e.returncode | ||
|
|
||
| # install pylint | ||
| try: | ||
| if args.next: | ||
| # use latest version of pylint | ||
| pip_install(["pylint"], True, executable, package_dir) | ||
| else: | ||
| pip_install([f"pylint=={PYLINT_VERSION}"], True, executable, package_dir) | ||
| except CalledProcessError as e: | ||
| logger.error("Failed to install pylint:", e) | ||
| return e.returncode | ||
|
|
||
| top_level_module = parsed.namespace.split(".")[0] | ||
|
|
||
| if in_ci(): | ||
| if not is_check_enabled(package_dir, "pylint"): | ||
| logger.info( | ||
| f"Package {package_name} opts-out of pylint check." | ||
| ) | ||
| continue | ||
|
|
||
| rcFileLocation = os.path.join(REPO_ROOT, "eng/pylintrc") if args.next else os.path.join(REPO_ROOT, "pylintrc") | ||
|
|
||
| try: | ||
| results.append(check_call( | ||
| [ | ||
| executable, | ||
| "-m", | ||
| "pylint", | ||
| "--rcfile={}".format(rcFileLocation), | ||
| "--output-format=parseable", | ||
| os.path.join(package_dir, top_level_module), | ||
| ] | ||
| )) | ||
| except CalledProcessError as e: | ||
| logger.error( | ||
| "{} exited with linting error {}. Please see this link for more information https://aka.ms/azsdk/python/pylint-guide".format(package_name, e.returncode) | ||
| ) | ||
| if args.next and in_ci(): | ||
| from gh_tools.vnext_issue_creator import create_vnext_issue | ||
| create_vnext_issue(package_dir, "pylint") | ||
|
|
||
| results.append(e.returncode) | ||
|
|
||
| if args.next and in_ci(): | ||
| from gh_tools.vnext_issue_creator import close_vnext_issue | ||
| close_vnext_issue(package_name, "pylint") | ||
|
|
||
| return max(results) if results else 0 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.