mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-12-13 08:37:03 +00:00
Add Pylint print checker and py-checkstyle as required (#8849)
* Always run the checkstyle * Add print checker lint plugin * Typos * Add print checker * Fix e2e
This commit is contained in:
parent
550a4226e0
commit
93381a7343
3
.github/workflows/py-checkstyle.yml
vendored
3
.github/workflows/py-checkstyle.yml
vendored
@ -16,9 +16,6 @@ name: Python Checkstyle
|
|||||||
on:
|
on:
|
||||||
pull_request_target:
|
pull_request_target:
|
||||||
types: [labeled, opened, synchronize, reopened]
|
types: [labeled, opened, synchronize, reopened]
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- '0.[0-9]+.[0-9]+'
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|||||||
@ -19,6 +19,7 @@ good-names=T,C,fn,db
|
|||||||
fail-under=6.0
|
fail-under=6.0
|
||||||
init-hook='from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))'
|
init-hook='from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))'
|
||||||
extension-pkg-allow-list=pydantic
|
extension-pkg-allow-list=pydantic
|
||||||
|
load-plugins=ingestion.plugins.print_checker
|
||||||
|
|
||||||
[MESSAGES CONTROL]
|
[MESSAGES CONTROL]
|
||||||
disable=no-name-in-module,import-error,duplicate-code
|
disable=no-name-in-module,import-error,duplicate-code
|
||||||
|
|||||||
4
Makefile
4
Makefile
@ -41,7 +41,7 @@ precommit_install: ## Install the project's precommit hooks from .pre-commit-co
|
|||||||
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint: ## Run pylint on the Python sources to analyze the codebase
|
lint: ## Run pylint on the Python sources to analyze the codebase
|
||||||
find $(PY_SOURCE) -path $(PY_SOURCE)/metadata/generated -prune -false -o -type f -name "*.py" | xargs pylint --ignore-paths=$(PY_SOURCE)/metadata_server/
|
PYTHONPATH="${PYTHONPATH}:./ingestion/plugins" find $(PY_SOURCE) -path $(PY_SOURCE)/metadata/generated -prune -false -o -type f -name "*.py" | xargs pylint --ignore-paths=$(PY_SOURCE)/metadata_server/
|
||||||
|
|
||||||
.PHONY: py_format
|
.PHONY: py_format
|
||||||
py_format: ## Run black and isort to format the Python codebase
|
py_format: ## Run black and isort to format the Python codebase
|
||||||
@ -54,7 +54,7 @@ py_format_check: ## Check if Python sources are correctly formatted
|
|||||||
pycln ingestion/ openmetadata-airflow-apis/ --diff --extend-exclude $(PY_SOURCE)/metadata/generated
|
pycln ingestion/ openmetadata-airflow-apis/ --diff --extend-exclude $(PY_SOURCE)/metadata/generated
|
||||||
isort --check-only ingestion/ openmetadata-airflow-apis/ --skip $(PY_SOURCE)/metadata/generated --skip ingestion/build --profile black --multi-line 3
|
isort --check-only ingestion/ openmetadata-airflow-apis/ --skip $(PY_SOURCE)/metadata/generated --skip ingestion/build --profile black --multi-line 3
|
||||||
black --check --diff ingestion/ openmetadata-airflow-apis/ --extend-exclude $(PY_SOURCE)/metadata/generated
|
black --check --diff ingestion/ openmetadata-airflow-apis/ --extend-exclude $(PY_SOURCE)/metadata/generated
|
||||||
pylint --fail-under=10 $(PY_SOURCE)/metadata --ignore-paths $(PY_SOURCE)/metadata/generated || (echo "PyLint error code $$?"; exit 1)
|
PYTHONPATH="${PYTHONPATH}:./ingestion/plugins" pylint --fail-under=10 $(PY_SOURCE)/metadata --ignore-paths $(PY_SOURCE)/metadata/generated || (echo "PyLint error code $$?"; exit 1)
|
||||||
|
|
||||||
## Ingestion models generation
|
## Ingestion models generation
|
||||||
.PHONY: generate
|
.PHONY: generate
|
||||||
|
|||||||
6
ingestion/plugins/README.md
Normal file
6
ingestion/plugins/README.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Custom PyLint plugins
|
||||||
|
|
||||||
|
- `pint_checker`: to handle `print` statements as warnings.
|
||||||
|
- Add it to `.pylintrc` as `load-plugins=ingestion.plugins.print_checker` under `[MASTER]`.
|
||||||
|
|
||||||
|
You'll need to update the path of `pylint` at runtime with `PYTHONPATH="${PYTHONPATH}:./ingestion/plugins"`.
|
||||||
0
ingestion/plugins/__init__.py
Normal file
0
ingestion/plugins/__init__.py
Normal file
53
ingestion/plugins/print_checker.py
Normal file
53
ingestion/plugins/print_checker.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# Copyright 2022 Collate
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
"""
|
||||||
|
Custom pylint plugin to catch `print` calls
|
||||||
|
"""
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from astroid import nodes
|
||||||
|
from pylint.checkers import BaseChecker
|
||||||
|
from pylint.checkers.utils import only_required_for_messages
|
||||||
|
from pylint.interfaces import IAstroidChecker
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from pylint.lint import PyLinter
|
||||||
|
|
||||||
|
|
||||||
|
class PrintChecker(BaseChecker):
|
||||||
|
"""
|
||||||
|
Check for any print statement in the code
|
||||||
|
"""
|
||||||
|
|
||||||
|
__implements__ = (IAstroidChecker,)
|
||||||
|
name = "no_print_allowed"
|
||||||
|
_symbol = "print-call"
|
||||||
|
msgs = {
|
||||||
|
"W5001": (
|
||||||
|
"Used builtin function %s",
|
||||||
|
_symbol,
|
||||||
|
"Print can make us lose traceability, use logging instead",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@only_required_for_messages("print-call")
|
||||||
|
def visit_call(self, node: nodes.Call) -> None:
|
||||||
|
if isinstance(node.func, nodes.Name) and node.func.name == "print":
|
||||||
|
self.add_message(self._symbol, node=node)
|
||||||
|
|
||||||
|
|
||||||
|
def register(linter: "PyLinter") -> None:
|
||||||
|
"""
|
||||||
|
This required method auto registers the checker during initialization.
|
||||||
|
:param linter: The linter to register the checker to.
|
||||||
|
"""
|
||||||
|
linter.register_checker(PrintChecker(linter))
|
||||||
@ -31,6 +31,6 @@ class ANSI(Enum):
|
|||||||
def print_ansi_encoded_string(
|
def print_ansi_encoded_string(
|
||||||
color: Optional[ANSI] = None, bold: bool = False, message: str = ""
|
color: Optional[ANSI] = None, bold: bool = False, message: str = ""
|
||||||
):
|
):
|
||||||
print(
|
print( # pylint: disable=W5001
|
||||||
f"{ANSI.BOLD.value if bold else ''}{color.value if color else ''}{message}{ANSI.ENDC.value}"
|
f"{ANSI.BOLD.value if bold else ''}{color.value if color else ''}{message}{ANSI.ENDC.value}"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -41,19 +41,18 @@ def get_beginning_of_day_timestamp_mill(
|
|||||||
"""Get the beginning of day timestamp
|
"""Get the beginning of day timestamp
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
days (int, optional): delat in days. Defaults to 0.
|
days (int, optional): delay in days. Defaults to 0.
|
||||||
seconds (int, optional): delat in seconds. Defaults to 0.
|
seconds (int, optional): delay in seconds. Defaults to 0.
|
||||||
microseconds (int, optional): delat in microseconds. Defaults to 0.
|
microseconds (int, optional): delay in microseconds. Defaults to 0.
|
||||||
milliseconds (int, optional): delat in milliseconds. Defaults to 0.
|
milliseconds (int, optional): delay in milliseconds. Defaults to 0.
|
||||||
minutes (int, optional): delat in minutes. Defaults to 0.
|
minutes (int, optional): delay in minutes. Defaults to 0.
|
||||||
hours (int, optional): delat in hours. Defaults to 0.
|
hours (int, optional): delay in hours. Defaults to 0.
|
||||||
weeks (int, optional): delat in weeks. Defaults to 0.
|
weeks (int, optional): delay in weeks. Defaults to 0.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: timestamp milliseconds
|
int: timestamp milliseconds
|
||||||
"""
|
"""
|
||||||
now_utc = datetime.utcnow()
|
now_utc = datetime.utcnow()
|
||||||
print(now_utc)
|
|
||||||
delta = timedelta(
|
delta = timedelta(
|
||||||
weeks=weeks,
|
weeks=weeks,
|
||||||
days=days,
|
days=days,
|
||||||
|
|||||||
@ -96,7 +96,7 @@ class MysqlCliTest(CliCommonDB.TestSuite):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def expected_filtered_table_includes() -> int:
|
def expected_filtered_table_includes() -> int:
|
||||||
return 43
|
return 44
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def expected_filtered_table_excludes() -> int:
|
def expected_filtered_table_excludes() -> int:
|
||||||
|
|||||||
@ -205,8 +205,6 @@ def test_percentage_of_entities_with_owner_kpi_result():
|
|||||||
kpi_target, results, "completedOwner", 1668083253659
|
kpi_target, results, "completedOwner", 1668083253659
|
||||||
)
|
)
|
||||||
|
|
||||||
print(kpi_result)
|
|
||||||
|
|
||||||
assert kpi_result.targetResult
|
assert kpi_result.targetResult
|
||||||
for result in kpi_result.targetResult:
|
for result in kpi_result.targetResult:
|
||||||
if result.name == "hasOwnerFraction":
|
if result.name == "hasOwnerFraction":
|
||||||
|
|||||||
@ -73,7 +73,6 @@ def _setup_mock_sagemaker(create_model: bool = False):
|
|||||||
sagemaker = boto3.Session().client("sagemaker")
|
sagemaker = boto3.Session().client("sagemaker")
|
||||||
if not create_model:
|
if not create_model:
|
||||||
return
|
return
|
||||||
print("Creating model!!!!!!!")
|
|
||||||
sagemaker.create_model(
|
sagemaker.create_model(
|
||||||
ModelName="mock-model",
|
ModelName="mock-model",
|
||||||
PrimaryContainer={
|
PrimaryContainer={
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user