Skip to content
Open
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
24 changes: 16 additions & 8 deletions nox/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@
from .nixpkgs_repo import get_repo, packages, packages_for_sha


def get_build_command(args, attrs, path):
def get_build_command(args):
""" Get the appropriate command to use to build the given attributes """
command = ['nix-build']
command += args
for a in attrs:
command.append('-A')
command.append(a)
command.append(path)
command.append("-E")
command.append("-")

return command


def get_build_expr(attrs, path):
""" Get the appropriate expression to use to build the given attributes """
return "with import {} {{}}; [ {} ]".format(path, ' '.join(attrs))


def build_in_path(args, attrs, path, dry_run=False):
"""Build the given package attributes in the given nixpkgs path"""
if not attrs:
Expand All @@ -33,15 +37,19 @@ def build_in_path(args, attrs, path, dry_run=False):
click.echo('Building in {}: {}'.format(click.style(result_dir, bold=True),
click.style(' '.join(attrs), bold=True)))

command = get_build_command(args, attrs, canonical_path)
expr = get_build_expr(attrs, canonical_path)
command = get_build_command(args)

click.echo('Invoking {}'.format(' '.join(command)))
click.echo('Invoking {} with expression {}'.format(' '.join(command), expr))

if dry_run:
return

try:
subprocess.check_call(command, cwd=result_dir)
with tempfile.SpooledTemporaryFile() as expr_f:
expr_f.write(expr.encode('utf-8'))
expr_f.seek(0)
subprocess.check_call(command, cwd=result_dir, stdin=expr_f)
except subprocess.CalledProcessError:
click.secho('The invocation of "{}" failed'.format(' '.join(command)), fg='red')
sys.exit(1)
Expand Down
9 changes: 7 additions & 2 deletions nox/tests/test_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@

class TestReview(unittest.TestCase):
def test_get_build_command(self):
result = review.get_build_command([], ["nox"], ".")
self.assertEqual(["nix-build", "-A", "nox", "."], result)
result = review.get_build_command([])
self.assertEqual(["nix-build", "-E", "-"], result)

def test_get_build_expr(self):
result = review.get_build_expr(["nox"], "./.")
self.assertEqual("with import ./. {}; [ nox ]", result)

def test_build_in_path(self):
# Just do a dry run to make sure there aren't any exceptions
self.assertIs(None, review.build_in_path([], ["nox"], ".", dry_run=True))
self.assertIs(None, review.build_in_path([], ["nox"], "./.", dry_run=True))

def test_differences(self):
# Tuples of <old set>, <new set>, <expected difference>
Expand Down