File tree Expand file tree Collapse file tree
cyclonedx/contrib/dependency Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # This file is part of CycloneDX Python Library
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+ #
15+ # SPDX-License-Identifier: Apache-2.0
16+ # Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+ """Dependency related functionality"""
Original file line number Diff line number Diff line change 1+ # This file is part of CycloneDX Python Library
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+ #
15+ # SPDX-License-Identifier: Apache-2.0
16+ # Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+ from typing import Iterable
19+
20+ from ...model .dependency import Dependency
21+
22+ def flatten (dep : Dependency ) -> Iterable [Dependency ]:
23+ if len (dep .dependencies ) == 0 :
24+ return (dep , )
25+ flat : list [Dependency ] = [Dependency (dep .ref , (Dependency (d .ref ) for d in dep .dependencies ))]
26+ todos : list [Dependency ] = list (dep .dependencies )
27+ while todos :
28+ todo = todos .pop ()
29+ if todo .dependencies :
30+ flat .append (Dependency (dep .ref , (Dependency (d .ref ) for d in todo .dependencies )))
31+ todos .extend (todo .dependencies )
32+ return flat
33+
You can’t perform that action at this time.
0 commit comments