Skip to content

Commit 4d78f2e

Browse files
committedJan 6, 2025··
feat: ruff
Introduces Ruff for formatting and linting and removes flake8, isort, and black. Fixes the resulting linter errors. Signed-off-by: Maxim Stykow <maxim.stykow@tngtech.com>
1 parent e05d9bb commit 4d78f2e

24 files changed

+163
-588
lines changed
 

‎.flake8

-13
This file was deleted.

‎.github/workflows/lint_and_run_tests.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@ jobs:
3535
- name: Install the project
3636
run: uv sync --locked
3737

38-
- name: Run isort
39-
run: uv run isort src/ tests/ --check
38+
- name: Run Ruff linter
39+
run: uv run ruff check
4040

41-
- name: Run black
42-
run: uv run black src/ tests/ --check
43-
44-
- name: Run flake8
45-
run: uv run flake8 src/ tests/
41+
- name: Run Ruff formatter
42+
run: uv run ruff format --check
4643

4744
- name: Run mypy
4845
run: uv run python -m mypy src/ tests/

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ __pycache__/
88
.vscode/*
99

1010
.mypy_cache/
11+
.ruff_cache
1112

1213
.venv/
1314
dist/

‎.pre-commit-config.yaml

+4-12
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44
repos:
5-
- repo: https://github.com/pycqa/isort
6-
rev: 5.12.0
5+
- repo: https://github.com/astral-sh/ruff-pre-commit
6+
rev: v0.8.6
77
hooks:
8-
- id: isort
9-
name: isort (python)
10-
- repo: https://github.com/psf/black
11-
rev: 23.1.0
12-
hooks:
13-
- id: black
14-
- repo: https://github.com/pycqa/flake8
15-
rev: 6.0.0
16-
hooks:
17-
- id: flake8
8+
- id: ruff
9+
- id: ruff-format
1810
- repo: https://github.com/pre-commit/mirrors-mypy
1911
rev: v1.4.1
2012
hooks:

‎README.md

+3-9
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,8 @@ Options:
5353
To test your changes, run
5454
5555
```bash
56-
uv run pytest
56+
uv run ruff check
57+
uv run ruff format --check
5758
uv run python -m mypy src/ tests/
58-
```
59-
60-
The package uses pre-commit hooks to check the code style of your changes.
61-
It also provides a script `(./scripts/linter_and_formatting.sh)` to make your changes compliant with the expected
62-
code style. To use this script under linux run
63-
64-
```bash
65-
./scripts/linter_and_formatting.sh # in the root of the repo
59+
uv run pytest
6660
```

‎pyproject.toml

+25-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ spdx2opossum = "opossum_lib.cli:spdx2opossum"
2323
[dependency-groups]
2424
test = ["pytest>=8.3.4,<9"]
2525
dev = [
26-
"black>=24.8.0,<25",
27-
"isort>=5.13.2,<6",
28-
"flake8>=7.1.1,<8",
2926
"mypy>=1.14.1,<2",
3027
"pre-commit>=4.0.1,<5",
28+
"ruff>=0.8.6",
3129
]
3230

3331
[tool.uv]
@@ -37,9 +35,6 @@ default-groups = [
3735
]
3836
package = true
3937

40-
[tool.isort]
41-
profile = "black"
42-
4338
[tool.mypy]
4439
warn_return_any = true
4540
warn_unused_configs = true
@@ -54,3 +49,27 @@ ignore_missing_imports = true
5449

5550
[tool.pytest.ini_options]
5651
testpaths = ["tests"]
52+
53+
[tool.ruff]
54+
line-length = 88
55+
56+
[tool.ruff.lint]
57+
select = [
58+
# pycodestyle
59+
"E",
60+
# Pyflakes
61+
"F",
62+
# pyupgrade
63+
"UP",
64+
# flake8-bugbear
65+
"B",
66+
# flake8-simplify
67+
"SIM",
68+
# isort
69+
"I",
70+
]
71+
extend-select = ["E501"]
72+
73+
[tool.ruff.format]
74+
quote-style = "double"
75+
docstring-code-format = true

‎scripts/linter_and_formatting.sh

-24
This file was deleted.

‎src/opossum.lib.py.egg-info/PKG-INFO

-280
This file was deleted.

‎src/opossum.lib.py.egg-info/SOURCES.txt

-27
This file was deleted.

‎src/opossum.lib.py.egg-info/dependency_links.txt

-1
This file was deleted.

‎src/opossum.lib.py.egg-info/entry_points.txt

-2
This file was deleted.

‎src/opossum.lib.py.egg-info/requires.txt

-3
This file was deleted.

‎src/opossum.lib.py.egg-info/top_level.txt

-1
This file was deleted.

‎src/opossum_lib/attribution_generation.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44
from io import StringIO
5-
from typing import Optional
65

76
from spdx_tools.spdx.model.document import CreationInfo
87
from spdx_tools.spdx.model.file import File
@@ -22,7 +21,7 @@
2221
from opossum_lib.opossum_file import OpossumPackage, SourceInfo
2322

2423

25-
def _get_purl(package: Package) -> Optional[str]:
24+
def _get_purl(package: Package) -> str | None:
2625
for external_reference in package.external_references:
2726
if external_reference.reference_type == PURL:
2827
return external_reference.locator

‎src/opossum_lib/file_generation.py

+25-30
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import uuid
66
from dataclasses import fields
77
from pathlib import Path
8-
from typing import Dict, List, Tuple, Union
98
from zipfile import ZIP_DEFLATED, ZipFile
109

1110
from networkx import DiGraph, shortest_path
@@ -55,33 +54,29 @@ def write_dict_to_file(
5554

5655

5756
def to_dict(
58-
element: Union[
59-
Resource,
60-
Metadata,
61-
OpossumPackage,
62-
OpossumInformation,
63-
SourceInfo,
64-
ExternalAttributionSource,
65-
str,
66-
int,
67-
bool,
68-
Dict[str, OpossumPackage],
69-
Dict[str, List[str]],
70-
List[str],
71-
None,
72-
]
73-
) -> Union[Dict, str, List[str], bool, int, None]:
57+
element: Resource
58+
| Metadata
59+
| OpossumPackage
60+
| OpossumInformation
61+
| SourceInfo
62+
| ExternalAttributionSource
63+
| str
64+
| int
65+
| bool
66+
| dict[str, OpossumPackage]
67+
| dict[str, list[str]]
68+
| list[str]
69+
| None,
70+
) -> dict | str | list[str] | bool | int | None:
7471
if isinstance(element, Resource):
7572
return element.to_dict()
7673
if isinstance(
7774
element,
78-
(
79-
Metadata,
80-
OpossumPackage,
81-
OpossumInformation,
82-
SourceInfo,
83-
ExternalAttributionSource,
84-
),
75+
Metadata
76+
| OpossumPackage
77+
| OpossumInformation
78+
| SourceInfo
79+
| ExternalAttributionSource,
8580
):
8681
result = []
8782
for f in fields(element):
@@ -97,8 +92,8 @@ def to_dict(
9792
def generate_json_file_from_tree(tree: DiGraph) -> OpossumInformation:
9893
metadata = create_metadata(tree)
9994
resources = Resource(type=ResourceType.TOP_LEVEL)
100-
resources_to_attributions: Dict[str, List[str]] = dict()
101-
external_attributions: Dict[str, OpossumPackage] = dict()
95+
resources_to_attributions: dict[str, list[str]] = dict()
96+
external_attributions: dict[str, OpossumPackage] = dict()
10297
attribution_breakpoints = []
10398
external_attribution_sources = {
10499
SPDX_FILE_IDENTIFIER: ExternalAttributionSource(SPDX_FILE_IDENTIFIER, 500),
@@ -117,8 +112,8 @@ def generate_json_file_from_tree(tree: DiGraph) -> OpossumInformation:
117112
"A tree should always have a node without incoming edge."
118113
)
119114
for node in connected_subgraph.nodes():
120-
path: List[str] = shortest_path(connected_subgraph, source, node)
121-
path_with_labels: List[Tuple[str, ResourceType]] = (
115+
path: list[str] = shortest_path(connected_subgraph, source, node)
116+
path_with_labels: list[tuple[str, ResourceType]] = (
122117
_replace_node_ids_with_labels_and_add_resource_type(
123118
path, connected_subgraph
124119
)
@@ -149,8 +144,8 @@ def generate_json_file_from_tree(tree: DiGraph) -> OpossumInformation:
149144

150145

151146
def create_attribution_and_link_with_resource(
152-
external_attributions: Dict[OpossumPackageIdentifier, OpossumPackage],
153-
resources_to_attributions: Dict[OpossumPackageIdentifier, List[str]],
147+
external_attributions: dict[OpossumPackageIdentifier, OpossumPackage],
148+
resources_to_attributions: dict[OpossumPackageIdentifier, list[str]],
154149
file_path: str,
155150
node: str,
156151
tree: DiGraph,

‎src/opossum_lib/graph_generation.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2023 TNG Technology Consulting GmbH <https://www.tngtech.com>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import Optional, Union
54

65
from networkx import DiGraph, set_node_attributes
76
from spdx_tools.spdx.graph_generation import generate_relationship_graph_from_spdx
@@ -21,9 +20,9 @@ def generate_graph_from_spdx(document: Document) -> DiGraph:
2120

2221
def _create_label_for_node(graph: DiGraph, node: str) -> str:
2322
if _node_represents_a_spdx_element(graph, node):
24-
element_node: Optional[Union[CreationInfo, File, Package, Snippet]] = (
25-
graph.nodes[node]["element"]
26-
)
23+
element_node: CreationInfo | File | Package | Snippet | None = graph.nodes[
24+
node
25+
]["element"]
2726
if element_node:
2827
return element_node.name or element_node.spdx_id
2928
else:

‎src/opossum_lib/helper_methods.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2023 TNG Technology Consulting GmbH <https://www.tngtech.com>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import Any, Dict, List, Optional, Tuple
4+
from typing import Any
55

66
from networkx import DiGraph, weakly_connected_components
77
from spdx_tools.spdx.constants import DOCUMENT_SPDX_ID
@@ -10,15 +10,15 @@
1010
from opossum_lib.opossum_file import ResourceType
1111

1212

13-
def _get_source_for_graph_traversal(connected_subgraph: DiGraph) -> Optional[str]:
13+
def _get_source_for_graph_traversal(connected_subgraph: DiGraph) -> str | None:
1414
return (
1515
DOCUMENT_SPDX_ID
1616
if DOCUMENT_SPDX_ID in connected_subgraph.nodes
1717
else _get_node_without_incoming_edge(connected_subgraph)
1818
)
1919

2020

21-
def _get_node_without_incoming_edge(graph: DiGraph) -> Optional[str]:
21+
def _get_node_without_incoming_edge(graph: DiGraph) -> str | None:
2222
for node, degree in graph.in_degree():
2323
if degree == 0 and _node_represents_a_spdx_element(graph, node):
2424
return str(node)
@@ -31,7 +31,7 @@ def _node_represents_a_spdx_element(graph: DiGraph, node: str) -> bool:
3131
return "element" in graph.nodes[node]
3232

3333

34-
def _weakly_connected_component_sub_graphs(graph: DiGraph) -> List[DiGraph]:
34+
def _weakly_connected_component_sub_graphs(graph: DiGraph) -> list[DiGraph]:
3535
connected_sub_graphs = []
3636
for connected_set in weakly_connected_components(
3737
graph
@@ -41,7 +41,7 @@ def _weakly_connected_component_sub_graphs(graph: DiGraph) -> List[DiGraph]:
4141
return connected_sub_graphs
4242

4343

44-
def _create_file_path_from_graph_path(path: List[str], graph: DiGraph) -> str:
44+
def _create_file_path_from_graph_path(path: list[str], graph: DiGraph) -> str:
4545
base_path = "/" + "/".join(
4646
[_replace_prefix(graph.nodes[node]["label"]) for node in path]
4747
)
@@ -51,8 +51,8 @@ def _create_file_path_from_graph_path(path: List[str], graph: DiGraph) -> str:
5151

5252

5353
def _replace_node_ids_with_labels_and_add_resource_type(
54-
path: List[str], graph: DiGraph
55-
) -> List[Tuple[str, ResourceType]]:
54+
path: list[str], graph: DiGraph
55+
) -> list[tuple[str, ResourceType]]:
5656
resulting_path = []
5757
path_with_label_and_resource_type = [
5858
(
@@ -85,11 +85,11 @@ def _replace_prefix(label: str) -> str:
8585
return label
8686

8787

88-
def _get_resource_type(node_attributes: Dict[str, Any]) -> ResourceType:
89-
element = node_attributes.get("element", None)
88+
def _get_resource_type(node_attributes: dict[str, Any]) -> ResourceType:
89+
element = node_attributes.get("element")
9090
if isinstance(element, Package):
9191
return ResourceType.FOLDER
92-
elif isinstance(element, (Snippet, File)):
92+
elif isinstance(element, Snippet | File):
9393
return ResourceType.FILE
9494
else:
9595
return ResourceType.OTHER

‎src/opossum_lib/merger.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2023 TNG Technology Consulting GmbH <https://www.tngtech.com>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import Any, Dict, List
4+
from typing import Any
55

66
from opossum_lib.opossum_file import (
77
OpossumInformation,
@@ -13,7 +13,7 @@
1313

1414

1515
def merge_opossum_information(
16-
elements_to_merge: List[OpossumInformation],
16+
elements_to_merge: list[OpossumInformation],
1717
) -> OpossumInformation:
1818
expanded_opossum_information = [
1919
expand_opossum_package_identifier(opossum_information)
@@ -86,7 +86,7 @@ def expand_opossum_package_identifier(
8686
)
8787

8888

89-
def _merge_resources(resources: List[Resource]) -> Resource:
89+
def _merge_resources(resources: list[Resource]) -> Resource:
9090
merged_resource = Resource(ResourceType.TOP_LEVEL)
9191
for resource in resources:
9292
for path in resource.get_paths_of_all_leaf_nodes_with_types():
@@ -95,10 +95,10 @@ def _merge_resources(resources: List[Resource]) -> Resource:
9595

9696

9797
def _merge_resources_to_attributions(
98-
resources_to_attributions: List[Dict[ResourcePath, List[OpossumPackageIdentifier]]]
99-
) -> Dict[ResourcePath, List[OpossumPackageIdentifier]]:
100-
merged_resources_to_attributions: Dict[
101-
ResourcePath, List[OpossumPackageIdentifier]
98+
resources_to_attributions: list[dict[ResourcePath, list[OpossumPackageIdentifier]]],
99+
) -> dict[ResourcePath, list[OpossumPackageIdentifier]]:
100+
merged_resources_to_attributions: dict[
101+
ResourcePath, list[OpossumPackageIdentifier]
102102
] = dict()
103103
for resource_to_attribution in resources_to_attributions:
104104
for resource_path, identifiers in resource_to_attribution.items():
@@ -112,8 +112,8 @@ def _merge_resources_to_attributions(
112112

113113

114114
def _merge_attribution_breakpoints(
115-
attribution_breakpoints_to_merge: List[List[str]],
116-
) -> List[str]:
115+
attribution_breakpoints_to_merge: list[list[str]],
116+
) -> list[str]:
117117
merged_attribution_breakpoints = []
118118
for attribution_breakpoints in attribution_breakpoints_to_merge:
119119
merged_attribution_breakpoints.extend(
@@ -126,8 +126,8 @@ def _merge_attribution_breakpoints(
126126
return merged_attribution_breakpoints
127127

128128

129-
def _merge_dicts_without_duplicates(dicts: List[Dict[str, Any]]) -> Dict[str, Any]:
130-
merged_dict: Dict[str, Any] = dict()
129+
def _merge_dicts_without_duplicates(dicts: list[dict[str, Any]]) -> dict[str, Any]:
130+
merged_dict: dict[str, Any] = dict()
131131
for single_dict in dicts:
132132
for key, value in single_dict.items():
133133
if key in merged_dict and merged_dict.get(key) != value:

‎src/opossum_lib/opossum_file.py

+31-31
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from copy import deepcopy
77
from dataclasses import dataclass, field
88
from enum import Enum, auto
9-
from typing import Dict, List, Literal, Optional, Tuple, Union
9+
from typing import Literal
1010

1111
OpossumPackageIdentifier = str
1212
ResourcePath = str
@@ -16,50 +16,50 @@
1616
class OpossumInformation:
1717
metadata: Metadata
1818
resources: Resource
19-
externalAttributions: Dict[OpossumPackageIdentifier, OpossumPackage]
20-
resourcesToAttributions: Dict[ResourcePath, List[OpossumPackageIdentifier]]
21-
attributionBreakpoints: List[str] = field(default_factory=list)
22-
externalAttributionSources: Dict[str, ExternalAttributionSource] = field(
19+
externalAttributions: dict[OpossumPackageIdentifier, OpossumPackage]
20+
resourcesToAttributions: dict[ResourcePath, list[OpossumPackageIdentifier]]
21+
attributionBreakpoints: list[str] = field(default_factory=list)
22+
externalAttributionSources: dict[str, ExternalAttributionSource] = field(
2323
default_factory=dict
2424
)
2525

2626

2727
@dataclass(frozen=True)
2828
class SourceInfo:
2929
name: str
30-
documentConfidence: Optional[int] = 0
30+
documentConfidence: int | None = 0
3131

3232

3333
@dataclass(frozen=True)
3434
class OpossumPackage:
3535
source: SourceInfo
36-
attributionConfidence: Optional[int] = None
37-
comment: Optional[str] = None
38-
packageName: Optional[str] = None
39-
packageVersion: Optional[str] = None
40-
packageNamespace: Optional[str] = None
41-
packageType: Optional[str] = None
42-
packagePURLAppendix: Optional[str] = None
43-
copyright: Optional[str] = None
44-
licenseName: Optional[str] = None
45-
licenseText: Optional[str] = None
46-
url: Optional[str] = None
47-
firstParty: Optional[bool] = None
48-
excludeFromNotice: Optional[bool] = None
49-
preSelected: Optional[bool] = None
50-
followUp: Optional[Literal["FOLLOW_UP"]] = None
51-
originId: Optional[str] = None
52-
criticality: Optional[Union[Literal["high"], Literal["medium"]]] = None
36+
attributionConfidence: int | None = None
37+
comment: str | None = None
38+
packageName: str | None = None
39+
packageVersion: str | None = None
40+
packageNamespace: str | None = None
41+
packageType: str | None = None
42+
packagePURLAppendix: str | None = None
43+
copyright: str | None = None
44+
licenseName: str | None = None
45+
licenseText: str | None = None
46+
url: str | None = None
47+
firstParty: bool | None = None
48+
excludeFromNotice: bool | None = None
49+
preSelected: bool | None = None
50+
followUp: Literal["FOLLOW_UP"] | None = None
51+
originId: str | None = None
52+
criticality: Literal["high"] | Literal["medium"] | None = None
5353

5454

5555
@dataclass(frozen=True)
5656
class Metadata:
5757
projectId: str
5858
fileCreationDate: str
5959
projectTitle: str
60-
projectVersion: Optional[str] = None
61-
expectedReleaseDate: Optional[str] = None
62-
buildDate: Optional[str] = None
60+
projectVersion: str | None = None
61+
expectedReleaseDate: str | None = None
62+
buildDate: str | None = None
6363

6464

6565
class ResourceType(Enum):
@@ -72,10 +72,10 @@ class ResourceType(Enum):
7272
@dataclass(frozen=True)
7373
class Resource:
7474
type: ResourceType
75-
children: Dict[str, Resource] = field(default_factory=dict)
75+
children: dict[str, Resource] = field(default_factory=dict)
7676

7777
def add_path(
78-
self, path_with_resource_types: List[Tuple[str, ResourceType]]
78+
self, path_with_resource_types: list[tuple[str, ResourceType]]
7979
) -> Resource:
8080
resource = deepcopy(self)
8181
if len(path_with_resource_types) == 0:
@@ -103,7 +103,7 @@ def element_exists_but_resource_type_differs(
103103
return False
104104

105105
def drop_element(
106-
self, path_to_element_to_drop: List[Tuple[str, ResourceType]]
106+
self, path_to_element_to_drop: list[tuple[str, ResourceType]]
107107
) -> Resource:
108108
paths_in_resource = self.get_paths_of_all_leaf_nodes_with_types()
109109
if path_to_element_to_drop not in paths_in_resource:
@@ -121,7 +121,7 @@ def drop_element(
121121

122122
return resource
123123

124-
def to_dict(self) -> Union[int, Dict]:
124+
def to_dict(self) -> int | dict:
125125
if not self.has_children():
126126
if self.type == ResourceType.FOLDER:
127127
return {}
@@ -134,7 +134,7 @@ def to_dict(self) -> Union[int, Dict]:
134134

135135
def get_paths_of_all_leaf_nodes_with_types(
136136
self,
137-
) -> List[List[Tuple[str, ResourceType]]]:
137+
) -> list[list[tuple[str, ResourceType]]]:
138138
paths = []
139139
for name, resource in self.children.items():
140140
path = [(name, resource.type)]

‎src/opossum_lib/tree_generation.py

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2023 TNG Technology Consulting GmbH <https://www.tngtech.com>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import Dict, Optional, Tuple, Union
54

65
from networkx import DiGraph, edge_bfs, is_weakly_connected
76
from spdx_tools.spdx.constants import DOCUMENT_SPDX_ID
@@ -21,17 +20,14 @@ def generate_tree_from_graph(graph: DiGraph) -> DiGraph:
2120

2221
def _generate_tree_from_graph_recursively(
2322
graph: DiGraph,
24-
source: Optional[str] = DOCUMENT_SPDX_ID,
25-
created_tree: Optional[DiGraph] = None,
23+
source: str | None = DOCUMENT_SPDX_ID,
24+
created_tree: DiGraph | None = None,
2625
) -> DiGraph:
2726
if not graph.edges():
2827
return graph.copy()
2928

3029
if is_weakly_connected(graph):
31-
if created_tree:
32-
created_tree = created_tree.copy()
33-
else:
34-
created_tree = DiGraph()
30+
created_tree = created_tree.copy() if created_tree else DiGraph()
3531
edges_bfs = edge_bfs(graph, source)
3632

3733
visited_edges = []
@@ -53,10 +49,7 @@ def _generate_tree_from_graph_recursively(
5349
created_tree.add_edges_from(tree_component.edges(data=True))
5450

5551
else: # get connected components
56-
if created_tree:
57-
created_tree = created_tree.copy()
58-
else:
59-
created_tree = DiGraph()
52+
created_tree = created_tree.copy() if created_tree else DiGraph()
6053
for connected_subgraph in _weakly_connected_component_sub_graphs(graph):
6154
# if the documents node is not in the subgraph we choose
6255
# any elements node without incoming edge
@@ -71,14 +64,14 @@ def _generate_tree_from_graph_recursively(
7164

7265

7366
def _add_edge_and_associated_nodes_to_tree(
74-
edge: Tuple[str, str], created_tree: DiGraph, graph: DiGraph
67+
edge: tuple[str, str], created_tree: DiGraph, graph: DiGraph
7568
) -> None:
7669
_add_source_node(edge, graph, created_tree)
7770
_add_target_node_and_edge(edge, graph, created_tree)
7871

7972

8073
def _add_target_node_and_edge(
81-
edge: Tuple[str, str], graph: DiGraph, tree: DiGraph
74+
edge: tuple[str, str], graph: DiGraph, tree: DiGraph
8275
) -> None:
8376
if edge[1] not in tree:
8477
target_node_data = graph.nodes[edge[1]]
@@ -93,9 +86,9 @@ def _add_target_node_and_edge(
9386
tree.add_edge(edge[0], duplicated_node)
9487

9588

96-
def _add_source_node(edge: Tuple[str, str], graph: DiGraph, tree: DiGraph) -> None:
89+
def _add_source_node(edge: tuple[str, str], graph: DiGraph, tree: DiGraph) -> None:
9790
if edge[0] not in tree:
98-
source_node_data: Dict[str, Union[CreationInfo, Package, File]] = graph.nodes[
91+
source_node_data: dict[str, CreationInfo | Package | File] = graph.nodes[
9992
edge[0]
10093
]
10194
tree.add_node(edge[0], **source_node_data)

‎tests/test_cli.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# SPDX-License-Identifier: Apache-2.0
44
import json
55
from pathlib import Path
6-
from typing import Tuple
76
from zipfile import ZipFile
87

98
import pytest
@@ -16,7 +15,7 @@
1615

1716

1817
@pytest.mark.parametrize("options", [("--infile", "--outfile"), ("-i", "-o")])
19-
def test_cli_with_system_exit_code_0(tmp_path: Path, options: Tuple[str, str]) -> None:
18+
def test_cli_with_system_exit_code_0(tmp_path: Path, options: tuple[str, str]) -> None:
2019
runner = CliRunner()
2120

2221
result = runner.invoke(
@@ -35,9 +34,11 @@ def test_cli_with_system_exit_code_0(tmp_path: Path, options: Tuple[str, str]) -
3534

3635
assert result.exit_code == 0
3736

38-
with ZipFile(str(tmp_path / "output.opossum"), "r") as z:
39-
with z.open("input.json") as file:
40-
opossum_dict = json.load(file)
37+
with (
38+
ZipFile(str(tmp_path / "output.opossum"), "r") as z,
39+
z.open("input.json") as file,
40+
):
41+
opossum_dict = json.load(file)
4142
assert "metadata" in opossum_dict
4243
# we are using randomly generated UUIDs for the project-id, therefore
4344
# we need to exclude the "metadata" section from the comparison

‎tests/test_graph_generation.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44
from pathlib import Path
5-
from typing import List
65

76
import pytest
87
from networkx import get_node_attributes
@@ -30,7 +29,7 @@ def test_generate_graph_from_spdx(
3029
file_name: str,
3130
nodes_count: int,
3231
edges_count: int,
33-
relationship_node_keys: List[str],
32+
relationship_node_keys: list[str],
3433
) -> None:
3534
document = parse_file(str(Path(__file__).resolve().parent / "data" / file_name))
3635
validation_messages = validate_full_spdx_document(document)

‎tests/test_merge.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2023 TNG Technology Consulting GmbH <https://www.tngtech.com>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import Dict, List
54
from unittest import mock
65

76
import pytest
@@ -173,9 +172,9 @@ def test_merge_resources() -> None:
173172
],
174173
)
175174
def test_merge_resources_to_attributions(
176-
resources_to_attributions: List[Dict[ResourcePath, List[OpossumPackageIdentifier]]],
177-
expected_resources_to_attributions: Dict[
178-
ResourcePath, List[OpossumPackageIdentifier]
175+
resources_to_attributions: list[dict[ResourcePath, list[OpossumPackageIdentifier]]],
176+
expected_resources_to_attributions: dict[
177+
ResourcePath, list[OpossumPackageIdentifier]
179178
],
180179
) -> None:
181180
merged_resources_to_attributions = _merge_resources_to_attributions(

‎uv.lock

+27-89
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.