Remove djangobwr and other bower-related things.

- Legacy-Id: 19575
This commit is contained in:
Lars Eggert 2021-11-09 11:29:53 +00:00
parent 8b222dff35
commit dedbc57855
13 changed files with 3 additions and 402 deletions

View file

View file

@ -1,10 +0,0 @@
from django.contrib.staticfiles.finders import AppDirectoriesFinder
class AppDirectoriesFinderBower(AppDirectoriesFinder):
def list(self, ignore_patterns):
"""
List all files in all app storages.
"""
ignore_patterns.append("bower_components")
return super(AppDirectoriesFinderBower, self).list(ignore_patterns)

View file

@ -1,232 +0,0 @@
import os
import sys
import json
import tempfile
import shutil
import hashlib
import glob
import textwrap
from subprocess import call, check_output, CalledProcessError
from optparse import make_option
import debug # pyflakes:ignore
from django.core.management.base import BaseCommand
from django.core.files.storage import FileSystemStorage
from django.conf import settings
from django.contrib.staticfiles.finders import BaseStorageFinder, AppDirectoriesFinder
class BaseDirectoryFinder(BaseStorageFinder):
storage = FileSystemStorage(location=settings.BASE_DIR)
class Command(BaseCommand):
"""
This command goes through any static/ directories of installed apps,
and the directories listed in settings.STATICFILES_DIRS. If package
description files for bower, npm, or grunt are found in any of these
locations, it will use the appropriate package manager to install the
listed packages in a temporary folder, using these commands:
- package.json: npm install
- Gruntfile.js: grunt default
- bower.json: bower install
It will then extract the distribution files to the location indicated in
settings.COMPONENT_ROOT.
"""
help = textwrap.dedent(__doc__).lstrip()
component_root = getattr(settings, 'COMPONENT_ROOT', os.path.join(settings.STATIC_ROOT, "components"))
def add_arguments(self, parser):
parser.add_argument('--with-version', dest='with_version', default=False, action='store_true',
help='Create component directories with version numbers')
parser.add_argument('--keep-packages', dest='keep_packages', default=False, action='store_true',
help='Keep the downloaded bower packages, instead of removing them after moving '
'distribution files to settings.COMPONENT_ROOT')
bower_info = {}
overrides = {}
def npm_install(self, pkg_json_path):
os.chdir(os.path.dirname(pkg_json_path))
call(['npm', 'install'])
def grunt_default(self, grunt_js_path):
os.chdir(os.path.dirname(grunt_js_path))
call(['grunt'])
def bower_install(self, bower_json_path, dest_dir):
"""Runs bower commnand for the passed bower.json path.
:param bower_json_path: bower.json file to install
:param dest_dir: where the compiled result will arrive
"""
# Verify that we are able to run bower, in order to give a good error message in the
# case that it's not installed. Do this separately from the 'bower install' call, in
# order not to warn about a missing bower in the case of installation-related errors.
try:
bower_version = check_output(['bower', '--version']).strip()
except OSError as e:
print("Trying to run bower failed -- is it installed? The error was: %s" % e)
exit(1)
except CalledProcessError as e:
print("Checking the bower version failed: %s" % e)
exit(2)
print("\nBower %s" % bower_version)
print("Installing from %s\n" % bower_json_path)
# bower args
args = ['bower', 'install', bower_json_path, '--allow-root',
'--verbose', '--config.cwd={}'.format(dest_dir), '-p']
# run bower command
call(args)
def get_bower_info(self, bower_json_path):
if not bower_json_path in self.bower_info:
self.bower_info[bower_json_path] = json.load(open(bower_json_path))
def get_bower_main_list(self, bower_json_path, override):
"""
Returns the bower.json main list or empty list.
Applies overrides from the site-wide bower.json.
"""
self.get_bower_info(bower_json_path)
main_list = self.bower_info[bower_json_path].get('main')
component = self.bower_info[bower_json_path].get('name')
if (override in self.bower_info
and "overrides" in self.bower_info[override]
and component in self.bower_info[override].get("overrides")
and "main" in self.bower_info[override].get("overrides").get(component)):
main_list = self.bower_info[override].get("overrides").get(component).get("main")
if isinstance(main_list, list):
return main_list
if main_list:
return [main_list]
return []
def get_bower_version(self, bower_json_path):
"""Returns the bower.json main list or empty list.
"""
self.get_bower_info(bower_json_path)
return self.bower_info[bower_json_path].get("version")
def clean_components_to_static_dir(self, bower_dir, override):
print("\nMoving component files to %s\n" % (self.component_root,))
for directory in os.listdir(bower_dir):
print("Component: %s" % (directory, ))
src_root = os.path.join(bower_dir, directory)
for bower_json in ['bower.json', '.bower.json']:
bower_json_path = os.path.join(src_root, bower_json)
if os.path.exists(bower_json_path):
main_list = self.get_bower_main_list(bower_json_path, override) + ['bower.json']
version = self.get_bower_version(bower_json_path)
dst_root = os.path.join(self.component_root, directory)
if self.with_version:
assert not dst_root.endswith(os.sep)
dst_root += "-"+version
for pattern in filter(None, main_list):
src_pattern = os.path.join(src_root, pattern)
# main_list elements can be fileglob patterns
for src_path in glob.glob(src_pattern):
if not os.path.exists(src_path):
print("Could not find source path: %s" % (src_path, ))
# Build the destination path
src_part = src_path[len(src_root+'/'):]
if src_part.startswith('dist/'):
src_part = src_part[len('dist/'):]
dst_path = os.path.join(dst_root, src_part)
# Normalize the paths, for good looks
src_path = os.path.abspath(src_path)
dst_path = os.path.abspath(dst_path)
# Check if we need to copy the file at all.
if os.path.exists(dst_path):
with open(src_path, 'br') as src:
src_hash = hashlib.sha1(src.read()).hexdigest()
with open(dst_path, 'br') as dst:
dst_hash = hashlib.sha1(dst.read()).hexdigest()
if src_hash == dst_hash:
#print('{0} = {1}'.format(src_path, dst_path))
continue
# Make sure dest dir exists.
dst_dir = os.path.dirname(dst_path)
if not os.path.exists(dst_dir):
os.makedirs(dst_dir)
print(' {0} > {1}'.format(src_path, dst_path))
shutil.copy(src_path, dst_path)
break
def handle(self, *args, **options):
self.with_version = options.get("with_version")
self.keep_packages = options.get("keep_packages")
temp_dir = getattr(settings, 'BWR_APP_TMP_FOLDER', 'tmp')
temp_dir = os.path.abspath(temp_dir)
# finders
basefinder = BaseDirectoryFinder()
appfinder = AppDirectoriesFinder()
# Assume bower.json files are to be found in each app directory,
# rather than in the app's static/ subdirectory:
appfinder.source_dir = '.'
finders = (basefinder, appfinder, )
if os.path.exists(temp_dir):
if not self.keep_packages:
sys.stderr.write(
"\nWARNING:\n\n"
" The temporary package installation directory exists, but the --keep-packages\n"
" option has not been given. In order to not delete anything which should be\n"
" kept, %s will not be removed.\n\n"
" Please remove it manually, or use the --keep-packages option to avoid this\n"
" message.\n\n" % (temp_dir,))
self.keep_packages = True
else:
os.makedirs(temp_dir)
for finder in finders:
for path in finder.find('package.json', all=True):
self.npm_install(path)
for finder in finders:
for path in finder.find('Gruntfile.json', all=True):
self.grunt_default(path)
for finder in finders:
for path in finder.find('bower.json', all=True):
self.get_bower_info(path)
self.bower_install(path, temp_dir)
bower_dir = os.path.join(temp_dir, 'bower_components')
# nothing to clean
if not os.path.exists(bower_dir):
print('No components seems to have been found by bower, exiting.')
sys.exit(0)
self.clean_components_to_static_dir(bower_dir, path)
if not self.keep_packages:
shutil.rmtree(temp_dir)

