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

support globs in prefix file functions #1554

Merged
merged 3 commits into from
Nov 28, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions conda_build/metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import, division, print_function

import glob
import logging
import os
import re
Expand Down Expand Up @@ -175,6 +176,14 @@ def parse(data, config, path=None):
return sanitize(res)


def expand_globs(path_list, root_dir):
files = []
for path in path_list:
files.extend(glob.glob(os.path.join(root_dir, path)))
# list comp is getting rid of absolute prefix, to match relative paths used in file list
return [f.replace(root_dir + os.path.sep, '') for f in files]


trues = {'y', 'on', 'true', 'yes'}
falses = {'n', 'no', 'false', 'off'}

Expand Down Expand Up @@ -685,17 +694,18 @@ def has_prefix_files(self):
if any('\\' in i for i in ret):
raise RuntimeError("build/has_prefix_files paths must use / "
"as the path delimiter on Windows")
return ret
return expand_globs(ret, self.config.build_prefix)

def ignore_prefix_files(self):
ret = self.get_value('build/ignore_prefix_files', False)
if type(ret) not in (list, bool):
raise RuntimeError('build/ignore_prefix_files should be boolean or a list of paths')
raise RuntimeError('build/ignore_prefix_files should be boolean or a list of paths '
'(optionally globs)')
if sys.platform == 'win32':
if type(ret) is list and any('\\' in i for i in ret):
raise RuntimeError("build/ignore_prefix_files paths must use / "
"as the path delimiter on Windows")
return ret
return expand_globs(ret, self.config.build_prefix) if type(ret) is list else ret

def always_include_files(self):
files = ensure_list(self.get_value('build/always_include_files', []))
Expand All @@ -704,7 +714,8 @@ def always_include_files(self):
"as the path delimiter on Windows")
if on_win:
files = [f.replace("/", "\\") for f in files]
return files

return expand_globs(files, self.config.build_prefix)

def include_recipe(self):
return self.get_value('build/include_recipe', True)
Expand All @@ -717,7 +728,7 @@ def binary_has_prefix_files(self):
if any('\\' in i for i in ret):
raise RuntimeError("build/binary_has_prefix_files paths must use / "
"as the path delimiter on Windows")
return ret
return expand_globs(ret, self.config.build_prefix)

def skip(self):
return self.get_value('build/skip', False)
Expand Down
11 changes: 10 additions & 1 deletion tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from conda_build.conda_interface import MatchSpec

from conda_build.metadata import select_lines, handle_config_version
from conda_build.metadata import select_lines, handle_config_version, expand_globs
from .utils import testing_workdir, test_config, test_metadata


Expand Down Expand Up @@ -107,3 +107,12 @@ def test_numpy(self):
self.assertRaises(RuntimeError,
handle_config_version,
MatchSpec('numpy x.x'), None)


def test_expand_globs(testing_workdir):
files = ['abc', 'acb']
for f in files:
with open(f, 'w') as _f:
_f.write('weee')
assert expand_globs(files, testing_workdir) == files
assert expand_globs(['a*'], testing_workdir) == files