Skip to content

Commit

Permalink
Merge pull request #23 from Autodesk/fix-input-resolution
Browse files Browse the repository at this point in the history
Fix input resolution when building docker images from file references
  • Loading branch information
avirshup authored Feb 27, 2018
2 parents c0bc066 + b14f2f9 commit 83c4852
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyccc/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def make_tar_stream(build_context, buffer):
"""
tf = tarfile.TarFile(fileobj=buffer, mode='w')
for context_path, fileobj in build_context.items():
if isinstance(fileobj, (files.LocalDirectoryReference, files.LocalFile)):
if getattr(fileobj, 'localpath', None) is not None:
tf.add(fileobj.localpath, arcname=context_path)
else:
tar_add_bytes(tf, context_path, fileobj.read('rb'))
Expand Down
14 changes: 14 additions & 0 deletions pyccc/tests/test_file_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
fixture_types = {}

PYVERSION = sys.version_info.major
THISDIR = os.path.dirname(__file__)


if PYVERSION >= 3:
unicode = str # we'll use "unicode" and "bytes" just to be completely clear
Expand Down Expand Up @@ -115,3 +117,15 @@ def test_containers_are_pickleable(fixture, request):
ctr = request.getfuncargvalue(fixture)
newctr = pickle.loads(pickle.dumps(ctr))
assert newctr.read() == ctr.read()


def test_local_directory_reference(tmpdir):
import filecmp
tmpdir = str(tmpdir)
src = os.path.join(THISDIR, 'data')
localdir = pyccc.files.LocalDirectoryReference(src)
target = os.path.join(tmpdir, 'data')
localdir.put(target)
match, mismatch, errors = filecmp.cmpfiles(src, target, ['a', 'b'])
assert not mismatch
assert not errors
15 changes: 15 additions & 0 deletions pyccc/tests/test_job_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,18 @@ def test_directory_input(fixture, request):
assert job.exitcode == 0
assert job.stdout.strip() == 'a\nb'


@pytest.mark.parametrize('fixture', fixture_types['engine'])
def test_passing_files_between_jobs(fixture, request):
engine = request.getfuncargvalue(fixture)

# this is OK with docker but should fail with a subprocess
job1 = engine.launch(image='alpine', command='echo hello > world')
job1.wait()
assert job1.exitcode == 0

job2 = engine.launch(image='alpine', command='cat helloworld',
inputs={'helloworld': job1.get_output('world')})
job2.wait()
assert job2.exitcode == 0
assert job2.stdout.strip() == 'hello'

0 comments on commit 83c4852

Please sign in to comment.