Skip to content

Commit 7d71eee

Browse files
authored
Merge pull request #3 from blink1073/update-setupbase
Update for new registerWidget syntax
2 parents 4e1edfd + e9ced35 commit 7d71eee

File tree

12 files changed

+428
-131
lines changed

12 files changed

+428
-131
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
.DS_Store
2+
3+
*.pyc
4+
.cache

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ information:
3333
- `npm_package_name`: name for the npm "front-end" package holding the JavaScript
3434
implementation used in your custom widget.
3535
- `npm_package_version`: initial version of the npm package.
36-
- `jlab_extension_name`: name for the jupyterlab extension npm package (must be different
37-
from `npm_package_name`).
3836
- `jlab_extension_id`: extension ID to supply to JupyterLab when registering the extension.
3937
The recommended format is "jupyter.extensions.<Your UNIQUE designator here>".
4038
- `project_short_description` : a short description for your project that will

cookiecutter.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"python_package_name": "ipywidgetexample",
77
"npm_package_name": "jupyter-widget-example",
88
"npm_package_version": "0.1.0",
9-
"jlab_extension_name": "jupyterlab-widget-example",
109
"jlab_extension_id": "jupyter.extensions.example",
1110
"project_short_description": "A Custom Jupyter Widget Library"
1211
}

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
testpaths=tests
3+
norecursedirs=node_modules

tests/test_instantiate.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
import os
3+
import sys
4+
5+
import pytest
6+
7+
HERE = os.path.abspath(os.path.dirname(__file__))
8+
PROJECT_ROOT = os.path.dirname(HERE)
9+
10+
pytest_plugins = "pytester"
11+
12+
use_shell = os.name == 'nt'
13+
14+
15+
@pytest.fixture(scope='session')
16+
def example_instance(tmpdir_factory):
17+
from cookiecutter.main import cookiecutter
18+
import pip
19+
20+
tmpdir = tmpdir_factory.mktemp('example_instance')
21+
22+
with tmpdir.as_cwd():
23+
cookiecutter(PROJECT_ROOT, no_input=True, config_file=os.path.join(HERE, 'testconfig.yaml'))
24+
instance_path = tmpdir.join('jupyter-widget-testwidgets')
25+
with instance_path.as_cwd():
26+
print(str(instance_path))
27+
try:
28+
pip.main(['install', '-v', '-e', '.[test]'])
29+
yield instance_path
30+
finally:
31+
try:
32+
pip.main(['uninstall', 'ipywidgettestwidgets', '-y'])
33+
except Exception:
34+
pass
35+
36+
37+
def test_python_tests(example_instance, testdir):
38+
with example_instance.as_cwd():
39+
testdir.runpytest()
40+
41+
42+
def test_js_tests(example_instance):
43+
from subprocess import check_call
44+
45+
cmd = ['npm', 'test']
46+
with example_instance.as_cwd():
47+
check_call(cmd, stdout=sys.stdout, stderr=sys.stderr, shell=use_shell)

tests/testconfig.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ default_context:
66
python_package_name: "ipywidgettestwidgets"
77
npm_package_name: "jupyter-widget-testwidgets"
88
npm_package_version: "1.1.0"
9-
jlab_extension_name: "jupyterlab-widget-testwidgets"
109
jlab_extension_id: "jupyter.extensions.testwidgets"
1110
project_short_description: "A Test Jupyter Widget Library"

{{cookiecutter.github_project_name}}/.travis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,5 @@ script:
5454
elif [[ $GROUP == js ]]; then
5555
npm test
5656
fi
57-
before_cache:
58-
# Do not cache our own package
59-
- |
60-
rm -rf packages/{{ cookiecutter.jlab_extension_name }}/node_modules/{{ cookiecutter.npm_package_name }}
6157
after_success:
6258
- codecov

{{cookiecutter.github_project_name}}/MANIFEST.in

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ include pytest.ini
66
include .coverage.rc
77

88
include package.json
9+
include webpack.config.js
910
include {{ cookiecutter.python_package_name }}/labextension/*.tgz
1011

1112
# Documentation
@@ -18,14 +19,16 @@ prune docs/dist
1819
# Examples
1920
graft examples
2021

22+
# Tests
23+
graft tests
24+
prune tests/build
25+
2126
# Javascript files
2227
graft {{ cookiecutter.python_package_name }}/nbextension
23-
graft packages
24-
prune packages/**/node_modules
25-
prune packages/**/coverage
26-
prune packages/**/node_modules
27-
prune packages/**/lib
28-
prune packages/**/test/build
28+
graft src
29+
prune **/node_modules
30+
prune coverage
31+
prune lib
2932

3033
# Patterns to exclude from any directory
3134
global-exclude *~

