Skip to content

Commit

Permalink
fix: use PurePaths instead to make it work on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
abraemer committed Jan 21, 2025
1 parent 057727c commit 60b1e47
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/opossum_lib/opossum_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from collections.abc import Iterable
from dataclasses import field
from enum import Enum, auto
from pathlib import Path
from typing import Literal

from pydantic import BaseModel, ConfigDict
Expand Down Expand Up @@ -123,7 +122,7 @@ def get_attribution_key(

class Resource(BaseModel):
model_config = ConfigDict(extra="forbid")
path: Path
path: PurePosixPath
type: ResourceType | None = None
attributions: list[OpossumPackage] = []
children: dict[str, Resource] = {}
Expand Down
6 changes: 2 additions & 4 deletions src/opossum_lib/scancode/resource_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@

from __future__ import annotations

from pathlib import Path

import opossum_lib.opossum_model as opossum_model
from opossum_lib.scancode.constants import SCANCODE_SOURCE_NAME
from opossum_lib.scancode.model import File, FileType, ScanCodeData


def scancode_to_file_tree(scancode_data: ScanCodeData) -> opossum_model.Resource:
temp_root = opossum_model.Resource(path=Path(""))
temp_root = opossum_model.Resource(path=PurePosixPath(""))
for file in scancode_data.files:
resource = opossum_model.Resource(
path=Path(file.path),
path=PurePosixPath(file.path.replace("\\", "/")),
attributions=get_attribution_info(file),
type=convert_resource_type(file.type),
)
Expand Down
7 changes: 3 additions & 4 deletions tests/test_scancode/model_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: Apache-2.0

from pathlib import Path

from opossum_lib.scancode.model import (
Copyright,
Expand Down Expand Up @@ -83,11 +82,11 @@ def _create_file(
if copyrights is None:
copyrights = []
if name is None:
name = Path(path).name
name = PurePosixPath(path).name
if base_name is None:
base_name = Path(Path(path).name).stem
base_name = PurePosixPath(PurePosixPath(path).name).stem
if extension is None:
extension = Path(path).suffix
extension = PurePosixPath(path).suffix
return File(
authors=authors,
base_name=base_name,
Expand Down

0 comments on commit 60b1e47

Please sign in to comment.