mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-07 10:04:07 +00:00
update setup.py css build step for scss
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "python3 ./bower-lite",
|
"postinstall": "python3 ./bower-lite",
|
||||||
"css": "sass -I share/jupyterhub/static/components --source-map share/jupyterhub/static/scss/style.scss:share/jupyterhub/static/css/style.css"
|
"css": "sass --style compressed -I share/jupyterhub/static/components --source-map share/jupyterhub/static/scss/style.scss:share/jupyterhub/static/css/style.min.css"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"sass": "^1.74.1"
|
"sass": "^1.74.1"
|
||||||
|
45
setup.py
45
setup.py
@@ -113,27 +113,34 @@ class NPM(BaseCommand):
|
|||||||
|
|
||||||
|
|
||||||
class CSS(BaseCommand):
|
class CSS(BaseCommand):
|
||||||
description = "compile CSS from LESS"
|
description = "compile CSS"
|
||||||
|
|
||||||
def should_run(self):
|
def should_run(self):
|
||||||
"""Does less need to run?"""
|
"""Does CSS need to run?"""
|
||||||
# from IPython.html.tasks.py
|
|
||||||
|
|
||||||
css_targets = [pjoin(static, 'css', 'style.min.css')]
|
css_targets = [pjoin(static, 'css', 'style.min.css')]
|
||||||
css_maps = [t + '.map' for t in css_targets]
|
css_maps = [t + '.map' for t in css_targets]
|
||||||
targets = css_targets + css_maps
|
targets = css_targets + css_maps
|
||||||
if not all(os.path.exists(t) for t in targets):
|
earliest_target_mtime = float('inf')
|
||||||
# some generated files don't exist
|
earliest_target_name = ''
|
||||||
return True
|
for t in targets:
|
||||||
earliest_target = sorted(mtime(t) for t in targets)[0]
|
if not os.path.exists(t):
|
||||||
|
print(f"Need to build css target: {t}")
|
||||||
|
return True
|
||||||
|
target_mtime = mtime(t)
|
||||||
|
if target_mtime < earliest_target_mtime:
|
||||||
|
earliest_target_name = t
|
||||||
|
earliest_target_mtime = target_mtime
|
||||||
|
|
||||||
# check if any .less files are newer than the generated targets
|
# check if any .scss files are newer than the generated targets
|
||||||
for dirpath, dirnames, filenames in os.walk(static):
|
for dirpath, dirnames, filenames in os.walk(static):
|
||||||
for f in filenames:
|
for f in filenames:
|
||||||
if f.endswith('.less'):
|
if f.endswith('.scss'):
|
||||||
path = pjoin(static, dirpath, f)
|
path = pjoin(static, dirpath, f)
|
||||||
timestamp = mtime(path)
|
timestamp = mtime(path)
|
||||||
if timestamp > earliest_target:
|
if timestamp > earliest_target_mtime:
|
||||||
|
print(
|
||||||
|
f"mtime for {path} > {earliest_target_name}, needs update"
|
||||||
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
@@ -144,26 +151,18 @@ class CSS(BaseCommand):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.run_command('js')
|
self.run_command('js')
|
||||||
print("Building css with less")
|
print("Building css")
|
||||||
|
|
||||||
style_less = pjoin(static, 'scss', 'style.scss')
|
args = ['npm', 'run', 'css']
|
||||||
style_css = pjoin(static, 'css', 'style.min.css')
|
|
||||||
sourcemap = style_css + '.map'
|
|
||||||
|
|
||||||
args = [
|
|
||||||
'npm',
|
|
||||||
'run',
|
|
||||||
'css',
|
|
||||||
]
|
|
||||||
try:
|
try:
|
||||||
check_call(args, cwd=here, shell=shell)
|
check_call(args, cwd=here, shell=shell)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print("Failed to run lessc: %s" % e, file=sys.stderr)
|
print("Failed to build css: %s" % e, file=sys.stderr)
|
||||||
print("You can install js dependencies with `npm install`", file=sys.stderr)
|
print("You can install js dependencies with `npm install`", file=sys.stderr)
|
||||||
raise
|
raise
|
||||||
# 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()
|
||||||
assert not self.should_run(), 'CSS.run failed'
|
assert not self.should_run(), 'CSS.run did not produce up-to-date output'
|
||||||
|
|
||||||
|
|
||||||
class JSX(BaseCommand):
|
class JSX(BaseCommand):
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
{% block stylesheet %}
|
{% block stylesheet %}
|
||||||
<link rel="stylesheet" href="{{ static_url("css/style.css") }}" type="text/css"/>
|
<link rel="stylesheet" href="{{ static_url("css/style.min.css") }}" type="text/css"/>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block favicon %}
|
{% block favicon %}
|
||||||
<link rel="icon" href="{{ static_url("favicon.ico") }}" type="image/x-icon">
|
<link rel="icon" href="{{ static_url("favicon.ico") }}" type="image/x-icon">
|
||||||
|
Reference in New Issue
Block a user