From d82b468cd5895e7c72bce72289522549f7225496 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Thu, 21 Dec 2017 15:25:09 -0600 Subject: [PATCH 1/2] Invoke nix-build with single expression, nix-build handles this better This results in much less memory usage, see issue for example. Fixes #84. --- nox/review.py | 7 +++---- nox/tests/test_review.py | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nox/review.py b/nox/review.py index 0d31db9..81fe333 100644 --- a/nox/review.py +++ b/nox/review.py @@ -15,10 +15,9 @@ def get_build_command(args, attrs, path): """ 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("with import %s {}; [ %s ]" % (path, ' '.join(attrs))) return command diff --git a/nox/tests/test_review.py b/nox/tests/test_review.py index b7f3042..0329c87 100644 --- a/nox/tests/test_review.py +++ b/nox/tests/test_review.py @@ -5,12 +5,13 @@ 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([], ["nox"], "./.") + self.assertEqual(["nix-build", "-E", "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 , , From 9184555c954d571d896a5c6dfbfe5b783f7d3b24 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Thu, 21 Dec 2017 15:51:55 -0600 Subject: [PATCH 2/2] Send attribute expression via stdin, fixes #73. --- nox/review.py | 19 ++++++++++++++----- nox/tests/test_review.py | 8 ++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/nox/review.py b/nox/review.py index 81fe333..8bd9375 100644 --- a/nox/review.py +++ b/nox/review.py @@ -11,16 +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 command.append("-E") + command.append("-") - command.append("with import %s {}; [ %s ]" % (path, ' '.join(attrs))) 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: @@ -32,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) diff --git a/nox/tests/test_review.py b/nox/tests/test_review.py index 0329c87..ccb7405 100644 --- a/nox/tests/test_review.py +++ b/nox/tests/test_review.py @@ -5,8 +5,12 @@ class TestReview(unittest.TestCase): def test_get_build_command(self): - result = review.get_build_command([], ["nox"], "./.") - self.assertEqual(["nix-build", "-E", "with import ./. {}; [ 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