Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for new registerWidget syntax #3

Merged
merged 25 commits into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from 16 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.DS_Store

*.pyc
.cache
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ information:
- `npm_package_name`: name for the npm "front-end" package holding the JavaScript
implementation used in your custom widget.
- `npm_package_version`: initial version of the npm package.
- `jlab_extension_name`: name for the jupyterlab extension npm package (must be different
from `npm_package_name`).
- `jlab_extension_id`: extension ID to supply to JupyterLab when registering the extension.
The recommended format is "jupyter.extensions.<Your UNIQUE designator here>".
- `project_short_description` : a short description for your project that will
Expand Down
1 change: 0 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"python_package_name": "ipywidgetexample",
"npm_package_name": "jupyter-widget-example",
"npm_package_version": "0.1.0",
"jlab_extension_name": "jupyterlab-widget-example",
"jlab_extension_id": "jupyter.extensions.example",
"project_short_description": "A Custom Jupyter Widget Library"
}
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
testpaths=tests
norecursedirs=node_modules
47 changes: 47 additions & 0 deletions tests/test_instantiate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

import os
import sys

import pytest

HERE = os.path.abspath(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(HERE)

pytest_plugins = "pytester"

use_shell = os.name == 'nt'


@pytest.fixture(scope='session')
def example_instance(tmpdir_factory):
from cookiecutter.main import cookiecutter
import pip

tmpdir = tmpdir_factory.mktemp('example_instance')

with tmpdir.as_cwd():
cookiecutter(PROJECT_ROOT, no_input=True, config_file=os.path.join(HERE, 'testconfig.yaml'))
instance_path = tmpdir.join('jupyter-widget-testwidgets')
with instance_path.as_cwd():
print(str(instance_path))
try:
pip.main(['install', '-v', '-e', '.[test]'])
yield instance_path
finally:
try:
pip.main(['uninstall', 'ipywidgettestwidgets', '-y'])
except Exception:
pass


def test_python_tests(example_instance, testdir):
with example_instance.as_cwd():
testdir.runpytest()


def test_js_tests(example_instance):
from subprocess import check_call

cmd = ['npm', 'test']
with example_instance.as_cwd():
check_call(cmd, stdout=sys.stdout, stderr=sys.stderr, shell=use_shell)
1 change: 0 additions & 1 deletion tests/testconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ default_context:
python_package_name: "ipywidgettestwidgets"
npm_package_name: "jupyter-widget-testwidgets"
npm_package_version: "1.1.0"
jlab_extension_name: "jupyterlab-widget-testwidgets"
jlab_extension_id: "jupyter.extensions.testwidgets"
project_short_description: "A Test Jupyter Widget Library"
4 changes: 0 additions & 4 deletions {{cookiecutter.github_project_name}}/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,5 @@ script:
elif [[ $GROUP == js ]]; then
npm test
fi
before_cache:
# Do not cache our own package
- |
rm -rf packages/{{ cookiecutter.jlab_extension_name }}/node_modules/{{ cookiecutter.npm_package_name }}
after_success:
- codecov
87 changes: 35 additions & 52 deletions {{cookiecutter.github_project_name}}/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,82 +5,65 @@
# Distributed under the terms of the Modified BSD License.

from __future__ import print_function

# the name of the project
name = '{{ cookiecutter.python_package_name }}'

#-----------------------------------------------------------------------------
# Minimal Python version sanity check
#-----------------------------------------------------------------------------

from glob import glob
from os.path import join as pjoin
import os
import sys

v = sys.version_info
if v[:2] < (3, 3):
# Note: 3.3 is untested, but we'll still allow it
error = "ERROR: %s requires Python version 3.3 or above." % name
print(error, file=sys.stderr)
sys.exit(1)
from setupbase import (
create_cmdclass, install_npm, ensure_targets,
find_packages, combine_commands, ensure_python,
get_version, setup, HERE
)

#-----------------------------------------------------------------------------
# get on with it
#-----------------------------------------------------------------------------

import io
import os
from glob import glob
# The name of the project
name = '{{ cookiecutter.python_package_name }}'

from setuptools import setup, find_packages
# Ensure a valid python version
ensure_python('>=3.3')

from setupbase import (create_cmdclass, install_npm, ensure_targets,
combine_commands, expand_data_files)
# Get our version
version = get_version(pjoin(name, '_version.py'))

pjoin = os.path.join
here = os.path.abspath(os.path.dirname(__file__))
nb_path = os.path.join(here, name, 'nbextension', 'static')
lab_path = os.path.join(here, name, 'labextension', '*.tgz')
nb_path = pjoin(HERE, name, 'nbextension', 'static')
lab_path = pjoin(HERE, name, 'labextension', '*.tgz')

# Representative files that should exist after a successful build
jstargets = [
os.path.join(nb_path, 'extension.js'),
os.path.join(here, 'lib', 'plugin.js'),
pjoin(nb_path, 'index.js'),
pjoin(HERE, 'lib', 'plugin.js'),
]

version_ns = {}
with io.open(pjoin(here, name, '_version.py'), encoding="utf8") as f:
exec(f.read(), {}, version_ns)


cmdclass = create_cmdclass(('jsdeps',))
cmdclass['jsdeps'] = combine_commands(
install_npm(here, build_cmd='build:all'),
ensure_targets(jstargets),
)


package_data = {
package_data_spec = {
name: [
'nbextension/static/*.*js*',
'labextension/*.tgz'
]
}

data_files = expand_data_files([
('share/jupyter/nbextensions/{{ cookiecutter.npm_package_name }}', [pjoin(nb_path, '*.js*')]),
('share/jupyter/lab/extensions', [lab_path])
])
data_files_spec = [
('share/jupyter/nbextensions/{{ cookiecutter.npm_package_name }}',
pjoin(nb_path, '*.js*')),
('share/jupyter/lab/extensions', lab_path)
]


cmdclass = create_cmdclass('jsdeps', package_data_spec=package_data_spec,
data_files_spec=data_files_spec)
cmdclass['jsdeps'] = combine_commands(
install_npm(HERE, build_cmd='build:all'),
ensure_targets(jstargets),
)


setup_args = dict(
name = name,
description = '{{ cookiecutter.project_short_description }}',
version = version_ns['__version__'],
version = version,
scripts = glob(pjoin('scripts', '*')),
cmdclass = cmdclass,
packages = find_packages(here),
package_data = package_data,
include_package_data = True,
data_files = data_files,
packages = find_packages(),
author = '{{ cookiecutter.author_name }}',
author_email = '{{ cookiecutter.author_email }}',
url = 'https://github.com/{{ cookiecutter.github_organization_name }}/{{ cookiecutter.python_package_name }}',
Expand All @@ -101,7 +84,7 @@
)


setuptools_args = {}
setuptools_args = dict(include_package_data=True)
install_requires = setuptools_args['install_requires'] = [
'ipywidgets>=7.0.0',
]
Expand Down
Loading