Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: python
python:
- "2.7"
- "3.6"
- "3.7-dev"
- "3.7"
install: make install-ci
script: make test-ci
after_success:
Expand Down
26 changes: 5 additions & 21 deletions rootpath/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# CONSTANTS
# --------------------------------------

DEFAULT_PATH = '.'
DEFAULT_ROOT_FILENAME_MATCH_PATTERN = '.git|requirements.txt'


Expand Down Expand Up @@ -50,39 +49,24 @@ def find_root_path(current_path, pattern = None):
if isinstance(pattern, six.string_types):
pattern = re.compile(pattern)

detecting = True

found_more_files = None
found_root = None
found_system_root = None

file_names = None
root_file_names = None

while (detecting):
while True:
file_names = listdir(current_path)
found_more_files = bool(len(file_names) > 0)

if not found_more_files:
detecting = False

if not file_names:
return None

root_file_names = filter(pattern.match, file_names)
root_file_names = list(root_file_names)

found_root = bool(len(root_file_names) > 0)

if found_root:
detecting = False
filtered_file_names_gen = filter(pattern.match, file_names)

if list(filtered_file_names_gen):
return current_path

found_system_root = bool(current_path == path.sep)

if found_system_root:
return None

current_path = path.abspath(path.join(current_path, '..'))
current_path = path.dirname(current_path)

return find_root_path(current_path, pattern)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

[tox]
envlist = py27, py36
envlist = py27, py36, py37
skip_missing_interpreters = true

[testenv]
Expand Down