File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change 49
49
find_user_pyproject_toml ,
50
50
gen_python_files ,
51
51
get_gitignore ,
52
+ get_root_relative_path ,
52
53
normalize_path_maybe_ignore ,
53
54
parse_pyproject_toml ,
54
55
path_is_excluded ,
@@ -700,7 +701,10 @@ def get_sources(
700
701
701
702
# Compare the logic here to the logic in `gen_python_files`.
702
703
if is_stdin or path .is_file ():
703
- root_relative_path = path .absolute ().relative_to (root ).as_posix ()
704
+ root_relative_path = get_root_relative_path (path , root , report )
705
+
706
+ if root_relative_path is None :
707
+ continue
704
708
705
709
root_relative_path = "/" + root_relative_path
706
710
Original file line number Diff line number Diff line change @@ -259,14 +259,7 @@ def normalize_path_maybe_ignore(
259
259
try :
260
260
abspath = path if path .is_absolute () else Path .cwd () / path
261
261
normalized_path = abspath .resolve ()
262
- try :
263
- root_relative_path = normalized_path .relative_to (root ).as_posix ()
264
- except ValueError :
265
- if report :
266
- report .path_ignored (
267
- path , f"is a symbolic link that points outside { root } "
268
- )
269
- return None
262
+ root_relative_path = get_root_relative_path (normalized_path , root , report )
270
263
271
264
except OSError as e :
272
265
if report :
@@ -276,6 +269,21 @@ def normalize_path_maybe_ignore(
276
269
return root_relative_path
277
270
278
271
272
+ def get_root_relative_path (
273
+ path : Path ,
274
+ root : Path ,
275
+ report : Optional [Report ] = None ,
276
+ ) -> Optional [str ]:
277
+ """Returns the file path relative to the 'root' directory"""
278
+ try :
279
+ root_relative_path = path .absolute ().relative_to (root ).as_posix ()
280
+ except ValueError :
281
+ if report :
282
+ report .path_ignored (path , f"is a symbolic link that points outside { root } " )
283
+ return None
284
+ return root_relative_path
285
+
286
+
279
287
def _path_is_ignored (
280
288
root_relative_path : str ,
281
289
root : Path ,
You can’t perform that action at this time.
0 commit comments