View file

@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View file

View file

@ -77,9 +77,6 @@ RUN dpkg-reconfigure locales && \
update-locale LC_ALL en_US.UTF-8
ENV LC_ALL en_US.UTF-8
# Install bower
RUN npm install -g bower
# Install idnits
ADD https://raw.githubusercontent.com/ietf-tools/idnits-mirror/main/idnits /usr/local/bin/
RUN chmod +rx /usr/local/bin/idnits
@ -131,4 +128,4 @@ COPY docker-init.sh /docker-init.sh
RUN chmod +x /docker-init.sh
WORKDIR /root/src
ENTRYPOINT ["/docker-init.sh"]
ENTRYPOINT ["/docker-init.sh"]

View file

@ -1,33 +0,0 @@
Handling of External Javascript and CSS Components
==================================================
The file ``bower.json`` in this direcory is a bower_ file which lists the
external web assets used by the datatracker.
In order to update the version of a component listed in ``ietf/bower.json``,
or add a new one, you should edit ``bower.json``, and then run the management
command::
$ ietf/manage.py bower_install
That command will fetch the required version of each external component listed
in ``bower.json`` (actually, it will do this for *all* ``bower.json`` files
found in the ``static/`` directories of all ``INSTALLED_APPS`` and the
directories in ``settings.STATICFILES_DIRS``), saving them temporarily under
``.tmp/bower_components/``; it will then extract the relevant ``js`` and
``css`` files and place them in an appropriately named directory under
``static/lib/``. The latter location is controlled by ``COMPONENT_ROOT`` in
``settings.py``.
(Not surprisingly, you need to have bower_ installed in order to use this
management command.)
The ``bower_install`` command is not run automatically by ``bin/mkrelease``,
since it needs an updated ``bower.json`` in order to do anything interesting;
and we're not running ``bower update`` since some package releases break
compatibility. So when you're intending to update an external web asset to a
newer version, you need to edit the ``bower.json`` file, run ``manage.py
bower_install``, verify that the new version doesn't break things, and then
commit the new files under ``static\lib\`` and the updated ``bower.json``.
.. _bower: http://bower.io/

