forked from fsfe/reuse-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport Path.is_relative_to to python3.8 and before
- Loading branch information
Showing
2 changed files
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# SPDX-FileCopyrightText: 2023 Matthias Riße | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
"""This module adds compatibility code like backports.""" | ||
import sys | ||
|
||
# Introduce an implementation of pathlib.Path's is_relative_to in python | ||
# versions before 3.9 | ||
if sys.version_info < (3, 9): | ||
from pathlib import Path | ||
|
||
def _is_relative_to(self, path): | ||
try: | ||
self.relative_to(path) | ||
return True | ||
except ValueError: | ||
return False | ||
|
||
Path.is_relative_to = _is_relative_to |