This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for CLI arguments
- Loading branch information
Showing
11 changed files
with
223 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -8,5 +8,6 @@ | |
"ms-python.pylint", | ||
"ms-python.python", | ||
"ms-python.vscode-pylance", | ||
"yzhang.markdown-all-in-one" | ||
] | ||
} |
This file contains 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 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 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
Empty file.
113 changes: 113 additions & 0 deletions
113
pydocstyle_gitlab_code_quality/src/config/cli_parser.py
This file contains 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,113 @@ | ||
import argparse | ||
import logging as log | ||
|
||
from .config import Config | ||
|
||
|
||
class CliParser: | ||
parser: argparse.ArgumentParser = argparse.ArgumentParser( | ||
description="Generate GitLab Code Quality report from an output of pydocstyle.", | ||
add_help=True, | ||
allow_abbrev=False, | ||
) | ||
|
||
@classmethod | ||
def initialize(cls) -> None: | ||
cls._setup_arguments() | ||
cls._update_config() | ||
|
||
@classmethod | ||
def _setup_arguments(cls) -> None: | ||
cls.parser.add_argument( | ||
"--minor", | ||
help="Error codes to be displayed with MINOR severity.", | ||
default=[], | ||
type=lambda s: s.split(","), | ||
) | ||
cls.parser.add_argument( | ||
"--major", | ||
help="Error codes to be displayed with MAJOR severity.", | ||
default=[], | ||
type=lambda s: s.split(","), | ||
) | ||
cls.parser.add_argument( | ||
"--critical", | ||
help="Error codes to be displayed with CRITICAL severity.", | ||
default=[], | ||
type=lambda s: s.split(","), | ||
) | ||
cls.parser.add_argument( | ||
"-i", | ||
"--ignore", | ||
help="Error codes to be omitted from Code Quality report.", | ||
default="", | ||
type=lambda s: s.split(","), | ||
) | ||
cls.parser.add_argument( | ||
"-f", | ||
"--file", | ||
"--input", | ||
help="Path to the file with pydocstyle output.", | ||
default="", | ||
type=str, | ||
) | ||
cls.parser.add_argument( | ||
"-o", | ||
"--output", | ||
help="Path to the file where the Code Quality report will be saved.", | ||
default="", | ||
type=str, | ||
) | ||
cls.parser.add_argument( | ||
"--no-stdout", | ||
help="Do not print the Code Quality report to stdout.", | ||
action="store_true", | ||
default=False, | ||
) | ||
cls.parser.add_argument( | ||
"--log-file", | ||
help="Path to the file where the log will be saved.", | ||
default=Config.log_file, | ||
type=str, | ||
) | ||
cls.parser.add_argument( | ||
"--enable-logging", | ||
help="Enable logging to a file.", | ||
action="store_true", | ||
default=False, | ||
) | ||
|
||
@classmethod | ||
def _update_config(cls) -> None: | ||
args = vars(cls.parser.parse_args()) | ||
|
||
if args.get("no_stdout", False): | ||
Config.output_sinks.pop(0) | ||
|
||
Config.enable_logging = args.get("enable_logging", False) | ||
Config.log_file = args.get("log_file", Config.log_file) | ||
|
||
if filepath := args.get("output", ""): | ||
file = open(filepath, "w", encoding="utf-8") # pylint: disable=consider-using-with | ||
Config.output_sinks.append(file) | ||
|
||
if filepath := args.get("file", ""): | ||
file = open(filepath, "r", encoding="utf-8") # pylint: disable=consider-using-with | ||
Config.input_sink = file | ||
|
||
if codes := args.get("minor", []): | ||
for code in codes: | ||
Config.code_severities[code] = 1 | ||
|
||
if codes := args.get("major", []): | ||
for code in codes: | ||
Config.code_severities[code] = 2 | ||
|
||
if codes := args.get("critical", []): | ||
log.info(codes) | ||
for code in codes: | ||
Config.code_severities[code] = 3 | ||
|
||
if codes := args.get("ignore", []): | ||
for code in codes: | ||
Config.code_severities[code] = -1 |
This file contains 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,18 @@ | ||
import logging | ||
from sys import stdin, stdout | ||
from typing import Dict, List, TextIO | ||
|
||
|
||
class Config: | ||
enable_logging: bool = False | ||
log_file: str = "pgcq_latest.log" | ||
log_level: int = logging.INFO | ||
|
||
code_severities: Dict[str, int] = {} | ||
code_severities.update({f"D1{i:02d}": 0 for i in range(0, 8)}) | ||
code_severities.update({f"D2{i:02d}": 0 for i in range(0, 16)}) | ||
code_severities.update({f"D3{i:02d}": 0 for i in range(0, 3)}) | ||
code_severities.update({f"D4{i:02d}": 0 for i in range(0, 20)}) | ||
|
||
input_sink: TextIO = stdin | ||
output_sinks: List[TextIO] = [stdout] |
Empty file.
File renamed without changes.
This file contains 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,20 @@ | ||
import logging | ||
|
||
from ..config.config import Config | ||
|
||
# from sys import stdout | ||
|
||
|
||
def initialize_logging() -> None: | ||
root = logging.getLogger() | ||
root.setLevel(Config.log_level) | ||
root.disabled = not Config.enable_logging | ||
|
||
# stdout_handler = logging.StreamHandler(stdout) | ||
# stdout_handler.setLevel(Config.log_level) | ||
|
||
if Config.enable_logging: | ||
file_handler = logging.FileHandler(Config.log_file, mode="w", encoding="utf-8") | ||
file_handler.setLevel(Config.log_level) | ||
|
||
root.addHandler(file_handler) |
This file contains 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