python-utility-scripts 0.0.13__tar.gz → 0.0.14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/PKG-INFO +2 -2
- {python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/apps/polarion/polarion_utils.py +9 -11
- {python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/apps/polarion/polarion_verify_tc_requirements.py +1 -1
- {python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/apps/unused_code/unused_code.py +27 -24
- {python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/apps/utils.py +5 -3
- {python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/pyproject.toml +12 -10
- {python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/LICENSE +0 -0
- {python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/README.md +0 -0
- {python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/apps/__init__.py +0 -0
- {python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/apps/polarion/README.md +0 -0
- {python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/apps/polarion/__init__.py +0 -0
- {python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/apps/unused_code/README.md +0 -0
- {python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/apps/unused_code/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-utility-scripts
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.14
|
|
4
4
|
Summary: Python utility scripts
|
|
5
5
|
Home-page: https://github.com/RedHatQE/python-utility-scripts
|
|
6
6
|
License: Apache-2.0
|
|
@@ -19,7 +19,7 @@ Requires-Dist: pyhelper-utils (>=0.0.3,<0.0.4)
|
|
|
19
19
|
Requires-Dist: pylero (>=0.0.8,<0.0.9)
|
|
20
20
|
Requires-Dist: pytest-mock (>=3.14.0,<4.0.0)
|
|
21
21
|
Requires-Dist: python-simple-logger (>=1.0.8,<2.0.0)
|
|
22
|
-
Requires-Dist: pyyaml
|
|
22
|
+
Requires-Dist: pyyaml (>=6.0.1,<7.0.0)
|
|
23
23
|
Project-URL: Documentation, https://github.com/RedHatQE/python-utility-scripts/blob/main/README.md
|
|
24
24
|
Project-URL: Repository, https://github.com/RedHatQE/python-utility-scripts
|
|
25
25
|
Description-Content-Type: text/markdown
|
{python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/apps/polarion/polarion_utils.py
RENAMED
|
@@ -2,34 +2,32 @@ from simple_logger.logger import get_logger
|
|
|
2
2
|
import shlex
|
|
3
3
|
import subprocess
|
|
4
4
|
from pylero.exceptions import PyleroLibException
|
|
5
|
-
|
|
5
|
+
from typing import Dict, List
|
|
6
6
|
|
|
7
7
|
LOGGER = get_logger(name=__name__)
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
def git_diff():
|
|
10
|
+
def git_diff() -> str:
|
|
11
11
|
data = subprocess.check_output(shlex.split("git diff HEAD^-1"))
|
|
12
|
-
|
|
13
|
-
return data
|
|
12
|
+
return data.decode()
|
|
14
13
|
|
|
15
14
|
|
|
16
|
-
def git_diff_lines():
|
|
17
|
-
diff = {}
|
|
15
|
+
def git_diff_lines() -> Dict[str, List[str]]:
|
|
16
|
+
diff: Dict[str, List[str]] = {}
|
|
18
17
|
for line in git_diff().splitlines():
|
|
19
18
|
LOGGER.debug(line)
|
|
20
19
|
if line.startswith("+"):
|
|
21
20
|
diff.setdefault("added", []).append(line)
|
|
22
|
-
|
|
23
21
|
return diff
|
|
24
22
|
|
|
25
23
|
|
|
26
24
|
def validate_polarion_requirements(
|
|
27
|
-
polarion_test_ids,
|
|
28
|
-
polarion_project_id,
|
|
29
|
-
):
|
|
25
|
+
polarion_test_ids: List[str],
|
|
26
|
+
polarion_project_id: str,
|
|
27
|
+
) -> List[str]:
|
|
30
28
|
from pylero.work_item import TestCase, Requirement
|
|
31
29
|
|
|
32
|
-
tests_with_missing_requirements = []
|
|
30
|
+
tests_with_missing_requirements: List[str] = []
|
|
33
31
|
|
|
34
32
|
for _id in polarion_test_ids:
|
|
35
33
|
has_req = False
|
|
@@ -21,7 +21,7 @@ LOGGER = get_logger(name="polarion-verify-tc-requirements")
|
|
|
21
21
|
)
|
|
22
22
|
@click.option("--project-id", "-p", help="Provide the polarion project id")
|
|
23
23
|
@click.option("--verbosity", default=False, is_flag=True)
|
|
24
|
-
def has_verify(config_file_path, project_id, verbosity):
|
|
24
|
+
def has_verify(config_file_path: str, project_id: str, verbosity: bool) -> None:
|
|
25
25
|
if verbosity:
|
|
26
26
|
LOGGER.setLevel(logging.DEBUG)
|
|
27
27
|
|
{python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/apps/unused_code/unused_code.py
RENAMED
|
@@ -6,43 +6,38 @@ import click
|
|
|
6
6
|
from simple_logger.logger import get_logger
|
|
7
7
|
|
|
8
8
|
from apps.utils import all_python_files, ListParamType, get_util_config
|
|
9
|
+
from typing import Any, Iterable, List
|
|
9
10
|
|
|
10
11
|
LOGGER = get_logger(name=__name__)
|
|
11
12
|
|
|
12
13
|
|
|
13
|
-
def is_fixture_autouse(func):
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
def is_fixture_autouse(func: ast.FunctionDef) -> bool:
|
|
15
|
+
deco_list: List[Any] = func.decorator_list
|
|
16
|
+
for deco in deco_list or []:
|
|
17
|
+
if not hasattr(deco, "func"):
|
|
18
|
+
continue
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
if getattr(deco.func, "attr", None) and getattr(deco.func, "value", None):
|
|
21
|
+
if deco.func.attr == "fixture" and deco.func.value.id == "pytest":
|
|
22
|
+
for _key in deco.keywords:
|
|
23
|
+
if _key.arg == "autouse":
|
|
24
|
+
return True
|
|
25
|
+
return False
|
|
24
26
|
|
|
25
27
|
|
|
26
|
-
def _iter_functions(tree):
|
|
28
|
+
def _iter_functions(tree: ast.Module) -> Iterable[ast.FunctionDef]:
|
|
27
29
|
"""
|
|
28
30
|
Get all function from python file
|
|
29
31
|
"""
|
|
30
|
-
|
|
31
|
-
def is_func(_elm):
|
|
32
|
-
return isinstance(_elm, ast.FunctionDef)
|
|
33
|
-
|
|
34
|
-
def is_test(_elm):
|
|
35
|
-
return _elm.name.startswith("test_")
|
|
36
|
-
|
|
37
32
|
for elm in tree.body:
|
|
38
|
-
if
|
|
39
|
-
if
|
|
33
|
+
if isinstance(elm, ast.FunctionDef):
|
|
34
|
+
if elm.name.startswith("test_"):
|
|
40
35
|
continue
|
|
41
36
|
|
|
42
37
|
yield elm
|
|
43
38
|
|
|
44
39
|
|
|
45
|
-
def is_ignore_function_list(ignore_prefix_list, function):
|
|
40
|
+
def is_ignore_function_list(ignore_prefix_list: List[str], function: ast.FunctionDef) -> bool:
|
|
46
41
|
ignore_function_lists = [
|
|
47
42
|
function.name for ignore_prefix in ignore_prefix_list if function.name.startswith(ignore_prefix)
|
|
48
43
|
]
|
|
@@ -50,6 +45,8 @@ def is_ignore_function_list(ignore_prefix_list, function):
|
|
|
50
45
|
LOGGER.debug(f"Following functions are getting skipped: {ignore_function_lists}")
|
|
51
46
|
return True
|
|
52
47
|
|
|
48
|
+
return False
|
|
49
|
+
|
|
53
50
|
|
|
54
51
|
@click.command()
|
|
55
52
|
@click.option(
|
|
@@ -68,14 +65,20 @@ def is_ignore_function_list(ignore_prefix_list, function):
|
|
|
68
65
|
help="Provide a comma-separated string or list of function prefixes to exclude",
|
|
69
66
|
type=ListParamType(),
|
|
70
67
|
)
|
|
71
|
-
@click.option("--
|
|
72
|
-
def get_unused_functions(
|
|
73
|
-
|
|
68
|
+
@click.option("--verbose", default=False, is_flag=True)
|
|
69
|
+
def get_unused_functions(
|
|
70
|
+
config_file_path: Any, exclude_files: Any, exclude_function_prefixes: Any, verbose: bool
|
|
71
|
+
) -> Any:
|
|
72
|
+
if verbose:
|
|
74
73
|
LOGGER.setLevel(logging.DEBUG)
|
|
74
|
+
else:
|
|
75
|
+
logging.disable(logging.CRITICAL)
|
|
76
|
+
|
|
75
77
|
_unused_functions = []
|
|
76
78
|
unused_code_config = get_util_config(util_name="pyutils-unusedcode", config_file_path=config_file_path)
|
|
77
79
|
func_ignore_prefix = exclude_function_prefixes or unused_code_config.get("exclude_function_prefix", [])
|
|
78
80
|
file_ignore_list = exclude_files or unused_code_config.get("exclude_files", [])
|
|
81
|
+
|
|
79
82
|
for py_file in all_python_files():
|
|
80
83
|
if os.path.basename(py_file) in file_ignore_list:
|
|
81
84
|
continue
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
1
2
|
import os
|
|
2
3
|
|
|
3
4
|
import yaml
|
|
4
5
|
from simple_logger.logger import get_logger
|
|
5
6
|
import json
|
|
6
7
|
import click
|
|
8
|
+
from typing import Any, Dict, Iterable
|
|
7
9
|
|
|
8
10
|
LOGGER = get_logger(name=__name__)
|
|
9
11
|
|
|
10
12
|
|
|
11
|
-
def get_util_config(util_name, config_file_path):
|
|
13
|
+
def get_util_config(util_name: str, config_file_path: str) -> Dict[str, Any]:
|
|
12
14
|
if os.path.exists(config_file_path):
|
|
13
15
|
with open(config_file_path) as _file:
|
|
14
16
|
return yaml.safe_load(_file).get(util_name, {})
|
|
@@ -39,7 +41,7 @@ class ListParamType(click.ParamType):
|
|
|
39
41
|
|
|
40
42
|
name = "list"
|
|
41
43
|
|
|
42
|
-
def convert(self, cli_value, param, ctx):
|
|
44
|
+
def convert(self, cli_value: Any, param: click.Parameter | None, ctx: click.Context | None) -> Any:
|
|
43
45
|
"""Converts CLI value to the list structure.
|
|
44
46
|
|
|
45
47
|
Args:
|
|
@@ -70,7 +72,7 @@ class ListParamType(click.ParamType):
|
|
|
70
72
|
)
|
|
71
73
|
|
|
72
74
|
|
|
73
|
-
def all_python_files():
|
|
75
|
+
def all_python_files() -> Iterable[str]:
|
|
74
76
|
"""
|
|
75
77
|
Get all python files from current directory and subdirectories
|
|
76
78
|
"""
|
|
@@ -2,13 +2,22 @@
|
|
|
2
2
|
omit = ["tests/*"]
|
|
3
3
|
|
|
4
4
|
[tool.coverage.report]
|
|
5
|
-
fail_under =
|
|
5
|
+
fail_under = 75
|
|
6
6
|
skip_empty = true
|
|
7
7
|
|
|
8
8
|
[tool.coverage.html]
|
|
9
9
|
directory = ".tests_coverage"
|
|
10
10
|
show_contexts = true
|
|
11
11
|
|
|
12
|
+
[tool.mypy]
|
|
13
|
+
show_error_codes = true
|
|
14
|
+
warn_unused_ignores = true
|
|
15
|
+
check_untyped_defs = true
|
|
16
|
+
disallow_any_generics = true
|
|
17
|
+
disallow_incomplete_defs = true
|
|
18
|
+
disallow_untyped_defs = true
|
|
19
|
+
no_implicit_optional = true
|
|
20
|
+
|
|
12
21
|
[tool.ruff]
|
|
13
22
|
preview = true
|
|
14
23
|
line-length = 120
|
|
@@ -20,7 +29,7 @@ exclude = [".git", ".venv", ".mypy_cache", ".tox", "__pycache__"]
|
|
|
20
29
|
|
|
21
30
|
[tool.poetry]
|
|
22
31
|
name = "python-utility-scripts"
|
|
23
|
-
version = "0.0.
|
|
32
|
+
version = "0.0.14"
|
|
24
33
|
description = "Python utility scripts"
|
|
25
34
|
authors = ["dbasunag <dbasunag@redhat.com>"]
|
|
26
35
|
license = "Apache License 2.0"
|
|
@@ -39,14 +48,13 @@ packages = [{ include = "apps" }]
|
|
|
39
48
|
pyutils-unusedcode = "apps.unused_code.unused_code:get_unused_functions"
|
|
40
49
|
pyutils-polarion-verify-tc-requirements = "apps.polarion.polarion_verify_tc_requirements:has_verify"
|
|
41
50
|
|
|
42
|
-
|
|
43
51
|
[tool.poetry.dependencies]
|
|
44
52
|
python = "^3.8"
|
|
45
53
|
python-simple-logger = "^1.0.8"
|
|
46
54
|
pylero = "^0.0.8"
|
|
47
|
-
pyyaml = "*"
|
|
48
55
|
pyhelper-utils = "^0.0.3"
|
|
49
56
|
pytest-mock = "^3.14.0"
|
|
57
|
+
pyyaml = "^6.0.1"
|
|
50
58
|
|
|
51
59
|
[tool.poetry.group.dev.dependencies]
|
|
52
60
|
ipdb = "^0.13.13"
|
|
@@ -58,12 +66,6 @@ enable = false
|
|
|
58
66
|
pattern = "((?P<epoch>\\d+)!)?(?P<base>\\d+(\\.\\d+)*)"
|
|
59
67
|
|
|
60
68
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
69
|
[tool.poetry.group.test.dependencies]
|
|
68
70
|
pytest = "^8.0.0"
|
|
69
71
|
pytest-cov = "^4.1.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_utility_scripts-0.0.13 → python_utility_scripts-0.0.14}/apps/unused_code/__init__.py
RENAMED
|
File without changes
|