Skip to content

Commit

Permalink
Backport Path.is_relative_to to python3.8 and before
Browse files Browse the repository at this point in the history
  • Loading branch information
matrss committed Feb 23, 2023
1 parent 5436d9c commit 8b573e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/reuse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from boolean.boolean import Expression
from pkg_resources import DistributionNotFound, get_distribution

import reuse.compat

try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:
Expand Down
20 changes: 20 additions & 0 deletions src/reuse/compat.py
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

0 comments on commit 8b573e6

Please sign in to comment.