Skip to content

Commit 4026147

Browse files
authored
Replace internal removeprefix function (#25)
1 parent f6aa725 commit 4026147

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

src/chembl_downloader/api.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ class VersionPathPair(NamedTuple):
7878
path: Path
7979

8080

81-
def _removeprefix(s: str, prefix: str) -> str:
82-
if s.startswith(prefix):
83-
return s[len(prefix) :]
84-
return s
85-
86-
8781
LATEST_README_URL = "https://ftp.ebi.ac.uk/pub/databases/chembl/ChEMBLdb/latest/README"
8882

8983

@@ -99,7 +93,10 @@ def latest() -> str:
9993
for line in res.iter_lines(decode_unicode=True):
10094
line = line.decode("utf8")
10195
if line.startswith(RELEASE_PREFIX):
102-
return _removeprefix(_removeprefix(line, RELEASE_PREFIX).strip(), "chembl_")
96+
line = line.removeprefix(RELEASE_PREFIX)
97+
line = line.strip()
98+
line = line.removeprefix("chembl_")
99+
return line
103100
raise ValueError("could not find latest ChEMBL version")
104101

105102

@@ -912,14 +909,15 @@ def download_readme(
912909
)
913910

914911

915-
def get_date(version: str, **kwargs: Any) -> str:
912+
def get_date(version: VersionHint | None = None, **kwargs: Any) -> str:
916913
"""Get the date of a given version."""
917914
path = download_readme(version=version, return_version=False, **kwargs)
918915
try:
919-
date_p = _removeprefix(
920-
next(line for line in path.read_text().splitlines() if line.startswith("* Date:")),
921-
DATE_PREFIX,
922-
).lstrip()
916+
date_p = next(
917+
line for line in path.read_text().splitlines() if line.startswith(DATE_PREFIX)
918+
)
919+
date_p = date_p.removeprefix(DATE_PREFIX)
920+
date_p = date_p.lstrip()
923921
except StopIteration:
924922
return "" # happens on 22.1 and 24.1
925923
else:

tests/test_api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ def test_cursor(self) -> None:
108108
cursor.execute("SELECT COUNT(activity_id) FROM activities")
109109
self.assertEqual(3, cursor.fetchone()[0])
110110

111+
def test_get_date(self) -> None:
112+
"""Test getting the date."""
113+
self.assertEqual("2024-12-01", chembl_downloader.get_date(version="35"))
114+
111115
def test_latest_version(self) -> None:
112116
"""Test getting the latest version."""
113117
latest_version = chembl_downloader.latest()

0 commit comments

Comments
 (0)