Skip to content

Commit

Permalink
Use PurePath.as_posix() when converting paths to string
Browse files Browse the repository at this point in the history
Otherwise on Windows, thse get backwards slashes.

Signed-off-by: Carmen Bianca BAKKER <[email protected]>
  • Loading branch information
carmenbianca committed Jun 27, 2023
1 parent 2c215c4 commit bfd0013
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/reuse/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from hashlib import sha1
from itertools import chain
from os import PathLike
from pathlib import Path
from pathlib import Path, PurePath
from typing import IO, Any, BinaryIO, Dict, Iterator, List, Optional, Set, Union

from boolean.boolean import Expression, ParseError
Expand Down Expand Up @@ -225,7 +225,8 @@ def _determine_license_suffix_path(path: StrPath) -> Path:

def _copyright_from_dep5(path: StrPath, dep5_copyright: Copyright) -> ReuseInfo:
"""Find the reuse information of *path* in the dep5 Copyright object."""
result = dep5_copyright.find_files_paragraph(Path(path).as_posix())
path = PurePath(path).as_posix()
result = dep5_copyright.find_files_paragraph(path)

if result is None:
return ReuseInfo()
Expand All @@ -237,7 +238,7 @@ def _copyright_from_dep5(path: StrPath, dep5_copyright: Copyright) -> ReuseInfo:
copyright_lines=set(
map(str.strip, result.copyright.splitlines()) # type: ignore
),
path=str(path),
path=path,
source_type=SourceType.DEP5,
source_path=".reuse/dep5",
)
Expand Down
4 changes: 2 additions & 2 deletions src/reuse/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ def reuse_info_of(self, path: StrPath) -> List[ReuseInfo]:
else:
source_type = SourceType.FILE_HEADER
file_result = file_result.copy(
path=str(self.relative_from_root(original_path)),
source_path=str(self.relative_from_root(path)),
path=self.relative_from_root(original_path).as_posix(),
source_path=self.relative_from_root(path).as_posix(),
source_type=source_type,
)

Expand Down
4 changes: 2 additions & 2 deletions src/reuse/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from hashlib import md5
from io import StringIO
from os import cpu_count
from pathlib import Path
from pathlib import Path, PurePath
from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Set, cast
from uuid import uuid4

Expand Down Expand Up @@ -406,7 +406,7 @@ def to_dict_lint(self) -> Dict[str, Any]:
return {
# This gets rid of the './' prefix. In Python 3.9, use
# str.removeprefix.
"path": str(Path(self.name)),
"path": PurePath(self.name).as_posix(),
"copyrights": [
{
"value": line,
Expand Down

0 comments on commit bfd0013

Please sign in to comment.