diff options
author | Ashley Whetter <ashley@awhetter.co.uk> | 2017-09-09 20:23:56 +0100 |
---|---|---|
committer | Ashley Whetter <ashley@awhetter.co.uk> | 2019-02-09 13:23:21 -0800 |
commit | db37ffa33f13d678c5b6c8a1b7172b493a3947c7 (patch) | |
tree | 420c39c401b6a57c407b4e6c6571755b5c116e72 | |
parent | f77265c6ce454e725477b67fcf818a0842046114 (diff) | |
download | pylint-git-db37ffa33f13d678c5b6c8a1b7172b493a3947c7.tar.gz |
Moved walk_up to utils
-rw-r--r-- | pylint/config.py | 25 | ||||
-rw-r--r-- | pylint/utils.py | 22 |
2 files changed, 24 insertions, 23 deletions
diff --git a/pylint/config.py b/pylint/config.py index 077bbf9c9..3826704ae 100644 --- a/pylint/config.py +++ b/pylint/config.py @@ -98,27 +98,6 @@ def save_results(results, base): print("Unable to create file %s: %s" % (data_file, ex), file=sys.stderr) -# TODO: Put into utils -def walk_up(from_dir): - """Walk up a directory tree - :param from_dir: The directory to walk up from. - This directory is included in the output. - :type from_dir: str - :returns: Each parent directory - :rtype: generator(str) - """ - cur_dir = None - new_dir = os.path.expanduser(from_dir) - new_dir = os.path.abspath(new_dir) - - # The parent of the root directory is the root directory. - # Once we have reached it, we are done. - while cur_dir != new_dir: - cur_dir = new_dir - yield cur_dir - new_dir = os.path.abspath(os.path.join(cur_dir, os.pardir)) - - def find_pylintrc_in(search_dir): """Find a pylintrc file in the given directory. :param search_dir: The directory to search. @@ -150,7 +129,7 @@ def find_nearby_pylintrc(search_dir=""): path = find_pylintrc_in(search_dir) if not path: - for search_dir in walk_up(search_dir): + for search_dir in utils.walk_up(search_dir): if not os.path.isfile(os.path.join(search_dir, "__init__.py")): break path = find_pylintrc_in(search_dir) @@ -814,7 +793,7 @@ class ConfigurationStore(object): :returns: The config objects for all parent directories. :rtype: generator(Configuration) """ - for cfg_dir in walk_up(path): + for cfg_dir in utils.walk_up(path): if cfg_dir in self._cache: yield self._cache[cfg_dir] break diff --git a/pylint/utils.py b/pylint/utils.py index 9d6283577..3f71cba67 100644 --- a/pylint/utils.py +++ b/pylint/utils.py @@ -1540,3 +1540,25 @@ def _rest_format_section(stream, section, options, doc=None): value = str(_format_option_value(optdict, value)) print(file=stream) print(" Default: ``%s``" % value.replace("`` ", "```` ``"), file=stream) + + +def walk_up(from_dir): + """Walk up a directory tree + + :param from_dir: The directory to walk up from. + This directory is included in the output. + :type from_dir: str + + :returns: Each parent directory + :rtype: generator(str) + """ + cur_dir = None + new_dir = os.path.expanduser(from_dir) + new_dir = os.path.abspath(new_dir) + + # The parent of the root directory is the root directory. + # Once we have reached it, we are done. + while cur_dir != new_dir: + cur_dir = new_dir + yield cur_dir + new_dir = os.path.abspath(os.path.join(cur_dir, os.pardir)) |