pyright-to-gitlab 1.0.1__py3-none-any.whl

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.
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyright-to-gitlab
3
+ Version: 1.0.1
4
+ Summary: Convert Pyright JSON output to GitLab CI/CD format
5
+ Author: Micha Schöll
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Micha Schöll
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ License-File: LICENSE
28
+ Requires-Python: >=3.6
29
+ Description-Content-Type: text/markdown
30
+
31
+ # pyright to gitlab
32
+ Simple Python script to convert a pyright --outputjson to a gitlab code-quality report.
33
+
34
+ ## Usage
35
+ Run the script with the path to the pyright output file:
36
+ ```shell
37
+ $ pip install pyright-to-gitlab
38
+ $ pyright . --outputjson | pyright-to-gitlab > code-quality.json
39
+ ```
40
+
41
+ Alternatively, the module can be called:
42
+ ```shell
43
+ $ pip install pyright-to-gitlab
44
+ $ pyright . --outputjson | python -m pyright_to_gitlab > code-quality.json
45
+ ```
46
+ ### Custom path prefix
47
+ The `--prefix` option adds a custom prefix to the file paths in the output. This is
48
+ useful if the paths in the pyright output are not relative to the root of the repository.
49
+
50
+
51
+ ```shell
52
+ $ pyright . --outputjson | pyright-to-gitlab --prefix my-app/ > code-quality.json
53
+ ```
54
+
55
+ ## Testing
56
+ To run the tests, execute
57
+ ```shell
58
+ $ uv run pytest tests/
59
+ ```
@@ -0,0 +1,6 @@
1
+ pyright_to_gitlab.py,sha256=LbPxle60_JFBGMtPZszoNaFmnXEzfWBhc67PuZ1669g,2251
2
+ pyright_to_gitlab-1.0.1.dist-info/METADATA,sha256=oztGH-gx0w-OAgVZ6_ezwqTHSAcXkAvhw-wnBLRxsew,2289
3
+ pyright_to_gitlab-1.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
4
+ pyright_to_gitlab-1.0.1.dist-info/entry_points.txt,sha256=MbNff91bPuO2XhW0P03N9O1Z7xtlr3x9duU5BftRbZo,60
5
+ pyright_to_gitlab-1.0.1.dist-info/licenses/LICENSE,sha256=tY29-MdtyUNoC3XN4IBzu_jxmb8U82z9UvLkQJuBiJM,1070
6
+ pyright_to_gitlab-1.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pyrigh-to-gitlab = pyright_to_gitlab:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Micha Schöll
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
pyright_to_gitlab.py ADDED
@@ -0,0 +1,66 @@
1
+ """Convert pyright.json output to GitLab Code Quality report format."""
2
+
3
+ import argparse
4
+ import hashlib
5
+ import json
6
+ import sys
7
+ from typing import cast
8
+
9
+
10
+ def _pyright_to_gitlab(prefix: str = "") -> str:
11
+ """Convert pyright.json output to GitLab Code Quality report format.
12
+
13
+ :arg prefix: A string to prepend to each file path in the output.
14
+ This is useful if the application is in a subdirectory of the repository.
15
+ :return: JSON of issues in GitLab Code Quality report format.
16
+
17
+ Pyright format at https://github.com/microsoft/pyright/blob/main/docs/command-line.md
18
+ Gitlab format at https://docs.gitlab.com/ci/testing/code_quality/#code-quality-report-format
19
+ """
20
+ data = cast("dict", json.load(sys.stdin))
21
+
22
+ issues = []
23
+ for issue in data.get("generalDiagnostics", []):
24
+ file = issue["file"]
25
+ start, end = issue["range"]["start"], issue["range"]["end"]
26
+ rule = "pyright: " + issue.get("rule", "")
27
+ severity = "major" if issue["severity"] == "error" else "minor"
28
+ # unique fingerprint
29
+ fp_str = "--".join([str(start), str(end), rule])
30
+
31
+ issues.append(
32
+ {
33
+ "description": issue["message"],
34
+ "severity": severity,
35
+ "fingerprint": hashlib.sha3_224(fp_str.encode()).hexdigest(),
36
+ "check_name": rule,
37
+ "location": {
38
+ "path": f"{prefix}{file}",
39
+ "positions": {
40
+ "begin": {"line": start["line"], "column": start["character"]},
41
+ "end": {"line": end["line"], "column": end["character"]},
42
+ },
43
+ },
44
+ }
45
+ )
46
+ return json.dumps(issues, indent=2)
47
+
48
+
49
+ def main() -> None:
50
+ """Parse arguments and call the conversion function."""
51
+ parser = argparse.ArgumentParser(
52
+ description="Convert pyright.json to GitLab Code Quality report."
53
+ )
54
+ parser.add_argument(
55
+ "--prefix",
56
+ type=str,
57
+ default="",
58
+ help="Prefix to add to each file (default: empty string)",
59
+ )
60
+ args = parser.parse_args()
61
+
62
+ print(_pyright_to_gitlab(prefix=args.prefix)) # noqa: T201
63
+
64
+
65
+ if __name__ == "__main__": # pragma: no cover
66
+ main()