diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -17,12 +17,12 @@ .vscode/ .directory node_modules/ -swh/web/static/*.* -swh/web/static/js/ -swh/web/static/css/ -swh/web/static/fonts/ -swh/web/static/jssources/ -swh/web/static/img/thirdParty/ +static/*.* +static/js/ +static/css/ +static/fonts/ +static/jssources/ +static/img/thirdParty/ .cache-loader/ build/ dist/ diff --git a/MANIFEST.in b/MANIFEST.in --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,12 +1,11 @@ -include Makefile include pytest.ini include README.md include requirements*.txt include tox.ini include version.txt recursive-include swh py.typed + recursive-include swh/web/assets * -recursive-include swh/web/static * recursive-include swh/web/templates * recursive-include swh/web/tests/resources * diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -1,9 +1,11 @@ #!/usr/bin/env python3 -# Copyright (C) 2015-2018 The Software Heritage developers +# Copyright (C) 2015-2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License v3 or later # See top-level LICENSE file for more information +import os + from setuptools import setup, find_packages from os import path @@ -35,6 +37,12 @@ return requirements +# package generated static assets as module data files +data_files = [] +for root, _, files in os.walk('static/'): + root_files = [os.path.join(root, i) for i in files] + data_files.append((os.path.join('share/swh/web', root), root_files)) + setup( name='swh.web', description='Software Heritage Web UI', @@ -63,4 +71,5 @@ 'Funding': 'https://www.softwareheritage.org/donate', 'Source': 'https://forge.softwareheritage.org/source/swh-web', }, + data_files=data_files ) diff --git a/swh/web/static/img/arrow-up-small.png b/static/img/arrow-up-small.png rename from swh/web/static/img/arrow-up-small.png rename to static/img/arrow-up-small.png diff --git a/swh/web/static/img/icons/swh-logo-32x32.png b/static/img/icons/swh-logo-32x32.png rename from swh/web/static/img/icons/swh-logo-32x32.png rename to static/img/icons/swh-logo-32x32.png diff --git a/swh/web/static/img/icons/swh-logo-archive-180x180.png b/static/img/icons/swh-logo-archive-180x180.png rename from swh/web/static/img/icons/swh-logo-archive-180x180.png rename to static/img/icons/swh-logo-archive-180x180.png diff --git a/swh/web/static/img/icons/swh-logo-archive-192x192.png b/static/img/icons/swh-logo-archive-192x192.png rename from swh/web/static/img/icons/swh-logo-archive-192x192.png rename to static/img/icons/swh-logo-archive-192x192.png diff --git a/swh/web/static/img/icons/swh-logo-archive-270x270.png b/static/img/icons/swh-logo-archive-270x270.png rename from swh/web/static/img/icons/swh-logo-archive-270x270.png rename to static/img/icons/swh-logo-archive-270x270.png diff --git a/swh/web/static/img/logos/bitbucket.png b/static/img/logos/bitbucket.png rename from swh/web/static/img/logos/bitbucket.png rename to static/img/logos/bitbucket.png diff --git a/swh/web/static/img/logos/debian.png b/static/img/logos/debian.png rename from swh/web/static/img/logos/debian.png rename to static/img/logos/debian.png diff --git a/swh/web/static/img/logos/framagit.png b/static/img/logos/framagit.png rename from swh/web/static/img/logos/framagit.png rename to static/img/logos/framagit.png diff --git a/swh/web/static/img/logos/github.png b/static/img/logos/github.png rename from swh/web/static/img/logos/github.png rename to static/img/logos/github.png diff --git a/swh/web/static/img/logos/gitlab.svg b/static/img/logos/gitlab.svg rename from swh/web/static/img/logos/gitlab.svg rename to static/img/logos/gitlab.svg diff --git a/swh/web/static/img/logos/gitorious.png b/static/img/logos/gitorious.png rename from swh/web/static/img/logos/gitorious.png rename to static/img/logos/gitorious.png diff --git a/swh/web/static/img/logos/gnu.png b/static/img/logos/gnu.png rename from swh/web/static/img/logos/gnu.png rename to static/img/logos/gnu.png diff --git a/swh/web/static/img/logos/googlecode.png b/static/img/logos/googlecode.png rename from swh/web/static/img/logos/googlecode.png rename to static/img/logos/googlecode.png diff --git a/swh/web/static/img/logos/hal.png b/static/img/logos/hal.png rename from swh/web/static/img/logos/hal.png rename to static/img/logos/hal.png diff --git a/swh/web/static/img/logos/inria.jpg b/static/img/logos/inria.jpg rename from swh/web/static/img/logos/inria.jpg rename to static/img/logos/inria.jpg diff --git a/swh/web/static/img/logos/npm.png b/static/img/logos/npm.png rename from swh/web/static/img/logos/npm.png rename to static/img/logos/npm.png diff --git a/swh/web/static/img/logos/pypi.svg b/static/img/logos/pypi.svg rename from swh/web/static/img/logos/pypi.svg rename to static/img/logos/pypi.svg diff --git a/swh/web/static/img/swh-api.png b/static/img/swh-api.png rename from swh/web/static/img/swh-api.png rename to static/img/swh-api.png diff --git a/swh/web/static/img/swh-browse.png b/static/img/swh-browse.png rename from swh/web/static/img/swh-browse.png rename to static/img/swh-browse.png diff --git a/swh/web/static/img/swh-logo-white.svg b/static/img/swh-logo-white.svg rename from swh/web/static/img/swh-logo-white.svg rename to static/img/swh-logo-white.svg diff --git a/swh/web/static/img/swh-logo.png b/static/img/swh-logo.png rename from swh/web/static/img/swh-logo.png rename to static/img/swh-logo.png diff --git a/swh/web/static/img/swh-logo.svg b/static/img/swh-logo.svg rename from swh/web/static/img/swh-logo.svg rename to static/img/swh-logo.svg diff --git a/swh/web/static/img/swh-spinner-small.gif b/static/img/swh-spinner-small.gif rename from swh/web/static/img/swh-spinner-small.gif rename to static/img/swh-spinner-small.gif diff --git a/swh/web/static/img/swh-spinner.gif b/static/img/swh-spinner.gif rename from swh/web/static/img/swh-spinner.gif rename to static/img/swh-spinner.gif diff --git a/swh/web/static/img/swh-support.png b/static/img/swh-support.png rename from swh/web/static/img/swh-support.png rename to static/img/swh-support.png diff --git a/swh/web/static/img/swh-vault.png b/static/img/swh-vault.png rename from swh/web/static/img/swh-vault.png rename to static/img/swh-vault.png diff --git a/swh/web/static/xml/swh-opensearch.xml b/static/xml/swh-opensearch.xml rename from swh/web/static/xml/swh-opensearch.xml rename to static/xml/swh-opensearch.xml diff --git a/swh/web/assets/config/webpack.config.development.js b/swh/web/assets/config/webpack.config.development.js --- a/swh/web/assets/config/webpack.config.development.js +++ b/swh/web/assets/config/webpack.config.development.js @@ -118,7 +118,7 @@ entry: bundles, // assets output configuration output: { - path: path.resolve('./swh/web/static/'), + path: path.resolve('./static/'), filename: 'js/[name].[chunkhash].js', chunkFilename: 'js/[name].[chunkhash].js', publicPath: publicPath, @@ -332,7 +332,7 @@ }), // needed in order to use django_webpack_loader new BundleTracker({ - filename: './swh/web/static/webpack-stats.json' + filename: './static/webpack-stats.json' }), // for generating the robots.txt file new RobotstxtPlugin({ @@ -371,7 +371,7 @@ new webpack.IgnorePlugin(/^\.\/pdf.worker.js$/), new CopyWebpackPlugin([{ from: path.resolve(nodeModules, 'pdfjs-dist/build/pdf.worker.min.js'), - to: path.resolve(__dirname, '../../static/js/') + to: path.resolve(__dirname, '../../../../static/js/') }]), new GenerateWebLabelsPlugin({ outputType: 'json', diff --git a/swh/web/settings/common.py b/swh/web/settings/common.py --- a/swh/web/settings/common.py +++ b/swh/web/settings/common.py @@ -9,6 +9,7 @@ """ import os +import sys from swh.web.config import get_config @@ -132,9 +133,12 @@ # https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_URL = '/static/' -STATICFILES_DIRS = [ - os.path.join(PROJECT_DIR, "../static") -] +# static folder location when swh-web has been installed with pip +STATIC_DIR = os.path.join(sys.prefix, 'share/swh/web/static') +if not os.path.exists(STATIC_DIR): + # static folder location when developping swh-web + STATIC_DIR = os.path.join(PROJECT_DIR, '../../../static') +STATICFILES_DIRS = [STATIC_DIR] INTERNAL_IPS = ['127.0.0.1'] @@ -252,14 +256,14 @@ }, } -WEBPACK_LOADER = { # noqa +WEBPACK_LOADER = { 'DEFAULT': { 'CACHE': False, 'BUNDLE_DIR_NAME': './', - 'STATS_FILE': os.path.join(PROJECT_DIR, '../static/webpack-stats.json'), # noqa + 'STATS_FILE': os.path.join(STATIC_DIR, 'webpack-stats.json'), 'POLL_INTERVAL': 0.1, 'TIMEOUT': None, - 'IGNORE': ['.+\.hot-update.js', '.+\.map'] + 'IGNORE': ['.+\\.hot-update.js', '.+\\.map'] } } diff --git a/swh/web/tests/conftest.py b/swh/web/tests/conftest.py --- a/swh/web/tests/conftest.py +++ b/swh/web/tests/conftest.py @@ -7,6 +7,7 @@ import json import os import shutil +import sys from subprocess import run, PIPE @@ -54,7 +55,12 @@ # So generate a dummy webpack-stats.json file to overcome # that issue. test_dir = os.path.dirname(__file__) - static_dir = os.path.join(test_dir, '../static') + # location of the static folder when running tests through tox + static_dir = os.path.join(sys.prefix, 'share/swh/web/static') + + if not os.path.exists(static_dir): + # location of the static folder when running tests locally with pytest + static_dir = os.path.join(test_dir, '../../../static') webpack_stats = os.path.join(static_dir, 'webpack-stats.json') if os.path.exists(webpack_stats): return