diff options
author | mefyl <quentin.hocquet@docker.com> | 2018-02-16 11:03:35 +0100 |
---|---|---|
committer | mefyl <quentin.hocquet@docker.com> | 2018-02-19 13:37:35 +0100 |
commit | 181c1c8eb970ae11a707b6b6c3d1e4d546504ccf (patch) | |
tree | 4da4c8e52c234ac394459dcb96d029a52d30f478 | |
parent | ba0e5332de2fb032b5b21e8e2835244152927c0f (diff) | |
download | docker-py-181c1c8eb970ae11a707b6b6c3d1e4d546504ccf.tar.gz |
Revert "Correctly support absolute paths in .dockerignore"
This reverts commit 34d50483e20e86cb7ab22700e036a5c4d319268a.
Signed-off-by: mefyl <quentin.hocquet@docker.com>
-rw-r--r-- | docker/utils/build.py | 20 | ||||
-rw-r--r-- | tests/unit/utils_test.py | 27 |
2 files changed, 17 insertions, 30 deletions
diff --git a/docker/utils/build.py b/docker/utils/build.py index a218873..d4223e7 100644 --- a/docker/utils/build.py +++ b/docker/utils/build.py @@ -46,7 +46,7 @@ def exclude_paths(root, patterns, dockerfile=None): ) -def should_include(path, exclude_patterns, include_patterns, root): +def should_include(path, exclude_patterns, include_patterns): """ Given a path, a list of exclude patterns, and a list of inclusion patterns: @@ -61,15 +61,11 @@ def should_include(path, exclude_patterns, include_patterns, root): for pattern in include_patterns: if match_path(path, pattern): return True - if os.path.isabs(pattern) and match_path( - os.path.join(root, path), pattern): - return True return False return True -def should_check_directory(directory_path, exclude_patterns, include_patterns, - root): +def should_check_directory(directory_path, exclude_patterns, include_patterns): """ Given a directory path, a list of exclude patterns, and a list of inclusion patterns: @@ -95,7 +91,7 @@ def should_check_directory(directory_path, exclude_patterns, include_patterns, if (pattern + '/').startswith(path_with_slash) ] directory_included = should_include( - directory_path, exclude_patterns, include_patterns, root + directory_path, exclude_patterns, include_patterns ) return directory_included or len(possible_child_patterns) > 0 @@ -114,28 +110,26 @@ def get_paths(root, exclude_patterns, include_patterns, has_exceptions=False): # traversal. See https://docs.python.org/2/library/os.html#os.walk dirs[:] = [ d for d in dirs if should_check_directory( - os.path.join(parent, d), exclude_patterns, include_patterns, - root + os.path.join(parent, d), exclude_patterns, include_patterns ) ] for path in dirs: if should_include(os.path.join(parent, path), - exclude_patterns, include_patterns, root): + exclude_patterns, include_patterns): paths.append(os.path.join(parent, path)) for path in files: if should_include(os.path.join(parent, path), - exclude_patterns, include_patterns, root): + exclude_patterns, include_patterns): paths.append(os.path.join(parent, path)) return paths def match_path(path, pattern): - pattern = pattern.rstrip('/' + os.path.sep) - if pattern and not os.path.isabs(pattern): + if pattern: pattern = os.path.relpath(pattern) pattern_components = pattern.split(os.path.sep) diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index e144b7b..eedcf71 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -876,13 +876,6 @@ class ExcludePathsTest(unittest.TestCase): ) ) - def test_exclude_include_absolute_path(self): - base = make_tree([], ['a.py', 'b.py']) - assert exclude_paths( - base, - ['/*', '!' + os.path.join(base, '*.py')] - ) == set(['a.py', 'b.py']) - class TarTest(unittest.TestCase): def test_tar_with_excludes(self): @@ -1033,52 +1026,52 @@ class ShouldCheckDirectoryTest(unittest.TestCase): def test_should_check_directory_not_excluded(self): assert should_check_directory( - 'not_excluded', self.exclude_patterns, self.include_patterns, '.' + 'not_excluded', self.exclude_patterns, self.include_patterns ) assert should_check_directory( convert_path('dir/with'), self.exclude_patterns, - self.include_patterns, '.' + self.include_patterns ) def test_shoud_check_parent_directories_of_excluded(self): assert should_check_directory( - 'dir', self.exclude_patterns, self.include_patterns, '.' + 'dir', self.exclude_patterns, self.include_patterns ) assert should_check_directory( convert_path('dir/with'), self.exclude_patterns, - self.include_patterns, '.' + self.include_patterns ) def test_should_not_check_excluded_directories_with_no_exceptions(self): assert not should_check_directory( 'exclude_rather_large_directory', self.exclude_patterns, - self.include_patterns, '.' + self.include_patterns ) assert not should_check_directory( convert_path('dir/with/subdir_excluded'), self.exclude_patterns, - self.include_patterns, '.' + self.include_patterns ) def test_should_check_excluded_directory_with_exceptions(self): assert should_check_directory( convert_path('dir/with/exceptions'), self.exclude_patterns, - self.include_patterns, '.' + self.include_patterns ) assert should_check_directory( convert_path('dir/with/exceptions/in'), self.exclude_patterns, - self.include_patterns, '.' + self.include_patterns ) def test_should_not_check_siblings_of_exceptions(self): assert not should_check_directory( convert_path('dir/with/exceptions/but_not_here'), - self.exclude_patterns, self.include_patterns, '.' + self.exclude_patterns, self.include_patterns ) def test_should_check_subdirectories_of_exceptions(self): assert should_check_directory( convert_path('dir/with/exceptions/like_this_one/subdir'), - self.exclude_patterns, self.include_patterns, '.' + self.exclude_patterns, self.include_patterns ) |