Coverage for ezdag/path.py: 100.0%
11 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-29 15:59 -0700
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-29 15:59 -0700
1# Copyright (C) 2023 Patrick Godwin, Cardiff University
2#
3# This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
4# If a copy of the MPL was not distributed with this file, You can obtain one at
5# <https://mozilla.org/MPL/2.0/>.
6#
7# SPDX-License-Identifier: MPL-2.0
9from __future__ import annotations
11import os
12from typing import Callable
15def is_abs_or_url(path: str) -> bool:
16 """Check whether a path is absolute or URL-based."""
17 if os.path.isabs(path):
18 return True
19 return "://" in str(path)
22def normalize(path: str, *, basename: bool | Callable[[str], bool] = False) -> str:
23 """Selectively return the path's basename based on a condition."""
24 if (callable(basename) and basename(path)) or basename is True:
25 return os.path.basename(path)
26 return path