Commit cd61c5df authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add ability to skip directories in loader

If `Loader.load_from_dir()` raises SkipDirectory the directory is
pruned. This allows skipping based on forward looking (ie. check a
directory for a known file/subdirectory and prune based on it's
presence).

The git loader prunes based on the presence of a `.git` file or
directory anywhere but the project root which would indicate a
submodule.
parent 659f4ca3
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
from os import path, environ
from configparser import ConfigParser, NoOptionError

from .. import loaders, patterns, rules, util
from .. import loaders, patterns, rules, walk, util


GIT_REPO = '.git'
@@ -76,6 +76,10 @@ class GitLoader(loaders.Loader):
			return

		abs_dirpath = path.join(self.project_root, dirpath)

		if dirpath != '' and path.exists(path.join(abs_dirpath, '.git')):
			raise walk.SkipDirectory()

		with util.ignore_if_missing():
			self.load_patterns(dirpath, GITIGNORE_FILE)

+9 −1
Original line number Diff line number Diff line
@@ -24,7 +24,11 @@ def walk_files(start):
		relpath = path.relpath(walkpath, top)
		relpath = '' if relpath == '.' else relpath
		if loader:
			try:
				loader.load_from_dir(relpath)
			except SkipDirectory:
				del dirnames[:]
				continue
		for dirname in list(dirnames):
			dirpath = path.join(relpath, dirname)
			if loader and not rules.run_rules(loader.rules, dirpath, dirname):
@@ -33,3 +37,7 @@ def walk_files(start):
			filepath = path.join(relpath, filename)
			if loader is None or rules.run_rules(loader.rules, filepath):
				yield path.relpath(path.join(top, filepath))



class SkipDirectory(BaseException): pass