remove bower

use npm to fetch dependencies and a simple postinstall script to copy into components
This commit is contained in:
Min RK
2017-08-04 11:20:17 +02:00
parent e01ce7b665
commit 00a4aef607
7 changed files with 82 additions and 61 deletions

View File

@@ -1,3 +0,0 @@
{
"directory": "share/jupyter/hub/static/components"
}

View File

@@ -1,7 +1,7 @@
include README.md include README.md
include COPYING.md include COPYING.md
include setupegg.py include setupegg.py
include bower.json include bower-lite
include package.json include package.json
include *requirements.txt include *requirements.txt
include Dockerfile include Dockerfile
@@ -18,12 +18,13 @@ graft docs
prune docs/node_modules prune docs/node_modules
# prune some large unused files from components # prune some large unused files from components
prune share/jupyter/hub/static/components/bootstrap/css prune share/jupyter/hub/static/components/bootstrap/dist/css
exclude share/jupyter/hub/static/components/components/fonts/*.svg exclude share/jupyter/hub/static/components/bootstrap/dist/fonts/*.svg
exclude share/jupyter/hub/static/components/bootstrap/less/*.js prune share/jupyter/hub/static/components/font-awesome/css
exclude share/jupyter/hub/static/components/font-awesome/css prune share/jupyter/hub/static/components/font-awesome/scss
exclude share/jupyter/hub/static/components/font-awesome/fonts/*.svg exclude share/jupyter/hub/static/components/font-awesome/fonts/*.svg
exclude share/jupyter/hub/static/components/jquery/*migrate*.js prune share/jupyter/hub/static/components/jquery/external
prune share/jupyter/hub/static/components/jquery/src
prune share/jupyter/hub/static/components/moment/lang prune share/jupyter/hub/static/components/moment/lang
prune share/jupyter/hub/static/components/moment/min prune share/jupyter/hub/static/components/moment/min

36
bower-lite Executable file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/env python
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
"""
bower-lite
Since Bower's on its way out,
stage frontend dependencies from node_modules into components
"""
import json
import os
from os.path import join
import shutil
HERE = os.path.abspath(os.path.dirname(__file__))
components = join(HERE, "share", "jupyter", "hub", "static", "components")
node_modules = join(HERE, "node_modules")
if os.path.exists(components):
shutil.rmtree(components)
os.mkdir(components)
with open(join(HERE, 'package.json')) as f:
package_json = json.load(f)
dependencies = package_json['dependencies']
for dep in dependencies:
src = join(node_modules, dep)
dest = join(components, dep)
print("%s -> %s" % (src, dest))
shutil.copytree(src, dest)

View File

@@ -1,11 +0,0 @@
{
"name": "jupyterhub-deps",
"version": "0.0.0",
"dependencies": {
"bootstrap": "components/bootstrap#~3.3",
"font-awesome": "components/font-awesome#~4.7",
"jquery": "components/jquery#~3.2",
"moment": "~2.18",
"requirejs": "~2.3"
}
}

View File

@@ -8,10 +8,19 @@
"type": "git", "type": "git",
"url": "https://github.com/jupyter/jupyterhub.git" "url": "https://github.com/jupyter/jupyterhub.git"
}, },
"scripts": {
"postinstall": "./bower-lite"
},
"devDependencies": { "devDependencies": {
"bower": "*",
"less": "^2.7.1", "less": "^2.7.1",
"less-plugin-clean-css": "^1.5.1", "less-plugin-clean-css": "^1.5.1",
"clean-css": "^3.4.13" "clean-css": "^3.4.13"
},
"dependencies": {
"bootstrap": "^3.3.7",
"font-awesome": "^4.7.0",
"jquery": "^3.2.1",
"moment": "^2.18.1",
"requirejs": "^2.3.4"
} }
} }

View File

@@ -149,45 +149,34 @@ class BaseCommand(Command):
return [] return []
class Bower(BaseCommand): class NPM(BaseCommand):
description = "fetch static client-side components with bower" description = "fetch static client-side components with bower"
user_options = [] user_options = []
bower_dir = pjoin(static, 'components')
node_modules = pjoin(here, 'node_modules') node_modules = pjoin(here, 'node_modules')
bower_dir = pjoin(static, 'components')
def should_run(self): def should_run(self):
if not os.path.exists(self.bower_dir):
return True
return mtime(self.bower_dir) < mtime(pjoin(here, 'bower.json'))
def should_run_npm(self):
if not shutil.which('npm'): if not shutil.which('npm'):
print("npm unavailable", file=sys.stderr) print("npm unavailable", file=sys.stderr)
return False return False
if not os.path.exists(self.bower_dir):
return True
if not os.path.exists(self.node_modules): if not os.path.exists(self.node_modules):
return True return True
if mtime(self.bower_dir) < mtime(self.node_modules):
return True
return mtime(self.node_modules) < mtime(pjoin(here, 'package.json')) return mtime(self.node_modules) < mtime(pjoin(here, 'package.json'))
def run(self): def run(self):
if not self.should_run(): if not self.should_run():
print("bower dependencies up to date") print("npm dependencies up to date")
return return
if self.should_run_npm(): print("installing js dependencies with npm")
print("installing build dependencies with npm")
check_call(['npm', 'install', '--progress=false'], cwd=here, shell=shell) check_call(['npm', 'install', '--progress=false'], cwd=here, shell=shell)
os.utime(self.node_modules) os.utime(self.node_modules)
env = os.environ.copy()
env['PATH'] = npm_path
args = ['bower', 'install', '--allow-root', '--config.interactive=false']
try:
check_call(args, cwd=here, env=env, shell=shell)
except OSError as e:
print("Failed to run bower: %s" % e, file=sys.stderr)
print("You can install js dependencies with `npm install`", file=sys.stderr)
raise
os.utime(self.bower_dir) os.utime(self.bower_dir)
# update data-files in case this created new files # update data-files in case this created new files
self.distribution.data_files = get_data_files() self.distribution.data_files = get_data_files()
@@ -275,7 +264,7 @@ class bdist_egg_disabled(bdist_egg):
setup_args['cmdclass'] = { setup_args['cmdclass'] = {
'js': Bower, 'js': NPM,
'css': CSS, 'css': CSS,
'build_py': js_css_first(build_py, strict=is_repo), 'build_py': js_css_first(build_py, strict=is_repo),
'sdist': js_css_first(sdist, strict=True), 'sdist': js_css_first(sdist, strict=True),

View File

@@ -35,8 +35,8 @@
<link rel="stylesheet" href="{{ static_url("css/style.min.css") }}" type="text/css"/> <link rel="stylesheet" href="{{ static_url("css/style.min.css") }}" type="text/css"/>
{% endblock %} {% endblock %}
<script src="{{static_url("components/requirejs/require.js") }}" type="text/javascript" charset="utf-8"></script> <script src="{{static_url("components/requirejs/require.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("components/jquery/jquery.min.js") }}" type="text/javascript" charset="utf-8"></script> <script src="{{static_url("components/jquery/dist/jquery.min.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("components/bootstrap/js/bootstrap.min.js") }}" type="text/javascript" charset="utf-8"></script> <script src="{{static_url("components/bootstrap/dist/js/bootstrap.min.js") }}" type="text/javascript" charset="utf-8"></script>
<script> <script>
require.config({ require.config({
{% if version_hash %} {% if version_hash %}
@@ -45,8 +45,8 @@
baseUrl: '{{static_url("js", include_version=False)}}', baseUrl: '{{static_url("js", include_version=False)}}',
paths: { paths: {
components: '../components', components: '../components',
jquery: '../components/jquery/jquery.min', jquery: '../components/jquery/dist/jquery.min',
bootstrap: '../components/bootstrap/js/bootstrap.min', bootstrap: '../components/bootstrap/dist/js/bootstrap.min',
moment: "../components/moment/moment", moment: "../components/moment/moment",
}, },
shim: { shim: {