View file

@ -1,66 +0,0 @@
{
"name": "datatracker",
"version": "6.0.0",
"ignore": [],
"main": [],
"dependencies": {
"bootstrap-datepicker": "~1",
"d3": "~3",
"font-awesome": "~4",
"fullcalendar": "~4",
"highcharts": "~6",
"js-cookie": "~2",
"jquery": "~1",
"jquery.tablesorter": "~2",
"moment": "~2",
"moment-timezone": "~0",
"select2": "~3",
"select2-bootstrap-css": "~1",
"spin.js": "~2",
"zxcvbn": "~4"
},
"devDependencies": {},
"overrides": {
"bootstrap-datepicker": {
"main": [
"dist/css/bootstrap-datepicker3.min.css",
"dist/js/bootstrap-datepicker.min.js"
]
},
"font-awesome": {
"main": [
"./css/font-awesome.min.css",
"./fonts/*"
]
},
"moment": {
"main": [
"min/moment.min.js"
]
},
"tablesorter": {
"main": [
"dist/js/jquery.tablesorter.combined.min.js",
"dist/css/theme.bootstrap.min.css"
]
},
"spin.js": {
"main": "spin.min.js"
},
"highcharts": {
"main": [
"highcharts.js",
"highcharts-more.js",
"highstock.js",
"highmaps.js",
"modules/exporting.js",
"modules/export-data.js",
"modules/offline-exporting.js",
"modules/map.js"
]
},
"js-cookie": {
"main": "src/js.cookie.js"
}
}
}

View file

@ -165,16 +165,11 @@ else:
STATIC_URL = "https://www.ietf.org/lib/dt/%s/"%__version__
STATIC_ROOT = "/a/www/www6s/lib/dt/%s/"%__version__
# Destination for components handled by djangobower
COMPONENT_ROOT = BASE_DIR + "/externals/static/"
COMPONENT_URL = STATIC_URL
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'ietf.utils.bower_storage.BowerStorageFinder',
)
WSGI_APPLICATION = "ietf.wsgi.application"
@ -442,7 +437,6 @@ INSTALLED_APPS = [
'corsheaders',
'django_markup',
'django_password_strength',
'djangobwr',
'form_utils',
'oidc_provider',
'simple_history',
@ -1292,4 +1286,4 @@ if SERVER_MODE != 'production':
CSRF_COOKIE_SAMESITE = 'Lax'
SESSION_COOKIE_SECURE = False
SESSION_COOKIE_SAMESITE = 'Lax'

View file

@ -1,12 +0,0 @@
from django.core.files.storage import FileSystemStorage
from django.contrib.staticfiles.finders import BaseStorageFinder
from django.conf import settings
import debug # pyflakes:ignore
class BowerStorageFinder(BaseStorageFinder):
storage = FileSystemStorage(location=settings.COMPONENT_ROOT, base_url=settings.COMPONENT_URL)
def find(self, path, all=False):
files = super(BowerStorageFinder, self).find(path, all)
return files

View file

@ -37,7 +37,6 @@ from ietf.group.factories import GroupFactory
from ietf.group.models import Group
from ietf.person.name import name_parts, unidecode_name
from ietf.submit.tests import submission_file
from ietf.utils.bower_storage import BowerStorageFinder
from ietf.utils.draft import Draft, getmeta
from ietf.utils.log import unreachable, assertion
from ietf.utils.mail import send_mail_preformatted, send_mail_text, send_mail_mime, outbox, get_payload_text
@ -390,39 +389,6 @@ class AdminTestCase(TestCase):
self.assertContains(r, model._meta.model_name,
msg_prefix="There doesn't seem to be any admin API for model %s.models.%s"%(app.__name__,model.__name__,))
## One might think that the code below would work, but it doesn't ...
# def list_static_files(path):
# r = Path(settings.STATIC_ROOT)
# p = r / path
# files = list(p.glob('**/*'))
# relfn = [ str(file.relative_to(r)) for file in files ]
# return relfn
#
# class TestBowerStaticFiles(TestCase):
#
# def test_bower_static_file_finder(self):
# from django.templatetags.static import static
# bower_json = os.path.join(settings.BASE_DIR, 'bower.json')
# with open(bower_json) as file:
# bower_info = json.load(file)
# for asset in bower_info["dependencies"]:
# files = list_static_files(asset)
# self.assertGreater(len(files), 0)
# for file in files:
# url = static(file)
# debug.show('url')
# r = self.client.get(url)
# self.assertEqual(r.status_code, 200)
class TestBowerStaticFiles(TestCase):
def test_bower_storage_finder(self):
bfs = BowerStorageFinder()
files = bfs.find('.')
self.assertNotEqual(files,[])
class DraftTests(TestCase):
def setUp(self):
@ -528,4 +494,4 @@ class TestRFC2047Strings(TestCase):
('', ''),
)
for encoded_str, unicode in names:
self.assertEqual(unicode, parse_unicode(encoded_str))
self.assertEqual(unicode, parse_unicode(encoded_str))