Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
  • Loading branch information
stuartleeks and scorphus committed Apr 17, 2021
1 parent 98c96a8 commit de02df1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tests/test_conf.py
Expand Up @@ -55,7 +55,7 @@ def test_from_env(self, os_environ, settings):
'THEFUCK_WAIT_SLOW_COMMAND': '999',
'THEFUCK_SLOW_COMMANDS': 'lein:react-native:./gradlew',
'THEFUCK_NUM_CLOSE_MATCHES': '359',
'THEFUCK_EXCLUDED_SEARCH_PATH_PREFIXES': '/mnt/'})
'THEFUCK_EXCLUDED_SEARCH_PATH_PREFIXES': '/media/:/mnt/'})
settings.init()
assert settings.rules == ['bash', 'lisp']
assert settings.exclude_rules == ['git', 'vim']
Expand All @@ -66,7 +66,7 @@ def test_from_env(self, os_environ, settings):
assert settings.wait_slow_command == 999
assert settings.slow_commands == ['lein', 'react-native', './gradlew']
assert settings.num_close_matches == 359
assert settings.excluded_search_path_prefixes == ['/mnt/']
assert settings.excluded_search_path_prefixes == ['/media/', '/mnt/']

def test_from_env_with_DEFAULT(self, os_environ, settings):
os_environ.update({'THEFUCK_RULES': 'DEFAULT_RULES:bash:lisp'})
Expand Down
5 changes: 3 additions & 2 deletions tests/test_utils.py
Expand Up @@ -103,8 +103,9 @@ def test_get_all_executables_exclude_paths(path, pathsep, excluded, settings):
settings.excluded_search_path_prefixes = [excluded]
with patch('thefuck.utils.Path') as Path_mock:
get_all_executables()
assert call(excluded) not in Path_mock.mock_calls
assert call(path.split(pathsep)[0]) in Path_mock.mock_calls
path_list = path.split(pathsep)
assert call(path_list[-1]) not in Path_mock.mock_calls
assert all(call(p) in Path_mock.mock_calls for p in path_list[:-1])


@pytest.mark.parametrize('args, result', [
Expand Down
8 changes: 3 additions & 5 deletions thefuck/utils.py
Expand Up @@ -105,10 +105,7 @@ def get_close_matches(word, possibilities, n=None, cutoff=0.6):


def include_path_in_search(path):
for exclude_path in settings.excluded_search_path_prefixes:
if path.startswith(exclude_path):
return False
return True
return not any(path.startswith(x) for x in settings.excluded_search_path_prefixes)


@memoize
Expand All @@ -125,7 +122,8 @@ def _safe(fn, fallback):
tf_entry_points = ['thefuck', 'fuck']

bins = [exe.name.decode('utf8') if six.PY2 else exe.name
for path in os.environ.get('PATH', '').split(os.pathsep) if include_path_in_search(path)
for path in os.environ.get('PATH', '').split(os.pathsep)
if include_path_in_search(path)
for exe in _safe(lambda: list(Path(path).iterdir()), [])
if not _safe(exe.is_dir, True)
and exe.name not in tf_entry_points]
Expand Down

0 comments on commit de02df1

Please sign in to comment.