Skip to content

Commit 8897dba

Browse files
committed
Use additional npm / Yarn options to speed up installation
The node_modules installation should be as fast and deterministic as possible, as it's taking place internally within a Python package build. Routine developer-facing information should be omitted, as this is expected to be handled as part of the direct Javascript development process. See: https://docs.npmjs.com/cli/v7/commands/npm-install#configuration https://yarnpkg.com/cli/install#options
1 parent eac55d9 commit 8897dba

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

hatch_jupyter_builder/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,27 @@ def npm_builder(
9494
if isinstance(npm, str):
9595
npm = [npm]
9696

97+
is_yarn = (abs_path / "yarn.lock").exists()
98+
9799
# Find a suitable default for the npm command.
98100
if npm is None:
99-
is_yarn = (abs_path / "yarn.lock").exists()
100101
if is_yarn and not which("yarn"):
101102
log.warning("yarn not found, ignoring yarn.lock file")
102103
is_yarn = False
103-
104104
npm = ["yarn"] if is_yarn else ["npm"]
105105

106106
npm_cmd = normalize_cmd(npm)
107107

108+
install_cmd = ["install", "--immutable"] if is_yarn else ["install", "--no-audit", "--no-fund"]
109+
108110
if build_dir and source_dir and not force:
109111
should_build = is_stale(build_dir, source_dir)
110112
else:
111113
should_build = True
112114

113115
if should_build:
114116
log.info("Installing build dependencies with npm. This may take a while...")
115-
run([*npm_cmd, "install"], cwd=str(abs_path))
117+
run([*npm_cmd, *install_cmd], cwd=str(abs_path))
116118
if build_cmd:
117119
run([*npm_cmd, "run", build_cmd], cwd=str(abs_path))
118120
else:

tests/test_npm_builder.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_npm_builder(mocker, repo):
2121
npm_builder("wheel", "standard", path=repo)
2222
run.assert_has_calls(
2323
[
24-
call(["foo", "install"], cwd=str(repo)),
24+
call(["foo", "install", "--no-audit", "--no-fund"], cwd=str(repo)),
2525
call(["foo", "run", "build"], cwd=str(repo)),
2626
]
2727
)
@@ -49,7 +49,7 @@ def test_npm_builder_yarn(mocker, repo):
4949
npm_builder("wheel", "standard", path=repo)
5050
run.assert_has_calls(
5151
[
52-
call(["foo", "install"], cwd=str(repo)),
52+
call(["foo", "install", "--immutable"], cwd=str(repo)),
5353
call(["foo", "run", "build"], cwd=str(repo)),
5454
]
5555
)
@@ -63,7 +63,7 @@ def test_npm_builder_missing_yarn(mocker, repo):
6363
npm_builder("wheel", "standard", path=repo)
6464
run.assert_has_calls(
6565
[
66-
call(["foo", "install"], cwd=str(repo)),
66+
call(["foo", "install", "--no-audit", "--no-fund"], cwd=str(repo)),
6767
call(["foo", "run", "build"], cwd=str(repo)),
6868
]
6969
)
@@ -76,7 +76,7 @@ def test_npm_builder_path(mocker, tmp_path):
7676
npm_builder("wheel", "standard", path=tmp_path)
7777
run.assert_has_calls(
7878
[
79-
call(["foo", "install"], cwd=str(tmp_path)),
79+
call(["foo", "install", "--no-audit", "--no-fund"], cwd=str(tmp_path)),
8080
call(["foo", "run", "build"], cwd=str(tmp_path)),
8181
]
8282
)
@@ -89,7 +89,7 @@ def test_npm_builder_editable(mocker, repo):
8989
npm_builder("wheel", "editable", path=repo, editable_build_cmd="foo")
9090
run.assert_has_calls(
9191
[
92-
call(["foo", "install"], cwd=str(repo)),
92+
call(["foo", "install", "--no-audit", "--no-fund"], cwd=str(repo)),
9393
call(["foo", "run", "foo"], cwd=str(repo)),
9494
]
9595
)
@@ -102,7 +102,7 @@ def test_npm_builder_npm_str(mocker, repo):
102102
npm_builder("wheel", "standard", path=repo, npm="npm")
103103
run.assert_has_calls(
104104
[
105-
call(["npm", "install"], cwd=str(repo)),
105+
call(["npm", "install", "--no-audit", "--no-fund"], cwd=str(repo)),
106106
call(["npm", "run", "build"], cwd=str(repo)),
107107
]
108108
)
@@ -113,7 +113,7 @@ def test_npm_builder_npm_build_command_none(mocker, repo):
113113
run = mocker.patch("hatch_jupyter_builder.utils.run")
114114
which.return_value = "npm"
115115
npm_builder("wheel", "standard", path=repo, build_cmd=None)
116-
run.assert_has_calls([call(["npm", "install"], cwd=str(repo))])
116+
run.assert_has_calls([call(["npm", "install", "--no-audit", "--no-fund"], cwd=str(repo))])
117117

118118

119119
def test_npm_builder_not_stale(mocker, repo):

0 commit comments

Comments
 (0)