Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing self.copy() ignore_case for excludes #8009

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions conans/client/file_copier.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ def _filter_files(src, pattern, links, excludes, ignore_case, excluded_folders):
else:
files_to_copy = [n for n in filenames if fnmatch.fnmatchcase(os.path.normpath(n),
pattern)]

for exclude in excludes:
files_to_copy = [f for f in files_to_copy if not fnmatch.fnmatch(f, exclude)]
if ignore_case:
files_to_copy = [f for f in files_to_copy if not fnmatch.fnmatch(f, exclude)]
else:
files_to_copy = [f for f in files_to_copy if not fnmatch.fnmatchcase(f, exclude)]

if ignore_case:
files_to_copy = [filenames[f] for f in files_to_copy]
Expand Down
2 changes: 1 addition & 1 deletion conans/client/loader_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def options(self):
@property
def _import_parameters(self):
def _parse_args(param_string):
root_package, ignore_case, folder, excludes, keep_path = None, False, False, None, True
root_package, ignore_case, folder, excludes, keep_path = None, True, False, None, True
params = param_string.split(",")
params = [p.strip() for p in params if p.strip()]
for param in params:
Expand Down
28 changes: 15 additions & 13 deletions conans/test/functional/conanfile/imports_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,26 @@ def test_imports_folders_extrachars_txt(self):
def test_conanfile_txt_multi_excludes(self):
# https://github.com/conan-io/conan/issues/2293
client = TestClient()
conanfile = """from conans import ConanFile
class Pkg(ConanFile):
exports_sources = "*"
def package(self):
self.copy("*.dll", dst="bin")
"""
client.save({"conanfile.py": conanfile,
pkg_conanfile = textwrap.dedent("""
from conans import ConanFile
class Pkg(ConanFile):
exports_sources = "*"
def package(self):
self.copy("*.dll", dst="bin")
""")
client.save({"conanfile.py": pkg_conanfile,
"a.dll": "",
"Foo/b.dll": "",
"Baz/b.dll": ""})
client.run("create . Pkg/0.1@user/testing")

conanfile = """[requires]
Pkg/0.1@user/testing
[imports]
bin, *.dll -> @ excludes=Foo/*.dll Baz/*.dll
"""
client.save({"conanfile.txt": conanfile}, clean_first=True)
consumer = textwrap.dedent("""
[requires]
Pkg/0.1@user/testing
[imports]
bin, *.dll -> @ excludes=Foo/*.dll Baz/*.dll
""")
client.save({"conanfile.txt": consumer}, clean_first=True)
client.run("install . --build=missing")
self.assertTrue(os.path.exists(os.path.join(client.current_folder, "a.dll")))
self.assertFalse(os.path.exists(os.path.join(client.current_folder, "Foo/b.dll")))
Expand Down
14 changes: 7 additions & 7 deletions conans/test/unittests/client/conanfile_loader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ def test_load_imports_arguments(self):
OpenCV/bin, * -> ./bin # I need this binaries
OpenCV/lib, * -> ./lib @ root_package=Pkg
OpenCV/data, * -> ./data @ root_package=Pkg, folder=True # Irrelevant
docs, * -> ./docs @ root_package=Pkg, folder=True, ignore_case=True, excludes="a b c" # Other
licenses, * -> ./licenses @ root_package=Pkg, folder=True, ignore_case=True, excludes="a b c", keep_path=False # Other
docs, * -> ./docs @ root_package=Pkg, folder=True, ignore_case=False, excludes="a b c" # Other
licenses, * -> ./licenses @ root_package=Pkg, folder=True, ignore_case=False, excludes="a b c", keep_path=False # Other
'''
tmp_dir = temp_folder()
file_path = os.path.join(tmp_dir, "file.txt")
Expand All @@ -233,11 +233,11 @@ def test_load_imports_arguments(self):

ret.copy = Mock()
ret.imports()
expected = [call(u'*', u'./bin', u'OpenCV/bin', None, False, False, None, True),
call(u'*', u'./lib', u'OpenCV/lib', u'Pkg', False, False, None, True),
call(u'*', u'./data', u'OpenCV/data', u'Pkg', True, False, None, True),
call(u'*', u'./docs', u'docs', u'Pkg', True, True, [u'"a', u'b', u'c"'], True),
call(u'*', u'./licenses', u'licenses', u'Pkg', True, True, [u'"a', u'b', u'c"'],
expected = [call(u'*', u'./bin', u'OpenCV/bin', None, False, True, None, True),
call(u'*', u'./lib', u'OpenCV/lib', u'Pkg', False, True, None, True),
call(u'*', u'./data', u'OpenCV/data', u'Pkg', True, True, None, True),
call(u'*', u'./docs', u'docs', u'Pkg', True, False, [u'"a', u'b', u'c"'], True),
call(u'*', u'./licenses', u'licenses', u'Pkg', True, False, [u'"a', u'b', u'c"'],
False)]
self.assertEqual(ret.copy.call_args_list, expected)

Expand Down
41 changes: 34 additions & 7 deletions conans/test/unittests/client/file_copier/file_copier_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_basic_with_linked_dir(self):
sub1 = os.path.join(folder1, "subdir1")
sub2 = os.path.join(folder1, "subdir2")
os.makedirs(sub1)
os.symlink("subdir1", sub2) # @UndefinedVariable
os.symlink("subdir1", sub2)
save(os.path.join(sub1, "file1.txt"), "Hello1")
save(os.path.join(sub1, "file2.c"), "Hello2")
save(os.path.join(sub1, "sub1/file1.txt"), "Hello1 sub")
Expand All @@ -52,11 +52,13 @@ def test_basic_with_linked_dir(self):
copier = FileCopier([folder1], folder2)
copier("*.txt", "texts", links=links)
if links:
self.assertEqual(os.readlink(os.path.join(folder2, "texts/subdir2")), "subdir1") # @UndefinedVariable
self.assertEqual(os.readlink(os.path.join(folder2, "texts/subdir2")), "subdir1")
self.assertEqual("Hello1", load(os.path.join(folder2, "texts/subdir1/file1.txt")))
self.assertEqual("Hello1 sub", load(os.path.join(folder2, "texts/subdir1/sub1/file1.txt")))
self.assertEqual("Hello1 sub", load(os.path.join(folder2,
"texts/subdir1/sub1/file1.txt")))
self.assertEqual("Hello1", load(os.path.join(folder2, "texts/subdir2/file1.txt")))
self.assertEqual(['file1.txt', 'sub1'].sort(), os.listdir(os.path.join(folder2, "texts/subdir2")).sort())
self.assertEqual(['file1.txt', 'sub1'].sort(),
os.listdir(os.path.join(folder2, "texts/subdir2")).sort())

for links in (False, True):
folder2 = temp_folder()
Expand All @@ -83,7 +85,7 @@ def test_linked_folder_missing_error(self):
self.assertEqual(os.listdir(folder2), [])
copier("*.txt", links=True)
self.assertEqual(sorted(os.listdir(folder2)), sorted(["subdir1", "subdir2"]))
self.assertEqual(os.readlink(os.path.join(folder2, "subdir2")), "subdir1") # @UndefinedVariable
self.assertEqual(os.readlink(os.path.join(folder2, "subdir2")), "subdir1")
self.assertEqual("Hello1", load(os.path.join(folder2, "subdir1/file1.txt")))
self.assertEqual("Hello1", load(os.path.join(folder2, "subdir2/file1.txt")))

Expand Down Expand Up @@ -166,7 +168,7 @@ def test_excludes(self):
folder2 = temp_folder()
copier = FileCopier([folder1], folder2)
copier("*.txt", excludes="*Test*.txt")
self.assertEqual(set(['MyLib.txt', 'MyLibImpl.txt']), set(os.listdir(folder2)))
self.assertEqual({'MyLib.txt', 'MyLibImpl.txt'}, set(os.listdir(folder2)))

folder2 = temp_folder()
copier = FileCopier([folder1], folder2)
Expand Down Expand Up @@ -195,7 +197,6 @@ def test_avoid_repeat_copies(self, copy2_mock):
dst_folder = temp_folder()
copier = FileCopier(src_folders, dst_folder)


for src_folder in src_folders:
copier("*", src=os.path.join(src_folder, "sub"))

Expand All @@ -219,3 +220,29 @@ def test_ignore_case(self):
copier = FileCopier([src_folder], dst_folder)
copier("foobar.txt", ignore_case=True)
self.assertEqual(["FooBar.txt"], os.listdir(dst_folder))

def test_ignore_case_excludes(self):
src_folder = temp_folder()
save(os.path.join(src_folder, "file.h"), "")
save(os.path.join(src_folder, "AttributeStorage.h"), "")
save(os.path.join(src_folder, "sub/file.h"), "")
save(os.path.join(src_folder, "sub/AttributeStorage.h"), "")

dst_folder = temp_folder()
copier = FileCopier([src_folder], dst_folder)
# Exclude pattern will match AttributeStorage
copier("*.h", excludes="*Test*", dst="include")
self.assertEqual(["include"], os.listdir(dst_folder))
self.assertEqual(sorted(["file.h", "sub"]),
sorted(os.listdir(os.path.join(dst_folder, "include"))))
self.assertEqual(["file.h"], os.listdir(os.path.join(dst_folder, "include", "sub")))

dst_folder = temp_folder()
copier = FileCopier([src_folder], dst_folder)
# Exclude pattern will not match AttributeStorage if ignore_case=False
copier("*.h", excludes="*Test*", dst="include", ignore_case=False)
self.assertEqual(["include"], os.listdir(dst_folder))
self.assertEqual(sorted(["AttributeStorage.h", "file.h", "sub"]),
sorted(os.listdir(os.path.join(dst_folder, "include"))))
self.assertEqual(sorted(["AttributeStorage.h", "file.h"]),
sorted(os.listdir(os.path.join(dst_folder, "include", "sub"))))