Skip to content

Commit 4fc2779

Browse files
committed
Add docstrings to hatchling.utils.fs
1 parent 1437d87 commit 4fc2779

File tree

1 file changed

+20
-0
lines changed
  • backend/src/hatchling/utils

1 file changed

+20
-0
lines changed

backend/src/hatchling/utils/fs.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55

66
def locate_file(root: str, file_name: str, *, boundary: str | None = None) -> str | None:
7+
"""
8+
Locate a file by searching upward from a root directory until the file is found or a boundary directory is reached.
9+
10+
Args:
11+
root (str): The starting directory for the search.
12+
file_name (str): The name of the file to locate.
13+
boundary (str | None, optional): The name of a directory that, if reached, stops the search. If None, the search continues up to the filesystem root.
14+
15+
Returns:
16+
str | None: The full path to the file if found; otherwise, None.
17+
"""
718
while True:
819
file_path = os.path.join(root, file_name)
920
if os.path.isfile(file_path):
@@ -20,6 +31,15 @@ def locate_file(root: str, file_name: str, *, boundary: str | None = None) -> st
2031

2132

2233
def path_to_uri(path: str) -> str:
34+
"""
35+
Convert a local filesystem path to a file URI, handling spaces and platform-specific path separators.
36+
37+
Args:
38+
path (str): The local filesystem path to convert.
39+
40+
Returns:
41+
str: The file URI corresponding to the given path.
42+
"""
2343
if os.sep == '/':
2444
return f'file://{os.path.abspath(path).replace(" ", "%20")}'
2545

0 commit comments

Comments
 (0)