diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 1bf726fb54..49ad5d5cb3 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -16,6 +16,7 @@ requirements: - python run: - python + - psutil - conda - jinja2 - patchelf [linux] diff --git a/conda.recipe/run_test.py b/conda.recipe/run_test.py.backup similarity index 100% rename from conda.recipe/run_test.py rename to conda.recipe/run_test.py.backup diff --git a/conda_build/build.py b/conda_build/build.py index 590f69dd75..9b2c127948 100644 --- a/conda_build/build.py +++ b/conda_build/build.py @@ -269,6 +269,17 @@ def create_info_files(m, files, include_recipe=True): files_with_prefix = sorted(have_prefix_files(files)) binary_has_prefix_files = m.binary_has_prefix_files() text_has_prefix_files = m.has_prefix_files() + + ignore_files = m.ignore_prefix_files() + if ignore_files: + # do we have a list of files, or just ignore everything? + if hasattr(ignore_files, "__iter__"): + files_with_prefix = [f for f in files_with_prefix if f[2] not in ignore_files] + binary_has_prefix_files = [f for f in binary_has_prefix_files if f[2] not in ignore_files] # noqa + text_has_prefix_files = [f for f in text_has_prefix_files if f[2] not in ignore_files] + else: + files_with_prefix = [] + if files_with_prefix and not m.get_value('build/noarch_python'): auto_detect = m.get_value('build/detect_binary_files_with_prefix') if sys.platform == 'win32': diff --git a/conda_build/metadata.py b/conda_build/metadata.py index b41877c7c4..b3d75d9b9c 100644 --- a/conda_build/metadata.py +++ b/conda_build/metadata.py @@ -278,8 +278,8 @@ def _git_clean(source_meta): 'build': ['number', 'string', 'entry_points', 'osx_is_app', 'features', 'track_features', 'preserve_egg_dir', 'no_link', 'binary_relocation', 'script', 'noarch_python', - 'has_prefix_files', 'binary_has_prefix_files', 'script_env', - 'detect_binary_files_with_prefix', 'rpaths', + 'has_prefix_files', 'binary_has_prefix_files', 'ignore_prefix_files', + 'detect_binary_files_with_prefix', 'rpaths', 'script_env', 'always_include_files', 'skip', 'msvc_compiler', 'pin_depends' # pin_depends is experimental still ], @@ -589,6 +589,16 @@ def has_prefix_files(self): "as the path delimiter on Windows") return ret + 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') + if sys.platform == 'win32': + if any('\\' in i for i in ret): + raise RuntimeError("build/ignore_prefix_files paths must use / " + "as the path delimiter on Windows") + return ret + def always_include_files(self): return self.get_value('build/always_include_files', []) diff --git a/tests/test-recipes/metadata/ignore_prefix_files/meta.yaml b/tests/test-recipes/metadata/ignore_prefix_files/meta.yaml new file mode 100644 index 0000000000..136af110e5 --- /dev/null +++ b/tests/test-recipes/metadata/ignore_prefix_files/meta.yaml @@ -0,0 +1,14 @@ +package: + name: conda-build-test-ignore-prefix-files + version: 1.0 + +build: + ignore_prefix_files: True + script: + - echo %PREFIX%\\test.txt > %SCRIPTS%\\test.bat # [win] + - echo %PREFIX%\\test2.txt > %SCRIPTS%\\test2.bat # [win] + - echo ${PREFIX}/bin/test.txt > ${PREFIX}/test.sh # [unix] + - echo ${PREFIX}/bin/test2.txt > ${PREFIX}/test2.sh # [unix] + +about: + summary: test that ignore_prefix_files with boolean setting ignores all files diff --git a/tests/test-recipes/metadata/ignore_prefix_files/run_test.py b/tests/test-recipes/metadata/ignore_prefix_files/run_test.py new file mode 100644 index 0000000000..435bd6589e --- /dev/null +++ b/tests/test-recipes/metadata/ignore_prefix_files/run_test.py @@ -0,0 +1,8 @@ +import os +import sys + +# assumes that sys.prefix is /envs/_test +pkgs = os.path.join(sys.prefix, "..", "..", "pkgs") +info_dir = os.path.join(pkgs, "conda-build-test-ignore-prefix-files-1.0-0", "info") +assert os.path.isdir(info_dir) +assert not os.path.isfile(os.path.join(info_dir, "has_prefix")) diff --git a/tests/test-recipes/metadata/ignore_some_prefix_files/meta.yaml b/tests/test-recipes/metadata/ignore_some_prefix_files/meta.yaml new file mode 100644 index 0000000000..b8f8ec04f4 --- /dev/null +++ b/tests/test-recipes/metadata/ignore_some_prefix_files/meta.yaml @@ -0,0 +1,19 @@ +package: + name: conda-build-test-ignore-some-prefix-files + version: 1.0 + +build: + #has_prefix_files: + # - Scripts\\test.bat # [win] + # - test.sh # [unix] + ignore_prefix_files: + - Scripts\\test2.bat # [win] + - test2.sh # [unix] + script: + - echo %PREFIX%\\test.txt > %SCRIPTS%\\test.bat # [win] + - echo %PREFIX%\\test2.txt > %SCRIPTS%\\test2.bat # [win] + - echo ${PREFIX}/bin/test.txt > ${PREFIX}/test.sh # [unix] + - echo ${PREFIX}/bin/test2.txt > ${PREFIX}/test2.sh # [unix] + +about: + summary: test that ignore_prefix_files with list setting ignores specified files diff --git a/tests/test-recipes/metadata/ignore_some_prefix_files/run_test.py b/tests/test-recipes/metadata/ignore_some_prefix_files/run_test.py new file mode 100644 index 0000000000..c60bbfe0d1 --- /dev/null +++ b/tests/test-recipes/metadata/ignore_some_prefix_files/run_test.py @@ -0,0 +1,11 @@ +import os +import sys + +# assumes that sys.prefix is /envs/_test +pkgs = os.path.normpath(os.path.join(sys.prefix, "..", "..", "pkgs")) +info_dir = os.path.join(pkgs, "conda-build-test-ignore-some-prefix-files-1.0-0", "info") +has_prefix_file = os.path.join(info_dir, "has_prefix") +print(info_dir) +assert os.path.isfile(has_prefix_file) +with open(has_prefix_file) as f: + assert "test2" not in f.read()