Skip to content

Commit

Permalink
Restore Python 3.8 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed May 20, 2024
1 parent c53584b commit aa00e28
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Empty file added pytest_perf/compat/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions pytest_perf/compat/py38.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys


if sys.version_info < (3, 9):

def removesuffix(self, suffix):
# suffix='' should not call self[:-0].
if suffix and self.endswith(suffix):
return self[: -len(suffix)]
else:
return self[:]

def removeprefix(self, prefix):
if self.startswith(prefix):
return self[len(prefix) :]
else:
return self[:]
else:

def removesuffix(self, suffix):
return self.removesuffix(suffix)

def removeprefix(self, prefix):
return self.removeprefix(prefix)
4 changes: 3 additions & 1 deletion pytest_perf/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import contextlib
import tempfile

from .compat.py38 import removesuffix

import pip_run
import tempora

Expand Down Expand Up @@ -119,7 +121,7 @@ def upstream_url(extras='', control=None):
origin = subprocess.check_output(_git_origin, encoding='utf-8', text=True).strip()
origin_url = _ensure_url(origin)
base, sep, name = origin.rpartition('/')
clean_name = name.removesuffix('.git')
clean_name = removesuffix(name, '.git')
rev = f'@{control}' if control else ''
return f'{clean_name}{extras}@git+{origin_url}{rev}'

Expand Down

0 comments on commit aa00e28

Please sign in to comment.