{{cookiecutter.github_project_name}}/setup.py

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,82 +5,64 @@
55
# Distributed under the terms of the Modified BSD License.
66

77
from __future__ import print_function
8-
9-
# the name of the project
10-
name = '{{ cookiecutter.python_package_name }}'
11-
12-
#-----------------------------------------------------------------------------
13-
# Minimal Python version sanity check
14-
#-----------------------------------------------------------------------------
15-
8+
from glob import glob
9+
from os.path import join as pjoin
1610
import sys
1711

18-
v = sys.version_info
19-
if v[:2] < (3, 3):
20-
# Note: 3.3 is untested, but we'll still allow it
21-
error = "ERROR: %s requires Python version 3.3 or above." % name
22-
print(error, file=sys.stderr)
23-
sys.exit(1)
12+
from setupbase import (
13+
create_cmdclass, install_npm, ensure_targets,
14+
find_packages, combine_commands, ensure_python,
15+
get_version, setup, HERE
16+
)
2417

25-
#-----------------------------------------------------------------------------
26-
# get on with it
27-
#-----------------------------------------------------------------------------
2818

29-
import io
30-
import os
31-
from glob import glob
19+
# The name of the project
20+
name = '{{ cookiecutter.python_package_name }}'
3221

33-
from setuptools import setup, find_packages
22+
# Ensure a valid python version
23+
ensure_python('>=3.3')
3424

35-
from setupbase import (create_cmdclass, install_npm, ensure_targets,
36-
combine_commands, expand_data_files)
25+
# Get our version
26+
version = get_version(pjoin(name, '_version.py'))
3727

38-
pjoin = os.path.join
39-
here = os.path.abspath(os.path.dirname(__file__))
40-
nb_path = os.path.join(here, name, 'nbextension', 'static')
41-
lab_path = os.path.join(here, name, 'labextension', '*.tgz')
28+
nb_path = pjoin(HERE, name, 'nbextension', 'static')
29+
lab_path = pjoin(HERE, name, 'labextension', '*.tgz')
4230

4331
# Representative files that should exist after a successful build
4432
jstargets = [
45-
os.path.join(nb_path, 'extension.js'),
46-
os.path.join(here, 'lib', 'plugin.js'),
33+
pjoin(nb_path, 'index.js'),
34+
pjoin(HERE, 'lib', 'plugin.js'),
4735
]
4836

49-
version_ns = {}
50-
with io.open(pjoin(here, name, '_version.py'), encoding="utf8") as f:
51-
exec(f.read(), {}, version_ns)
52-
53-
54-
cmdclass = create_cmdclass(('jsdeps',))
55-
cmdclass['jsdeps'] = combine_commands(
56-
install_npm(here, build_cmd='build:all'),
57-
ensure_targets(jstargets),
58-
)
59-
60-
61-
package_data = {
37+
package_data_spec = {
6238
name: [
6339
'nbextension/static/*.*js*',
6440
'labextension/*.tgz'
6541
]
6642
}
6743

68-
data_files = expand_data_files([
69-
('share/jupyter/nbextensions/{{ cookiecutter.npm_package_name }}', [pjoin(nb_path, '*.js*')]),
70-
('share/jupyter/lab/extensions', [lab_path])
71-
])
44+
data_files_spec = [
45+
('share/jupyter/nbextensions/{{ cookiecutter.npm_package_name }}',
46+
pjoin(nb_path, '*.js*')),
47+
('share/jupyter/lab/extensions', lab_path)
48+
]
49+
50+
51+
cmdclass = create_cmdclass('jsdeps', package_data_spec=package_data_spec,
52+
data_files_spec=data_files_spec)
53+
cmdclass['jsdeps'] = combine_commands(
54+
install_npm(HERE, build_cmd='build:all'),
55+
ensure_targets(jstargets),
56+
)
7257

7358

7459
setup_args = dict(
7560
name = name,
7661
description = '{{ cookiecutter.project_short_description }}',
77-
version = version_ns['__version__'],
62+
version = version,
7863
scripts = glob(pjoin('scripts', '*')),
7964
cmdclass = cmdclass,
80-
packages = find_packages(here),
81-
package_data = package_data,
82-
include_package_data = True,
83-
data_files = data_files,
65+
packages = find_packages(),
8466
author = '{{ cookiecutter.author_name }}',
8567
author_email = '{{ cookiecutter.author_email }}',
8668
url = 'https://github.com/{{ cookiecutter.github_organization_name }}/{{ cookiecutter.python_package_name }}',
@@ -101,7 +83,7 @@
10183
)
10284

10385

104-
setuptools_args = {}
86+
setuptools_args = dict(include_package_data=True)
10587
install_requires = setuptools_args['install_requires'] = [
10688
'ipywidgets>=7.0.0',
10789
]

0 commit comments

Comments
 (0)