From 612e3f3d26333285135d65a2995393817cba7b7b Mon Sep 17 00:00:00 2001 From: "Afshin T. Darian" Date: Wed, 24 Mar 2021 15:22:43 +0000 Subject: [PATCH] Fix Usage of install_npm --- jupyter_packaging/setupbase.py | 2 +- tests/conftest.py | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/jupyter_packaging/setupbase.py b/jupyter_packaging/setupbase.py index e2ea83d..fb5a212 100644 --- a/jupyter_packaging/setupbase.py +++ b/jupyter_packaging/setupbase.py @@ -547,7 +547,7 @@ def install_npm(path=None, build_dir=None, source_dir=None, build_cmd='build', npm: str or list, optional. The npm executable name, or a tuple of ['node', executable]. """ - npm_builder(path=path, build_dir=build_dir, source_dir=source_dir, build_cmd=build_cmd, force=force, npm=npm) + builder = npm_builder(path=path, build_dir=build_dir, source_dir=source_dir, build_cmd=build_cmd, force=force, npm=npm) class NPM(BaseCommand): description = 'install package.json dependencies using npm' diff --git a/tests/conftest.py b/tests/conftest.py index 42b1391..9548412 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,4 @@ +import json import os import pathlib from pytest import fixture @@ -5,6 +6,12 @@ HERE = pathlib.Path(__file__).resolve() +PACKAGE_JSON = json.dumps(dict( + name="foo", + version="0.1.0", + scripts=dict(build="echo 'hi'") +)) + @fixture(scope="session", autouse=True) def clear_pip_cache(): @@ -59,14 +66,16 @@ def exclude(filename): ) setup_maker_deprecated = lambda name="jupyter_packaging_test_foo", data_files_spec=None, **kwargs: """ -from jupyter_packaging import create_cmdclass +from jupyter_packaging import create_cmdclass, install_npm import setuptools import os def exclude(filename): return os.path.basename(filename) == "exclude.py" -cmdclass = create_cmdclass(data_files_spec={data_files_spec}, exclude=exclude) + +cmdclass = create_cmdclass('jsdeps', data_files_spec={data_files_spec}, exclude=exclude) +cmdclass['jsdeps'] = install_npm() setuptools.setup(cmdclass=cmdclass, {setup_args}) """.format( @@ -147,7 +156,10 @@ def make_package_deprecated(tmp_path, pyproject_toml): """A callable fixture that creates a mock python package in tmp_path and returns the package directory """ - return make_package_base(tmp_path, pyproject_toml, setup_func=setup_maker_deprecated) + package = make_package_base(tmp_path, pyproject_toml, setup_func=setup_maker_deprecated) + package_json = tmp_path / "package.json" + package_json.write_text(PACKAGE_JSON, encoding='utf-8') + return package @fixture