summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2023-04-02 22:31:38 +0200
committerRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2023-04-02 22:31:38 +0200
commitaa76572cb34cc5169002bd942ec25bbd7a57876a (patch)
tree7e8cb8db1afe16a942af75f23864413e278c2337
parentd4f6b7d8a25d5466d38e6e321689cfba8a3cb8dc (diff)
downloadsetuptools-scm-aa76572cb34cc5169002bd942ec25bbd7a57876a.tar.gz
chore: migrate walk_potental_roots to pathlib.Path
-rw-r--r--src/setuptools_scm/discover.py19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/setuptools_scm/discover.py b/src/setuptools_scm/discover.py
index 47e08e7..d0655bb 100644
--- a/src/setuptools_scm/discover.py
+++ b/src/setuptools_scm/discover.py
@@ -1,6 +1,7 @@
from __future__ import annotations
import os
+from pathlib import Path
from typing import Iterable
from typing import Iterator
@@ -11,24 +12,16 @@ from ._config import Configuration
log = _log.log.getChild("discover")
-def walk_potential_roots(
- root: _t.PathT, search_parents: bool = True
-) -> Iterator[_t.PathT]:
+def walk_potential_roots(root: _t.PathT, search_parents: bool = True) -> Iterator[Path]:
"""
Iterate though a path and each of its parents.
:param root: File path.
:param search_parents: If ``False`` the parents are not considered.
"""
-
- if not search_parents:
- yield root
- return
-
- tail = root
-
- while tail:
- yield root
- root, tail = os.path.split(root)
+ root = Path(root)
+ yield root
+ if search_parents:
+ yield from root.parents
def match_entrypoint(root: _t.PathT, name: str) -> bool: