15
15
from pip ._vendor .six .moves .urllib import parse as urllib_parse
16
16
17
17
from pip ._internal .exceptions import BadCommand
18
+ from pip ._internal .utils .compat import samefile
18
19
from pip ._internal .utils .misc import (
19
20
ask_path_exists ,
20
21
backup_dir ,
@@ -71,6 +72,33 @@ def make_vcs_requirement_url(repo_url, rev, project_name, subdir=None):
71
72
return req
72
73
73
74
75
+ def find_path_to_setup_from_repo_root (location , repo_root ):
76
+ """
77
+ Find the path to `setup.py` by searching up the filesystem from `location`.
78
+ Return the path to `setup.py` relative to `repo_root`.
79
+ Return None if `setup.py` is in `repo_root` or cannot be found.
80
+ """
81
+ # find setup.py
82
+ orig_location = location
83
+ while not os .path .exists (os .path .join (location , 'setup.py' )):
84
+ last_location = location
85
+ location = os .path .dirname (location )
86
+ if location == last_location :
87
+ # We've traversed up to the root of the filesystem without
88
+ # finding setup.py
89
+ logger .warning (
90
+ "Could not find setup.py for directory %s (tried all "
91
+ "parent directories)" ,
92
+ orig_location ,
93
+ )
94
+ return None
95
+
96
+ if samefile (repo_root , location ):
97
+ return None
98
+
99
+ return os .path .relpath (location , repo_root )
100
+
101
+
74
102
class RemoteNotFoundError (Exception ):
75
103
pass
76
104
@@ -240,9 +268,10 @@ def should_add_vcs_url_prefix(cls, remote_url):
240
268
return not remote_url .lower ().startswith ('{}:' .format (cls .name ))
241
269
242
270
@classmethod
243
- def get_subdirectory (cls , repo_dir ):
271
+ def get_subdirectory (cls , location ):
244
272
"""
245
273
Return the path to setup.py, relative to the repo root.
274
+ Return None if setup.py is in the repo root.
246
275
"""
247
276
return None
248
277
@@ -582,7 +611,8 @@ def run_command(
582
611
extra_ok_returncodes = None , # type: Optional[Iterable[int]]
583
612
command_desc = None , # type: Optional[str]
584
613
extra_environ = None , # type: Optional[Mapping[str, Any]]
585
- spinner = None # type: Optional[SpinnerInterface]
614
+ spinner = None , # type: Optional[SpinnerInterface]
615
+ log_failed_cmd = True
586
616
):
587
617
# type: (...) -> Text
588
618
"""
@@ -598,7 +628,8 @@ def run_command(
598
628
command_desc = command_desc ,
599
629
extra_environ = extra_environ ,
600
630
unset_environ = cls .unset_environ ,
601
- spinner = spinner )
631
+ spinner = spinner ,
632
+ log_failed_cmd = log_failed_cmd )
602
633
except OSError as e :
603
634
# errno.ENOENT = no such file or directory
604
635
# In other words, the VCS executable isn't available
0 commit comments