Skip to content

Commit

Permalink
Merge pull request #32 from opensafely-core/fix-pull
Browse files Browse the repository at this point in the history
fix: fix text encoding bug in new pull command
  • Loading branch information
bloodearnest authored Feb 19, 2021
2 parents 171070d + c8379e1 commit a6aed6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions opensafely/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ def main(image, force):

def get_local_images():
ps = subprocess.run(
["docker", "image", "ls", "--format='{{.Repository}}'"],
["docker", "image", "ls", "--format={{.Repository}}"],
check=True,
capture_output=True,
)
return set(ps.stdout.split("\n"))
lines = [line for line in ps.stdout.decode('utf8').split("\n") if line.strip()]
return set(lines)


def remove_deprecated_images(local_images):
Expand Down
10 changes: 5 additions & 5 deletions tests/test_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def tag(image):

def test_default_no_local_images(run, capsys):

run.expect(["docker", "image", "ls", "--format='{{.Repository}}'"], stdout="")
run.expect(["docker", "image", "ls", "--format={{.Repository}}"], stdout=b"")

pull.main(image="all", force=False)
out, err = capsys.readouterr()
Expand All @@ -87,7 +87,7 @@ def test_default_no_local_images(run, capsys):

def test_default_no_local_images_force(run, capsys):

run.expect(["docker", "image", "ls", "--format='{{.Repository}}'"], stdout="")
run.expect(["docker", "image", "ls", "--format={{.Repository}}"], stdout=b"")
run.expect(["docker", "pull", tag("r")])
run.expect(["docker", "pull", tag("python")])
run.expect(["docker", "pull", tag("jupyter")])
Expand All @@ -109,8 +109,8 @@ def test_default_no_local_images_force(run, capsys):
def test_default_with_local_images(run, capsys):

run.expect(
["docker", "image", "ls", "--format='{{.Repository}}'"],
stdout="ghcr.io/opensafely-core/r",
["docker", "image", "ls", "--format={{.Repository}}"],
stdout=b"ghcr.io/opensafely-core/r",
)
run.expect(["docker", "pull", tag("r")])
run.expect(["docker", "image", "prune", "--force"])
Expand All @@ -126,7 +126,7 @@ def test_default_with_local_images(run, capsys):

def test_specific_image(run, capsys):

run.expect(["docker", "image", "ls", "--format='{{.Repository}}'"], stdout="")
run.expect(["docker", "image", "ls", "--format={{.Repository}}"], stdout=b"")
run.expect(["docker", "pull", tag("r")])
run.expect(["docker", "image", "prune", "--force"])

Expand Down

0 comments on commit a6aed6f

Please sign in to comment.