python-utility-scripts 0.0.8__tar.gz → 0.0.10__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.8 → python_utility_scripts-0.0.10}/PKG-INFO +5 -2
- {python_utility_scripts-0.0.8 → python_utility_scripts-0.0.10}/README.md +2 -1
- python_utility_scripts-0.0.10/apps/polarion/README.md +32 -0
- python_utility_scripts-0.0.10/apps/polarion/polarion_utils.py +45 -0
- python_utility_scripts-0.0.10/apps/polarion/polarion_verify_tc_requirements.py +49 -0
- {python_utility_scripts-0.0.8 → python_utility_scripts-0.0.10}/apps/unused_code/README.md +6 -6
- python_utility_scripts-0.0.10/apps/unused_code/__init__.py +0 -0
- {python_utility_scripts-0.0.8 → python_utility_scripts-0.0.10}/apps/unused_code/unused_code.py +8 -13
- {python_utility_scripts-0.0.8 → python_utility_scripts-0.0.10}/apps/utils.py +9 -0
- {python_utility_scripts-0.0.8 → python_utility_scripts-0.0.10}/pyproject.toml +21 -2
- {python_utility_scripts-0.0.8 → python_utility_scripts-0.0.10}/LICENSE +0 -0
- {python_utility_scripts-0.0.8 → python_utility_scripts-0.0.10}/apps/__init__.py +0 -0
- {python_utility_scripts-0.0.8/apps/unused_code → python_utility_scripts-0.0.10/apps/polarion}/__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.10
|
|
4
4
|
Summary: Python utility scripts
|
|
5
5
|
Home-page: https://github.com/RedHatQE/python-utility-scripts
|
|
6
6
|
License: Apache-2.0
|
|
@@ -15,7 +15,9 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Requires-Dist: pyhelper-utils (>=0.0.3,<0.0.4)
|
|
18
19
|
Requires-Dist: pylero (>=0.0.8,<0.0.9)
|
|
20
|
+
Requires-Dist: pytest-mock (>=3.14.0,<4.0.0)
|
|
19
21
|
Requires-Dist: python-simple-logger (>=1.0.8,<2.0.0)
|
|
20
22
|
Requires-Dist: pyyaml
|
|
21
23
|
Project-URL: Documentation, https://github.com/RedHatQE/python-utility-scripts/blob/main/README.md
|
|
@@ -24,7 +26,8 @@ Description-Content-Type: text/markdown
|
|
|
24
26
|
|
|
25
27
|
# python-utility-scripts
|
|
26
28
|
Repository for various python utility scripts
|
|
27
|
-
* [
|
|
29
|
+
* [pyutils-unusedcode](https://github.com/RedHatQE/python-utility-scripts/blob/main/apps/unused_code/README.md)
|
|
30
|
+
* [pyutils-polarion-verify-tc-requirements](https://github.com/RedHatQE/python-utility-scripts/blob/main/apps/polarion/README.md)
|
|
28
31
|
|
|
29
32
|
## Installation
|
|
30
33
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# python-utility-scripts
|
|
2
2
|
Repository for various python utility scripts
|
|
3
|
-
* [
|
|
3
|
+
* [pyutils-unusedcode](https://github.com/RedHatQE/python-utility-scripts/blob/main/apps/unused_code/README.md)
|
|
4
|
+
* [pyutils-polarion-verify-tc-requirements](https://github.com/RedHatQE/python-utility-scripts/blob/main/apps/polarion/README.md)
|
|
4
5
|
|
|
5
6
|
## Installation
|
|
6
7
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# scripts to interact with Polarion instance
|
|
2
|
+
|
|
3
|
+
## pyutils-polarion-verify-tc-requirements
|
|
4
|
+
Utility to check if test cases in a pytest repository has associated Polarion requirements.
|
|
5
|
+
|
|
6
|
+
## Requirements
|
|
7
|
+
This script uses [pylero](https://github.com/RedHatQE/pylero) and expects .pylero config file to be present in current directory or user's home directory.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
```bash
|
|
11
|
+
pyutils-polarion-verify-tc-requirements --help
|
|
12
|
+
pyutils-polarion-verify-tc-requirements --project_id <project_id>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Config file
|
|
16
|
+
To specify polation project id for polarion scripts, it can be added to the config file:
|
|
17
|
+
`~/.config/python-utility-scripts/config.yaml`
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Example:
|
|
21
|
+
|
|
22
|
+
```yaml
|
|
23
|
+
pyutils-polarion-verify-tc-requirements :
|
|
24
|
+
project_id: "<project_id>"
|
|
25
|
+
```
|
|
26
|
+
This would run the polarion requirement check against Polarion project <project_id>
|
|
27
|
+
|
|
28
|
+
To run from CLI with `--project-id`
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pyutils-polarion-verify-tc-requirements --project-id 'my_project_id'
|
|
32
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from simple_logger.logger import get_logger
|
|
2
|
+
import shlex
|
|
3
|
+
import subprocess
|
|
4
|
+
from pylero.exceptions import PyleroLibException
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
LOGGER = get_logger(name=__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def git_diff():
|
|
11
|
+
data = subprocess.check_output(shlex.split("git diff HEAD^-1"))
|
|
12
|
+
data = data.decode("utf-8")
|
|
13
|
+
return data
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def git_diff_lines():
|
|
17
|
+
diff = {}
|
|
18
|
+
for line in git_diff().splitlines():
|
|
19
|
+
LOGGER.debug(line)
|
|
20
|
+
if line.startswith("+"):
|
|
21
|
+
diff.setdefault("added", []).append(line)
|
|
22
|
+
|
|
23
|
+
return diff
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def validate_polarion_requirements(polarion_test_ids, polarion_project_id):
|
|
27
|
+
tests_with_missing_requirements = []
|
|
28
|
+
from pylero.work_item import Requirement, TestCase
|
|
29
|
+
|
|
30
|
+
for _id in polarion_test_ids:
|
|
31
|
+
has_req = False
|
|
32
|
+
LOGGER.debug(f"Checking if {_id} verifies any requirement")
|
|
33
|
+
tc = TestCase(project_id=polarion_project_id, work_item_id=_id)
|
|
34
|
+
for link in tc.linked_work_items:
|
|
35
|
+
try:
|
|
36
|
+
Requirement(project_id=polarion_project_id, work_item_id=link.work_item_id)
|
|
37
|
+
has_req = True
|
|
38
|
+
break
|
|
39
|
+
except PyleroLibException:
|
|
40
|
+
continue
|
|
41
|
+
|
|
42
|
+
if not has_req:
|
|
43
|
+
LOGGER.error(f"{_id}: Is missing requirement")
|
|
44
|
+
tests_with_missing_requirements.append(_id)
|
|
45
|
+
return tests_with_missing_requirements
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import logging
|
|
3
|
+
from simple_logger.logger import get_logger
|
|
4
|
+
import os
|
|
5
|
+
import click
|
|
6
|
+
|
|
7
|
+
from apps.polarion.polarion_utils import (
|
|
8
|
+
git_diff_lines,
|
|
9
|
+
validate_polarion_requirements,
|
|
10
|
+
)
|
|
11
|
+
from apps.utils import get_util_config
|
|
12
|
+
|
|
13
|
+
LOGGER = get_logger(name=__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@click.command()
|
|
17
|
+
@click.option(
|
|
18
|
+
"--config-file-path",
|
|
19
|
+
help="Provide absolute path to the config file. Any CLI option(s) would override YAML file",
|
|
20
|
+
type=click.Path(),
|
|
21
|
+
default=os.path.expanduser("~/.config/python-utility-scripts/config.yaml"),
|
|
22
|
+
)
|
|
23
|
+
@click.option("--project-id", "-p", help="Provide the polarion project id")
|
|
24
|
+
@click.option("--verbosity", default=False, is_flag=True)
|
|
25
|
+
def has_verify(config_file_path, project_id, verbosity):
|
|
26
|
+
if verbosity:
|
|
27
|
+
LOGGER.setLevel(logging.DEBUG)
|
|
28
|
+
polarion_project_id = project_id or get_util_config(
|
|
29
|
+
util_name="pyutils-polarion-verify-tc-requirements", config_file_path=config_file_path
|
|
30
|
+
).get("project_id")
|
|
31
|
+
if not polarion_project_id:
|
|
32
|
+
click.echo("Polarion project id must be passed via config file or command line")
|
|
33
|
+
raise click.Abort()
|
|
34
|
+
|
|
35
|
+
if added_ids := re.findall(
|
|
36
|
+
rf"pytest.mark.polarion.*({polarion_project_id}-[0-9]+)",
|
|
37
|
+
"\n".join(git_diff_lines().get("added", [])),
|
|
38
|
+
re.MULTILINE | re.IGNORECASE,
|
|
39
|
+
):
|
|
40
|
+
LOGGER.debug(f"Checking following ids: {added_ids}")
|
|
41
|
+
if tests_with_missing_requirements := validate_polarion_requirements(
|
|
42
|
+
polarion_test_ids=added_ids, polarion_project_id=polarion_project_id
|
|
43
|
+
):
|
|
44
|
+
click.echo(f"TestCases with missing requirement: {tests_with_missing_requirements}")
|
|
45
|
+
raise click.Abort()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
has_verify()
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pyutils-unusedcode
|
|
2
2
|
Helper to identify unused code in a pytest repository. It should be run from inside the test repository using this tool.
|
|
3
3
|
|
|
4
4
|
## Usage
|
|
5
5
|
|
|
6
6
|
```bash
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
pyutils-unusedcode
|
|
8
|
+
pyutils-unusedcode --help
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Config file
|
|
@@ -15,7 +15,7 @@ To skip unused code check on specific files or functions of a repository, a conf
|
|
|
15
15
|
### Example:
|
|
16
16
|
|
|
17
17
|
```yaml
|
|
18
|
-
|
|
18
|
+
pyutils-unusedcode:
|
|
19
19
|
exclude_files:
|
|
20
20
|
- "my_exclude_file.py"
|
|
21
21
|
exclude_function_prefix:
|
|
@@ -26,11 +26,11 @@ This would exclude any functions with prefix my_exclude_function_prefix and file
|
|
|
26
26
|
To run from CLI with `--exclude-function-prefixes`
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
|
-
|
|
29
|
+
pyutils-unusedcode --exclude-function-prefixes 'my_exclude_function1,my_exclude_function2'
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
To run from CLI with `--exclude-files`
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
|
-
|
|
35
|
+
pyutils-unusedcode --exclude-files 'my_exclude_file1.py,my_exclude_file2.py'
|
|
36
36
|
```
|
|
File without changes
|
{python_utility_scripts-0.0.8 → python_utility_scripts-0.0.10}/apps/unused_code/unused_code.py
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import ast
|
|
2
|
+
import logging
|
|
2
3
|
import os
|
|
3
4
|
import subprocess
|
|
4
5
|
import click
|
|
5
|
-
import yaml
|
|
6
6
|
from simple_logger.logger import get_logger
|
|
7
7
|
|
|
8
|
-
from apps.utils import all_python_files, ListParamType
|
|
8
|
+
from apps.utils import all_python_files, ListParamType, get_util_config
|
|
9
9
|
|
|
10
10
|
LOGGER = get_logger(name=__name__)
|
|
11
11
|
|
|
@@ -42,19 +42,12 @@ def _iter_functions(tree):
|
|
|
42
42
|
yield elm
|
|
43
43
|
|
|
44
44
|
|
|
45
|
-
def read_config_file(config_file_path):
|
|
46
|
-
if os.path.exists(config_file_path):
|
|
47
|
-
with open(config_file_path) as _file:
|
|
48
|
-
return yaml.safe_load(_file)
|
|
49
|
-
return {}
|
|
50
|
-
|
|
51
|
-
|
|
52
45
|
def is_ignore_function_list(ignore_prefix_list, function):
|
|
53
46
|
ignore_function_lists = [
|
|
54
47
|
function.name for ignore_prefix in ignore_prefix_list if function.name.startswith(ignore_prefix)
|
|
55
48
|
]
|
|
56
49
|
if ignore_function_lists:
|
|
57
|
-
LOGGER.
|
|
50
|
+
LOGGER.debug(f"Following functions are getting skipped: {ignore_function_lists}")
|
|
58
51
|
return True
|
|
59
52
|
|
|
60
53
|
|
|
@@ -75,10 +68,12 @@ def is_ignore_function_list(ignore_prefix_list, function):
|
|
|
75
68
|
help="Provide a comma-separated string or list of function prefixes to exclude",
|
|
76
69
|
type=ListParamType(),
|
|
77
70
|
)
|
|
78
|
-
|
|
71
|
+
@click.option("--verbosity", default=False, is_flag=True)
|
|
72
|
+
def get_unused_functions(config_file_path, exclude_files, exclude_function_prefixes, verbosity):
|
|
73
|
+
if verbosity:
|
|
74
|
+
LOGGER.setLevel(logging.DEBUG)
|
|
79
75
|
_unused_functions = []
|
|
80
|
-
|
|
81
|
-
unused_code_config = config_yaml.get("pyappsutils-unusedcode", {})
|
|
76
|
+
unused_code_config = get_util_config(util_name="pyutils-unusedcode", config_file_path=config_file_path)
|
|
82
77
|
func_ignore_prefix = exclude_function_prefixes or unused_code_config.get("exclude_function_prefix", [])
|
|
83
78
|
file_ignore_list = exclude_files or unused_code_config.get("exclude_files", [])
|
|
84
79
|
for py_file in all_python_files():
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
|
+
|
|
3
|
+
import yaml
|
|
2
4
|
from simple_logger.logger import get_logger
|
|
3
5
|
import json
|
|
4
6
|
import click
|
|
@@ -6,6 +8,13 @@ import click
|
|
|
6
8
|
LOGGER = get_logger(name=__name__)
|
|
7
9
|
|
|
8
10
|
|
|
11
|
+
def get_util_config(util_name, config_file_path):
|
|
12
|
+
if os.path.exists(config_file_path):
|
|
13
|
+
with open(config_file_path) as _file:
|
|
14
|
+
return yaml.safe_load(_file).get(util_name, {})
|
|
15
|
+
return {}
|
|
16
|
+
|
|
17
|
+
|
|
9
18
|
# Reference: https://gist.github.com/welel/9cf860dd3f4d3e09f9b4305878b3a04e
|
|
10
19
|
class ListParamType(click.ParamType):
|
|
11
20
|
"""Represents the list type of a CLI parameter.
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
[tool.coverage.run]
|
|
2
|
+
omit = ["tests/*"]
|
|
3
|
+
|
|
4
|
+
[tool.coverage.report]
|
|
5
|
+
fail_under = 60
|
|
6
|
+
skip_empty = true
|
|
7
|
+
|
|
8
|
+
[tool.coverage.html]
|
|
9
|
+
directory = ".tests_coverage"
|
|
10
|
+
show_contexts = true
|
|
11
|
+
|
|
1
12
|
[tool.ruff]
|
|
2
13
|
preview = true
|
|
3
14
|
line-length = 120
|
|
@@ -9,7 +20,7 @@ exclude = [".git", ".venv", ".mypy_cache", ".tox", "__pycache__"]
|
|
|
9
20
|
|
|
10
21
|
[tool.poetry]
|
|
11
22
|
name = "python-utility-scripts"
|
|
12
|
-
version = "0.0.
|
|
23
|
+
version = "0.0.10"
|
|
13
24
|
description = "Python utility scripts"
|
|
14
25
|
authors = ["dbasunag <dbasunag@redhat.com>"]
|
|
15
26
|
license = "Apache License 2.0"
|
|
@@ -25,7 +36,8 @@ classifiers = [
|
|
|
25
36
|
packages = [{ include = "apps" }]
|
|
26
37
|
|
|
27
38
|
[tool.poetry.scripts]
|
|
28
|
-
|
|
39
|
+
pyutils-unusedcode = "apps.unused_code.unused_code:get_unused_functions"
|
|
40
|
+
pyutils-polarion-verify-tc-requirements = "apps.polarion.polarion_verify_tc_requirements:has_verify"
|
|
29
41
|
|
|
30
42
|
|
|
31
43
|
[tool.poetry.dependencies]
|
|
@@ -33,11 +45,14 @@ python = "^3.8"
|
|
|
33
45
|
python-simple-logger = "^1.0.8"
|
|
34
46
|
pylero = "^0.0.8"
|
|
35
47
|
pyyaml = "*"
|
|
48
|
+
pyhelper-utils = "^0.0.3"
|
|
49
|
+
pytest-mock = "^3.14.0"
|
|
36
50
|
|
|
37
51
|
[tool.poetry.group.dev.dependencies]
|
|
38
52
|
ipdb = "^0.13.13"
|
|
39
53
|
ipython = "*"
|
|
40
54
|
|
|
55
|
+
|
|
41
56
|
[tool.poetry-dynamic-versioning]
|
|
42
57
|
enable = false
|
|
43
58
|
pattern = "((?P<epoch>\\d+)!)?(?P<base>\\d+(\\.\\d+)*)"
|
|
@@ -45,8 +60,12 @@ pattern = "((?P<epoch>\\d+)!)?(?P<base>\\d+(\\.\\d+)*)"
|
|
|
45
60
|
|
|
46
61
|
|
|
47
62
|
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
48
66
|
[tool.poetry.group.test.dependencies]
|
|
49
67
|
pytest = "^8.0.0"
|
|
68
|
+
pytest-cov = "^4.1.0"
|
|
50
69
|
|
|
51
70
|
[tool.poetry-dynamic-versioning.substitution]
|
|
52
71
|
files = ["VERSION"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|