Skip to content

Commit

Permalink
Merge pull request #3061 from msarahan/fix_source_files
Browse files Browse the repository at this point in the history
test recipe for parent source_files, try to handle parent recipe folders
  • Loading branch information
msarahan authored Aug 6, 2018
2 parents dbe358a + 860ef93 commit 540d0aa
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 30 deletions.
7 changes: 2 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,8 @@ test_script:
# remove all folders to avoid permission errors. Leave root files (may have coverage info there)
- for /d %%F in (c:\cbtmp\*) do rd /s /q "%%F"
- py.test --color=yes -v --cov conda_build --cov-report xml --cov-append tests --basetemp C:\cbtmp -n 2 -m "not serial"
# install conda-verify from its master branch, at least for a while until it's more stable
- git clone https://github.com/conda/conda-verify
- pushd conda-verify
- pip install .
- popd
# install conda-verify later, so we are ignoring checks in most tests
- conda install -y conda-verify
- py.test --color=yes -v --cov conda_build --cov-report xml tests --basetemp C:\cbtmp -n 0 -m "serial"

# For debugging, this is helpful - zip up the test environment and make it available for later download.
Expand Down
61 changes: 36 additions & 25 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,43 +361,54 @@ def copy_license(m):


def copy_test_source_files(m, destination):
src_dir = None
src_dir = ''
if os.listdir(m.config.work_dir):
src_dir = m.config.work_dir
elif hasattr(m.config, 'recipe_dir') and m.config.recipe_dir:
src_dir = os.path.join(m.config.recipe_dir, 'info', 'test')

if src_dir and os.path.isdir(src_dir):
for pattern in utils.ensure_list(m.get_value('test/source_files', [])):
if utils.on_win and '\\' in pattern:
raise RuntimeError("test/source_files paths must use / "
"as the path delimiter on Windows")
files = glob(join(src_dir, pattern))
if not files:
msg = "Did not find any source_files for test with pattern {0}"
raise RuntimeError(msg.format(pattern))
for f in files:
try:
# disable locking to avoid locking a temporary directory (the extracted
# test folder)
utils.copy_into(f, f.replace(src_dir, destination), m.config.timeout,
locking=False, clobber=True)
except OSError as e:
log = logging.getLogger(__name__)
log.warn("Failed to copy {0} into test files. Error was: {1}".format(f,
str(e)))
for ext in '.pyc', '.pyo':
for f in utils.get_ext_files(destination, ext):
os.remove(f)
src_dirs = [src_dir]
if os.path.isdir(os.path.join(src_dir, 'parent')):
src_dirs.append(os.path.join(src_dir, 'parent'))

for src_dir in src_dirs:
if src_dir and os.path.isdir(src_dir) and src_dir != destination:
for pattern in utils.ensure_list(m.get_value('test/source_files', [])):
if utils.on_win and '\\' in pattern:
raise RuntimeError("test/source_files paths must use / "
"as the path delimiter on Windows")
files = glob(join(src_dir, pattern))
if not files:
msg = "Did not find any source_files for test with pattern {0}"
raise RuntimeError(msg.format(pattern))
for f in files:
try:
# disable locking to avoid locking a temporary directory (the extracted
# test folder)
utils.copy_into(f, f.replace(src_dir, destination), m.config.timeout,
locking=False, clobber=True)
except OSError as e:
log = logging.getLogger(__name__)
log.warn("Failed to copy {0} into test files. Error was: {1}".format(f,
str(e)))
for ext in '.pyc', '.pyo':
for f in utils.get_ext_files(destination, ext):
os.remove(f)

recipe_test_files = m.get_value('test/files')
if recipe_test_files:
orig_recipe_dir = m.path or m.meta.get('extra', {}).get('parent_recipe', {}).get('path')
for pattern in recipe_test_files:
files = glob(join(orig_recipe_dir, pattern))
for f in files:
utils.copy_into(f, f.replace(orig_recipe_dir, destination),
timeout=m.config.timeout, locking=m.config.locking, clobber=True)
basedir = orig_recipe_dir
if not os.path.isfile(f):
basedir = os.path.join(orig_recipe_dir, 'parent')
dest = f.replace(basedir, destination)
if f != dest:
utils.copy_into(f, f.replace(basedir, destination),
timeout=m.config.timeout, locking=m.config.locking,
clobber=True)


def write_hash_input(m):
Expand Down
27 changes: 27 additions & 0 deletions tests/test-recipes/split-packages/test_files_in_parent/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package:
name: test_files_in_parent_recipe
version: 1.0

source:
path: src

build:
script: echo "weee"

outputs:
# one that has same name as top-level
- name: test_files_in_parent_recipe
test:
files:
- recipe_file
commands:
- test -e recipe_file # [unix]
- IF NOT EXIST recipe_file exit 1 # [win]
# one that does not
- name: abc
test:
files:
- recipe_file
commands:
- test -e recipe_file # [unix]
- IF NOT EXIST recipe_file exit 1 # [win]
Empty file.
Empty file.

0 comments on commit 540d0aa

Please sign in to comment.