build: switch from Makefile to setuptools (#71292)
This commit is contained in:
parent
cb6d7d5621
commit
778006540b
|
@ -0,0 +1,22 @@
|
|||
# static
|
||||
recursive-include static *.scss *.css *.js *.ico *.gif *.svg *.png *.jpg *.jpeg *.woff *.woff2 *.ttf *.map *.json *.eot *.otf
|
||||
|
||||
# templates
|
||||
recursive-include templates *.html *.txt
|
||||
|
||||
# documentation
|
||||
recursive-include help *.page *.png
|
||||
|
||||
# scripts & pictos
|
||||
recursive-include src *.py *.svg
|
||||
|
||||
# locales
|
||||
recursive-include publik_base_theme/locale *.po *.mo
|
||||
|
||||
include MANIFEST.in
|
||||
include COPYING
|
||||
include VERSION
|
||||
include inkscape_wrapper.py
|
||||
include themes.json
|
||||
include create_themes_json.py
|
||||
include make_data_uris.py
|
96
Makefile
96
Makefile
|
@ -1,96 +0,0 @@
|
|||
VERSION=`git describe | sed 's/^v//; s/-/./g' `
|
||||
NAME="publik-base-theme"
|
||||
INKSCAPE=$(shell pwd)/src/inkscape_wrapper.py
|
||||
|
||||
prefix = /usr
|
||||
|
||||
all: themes.json icons css
|
||||
|
||||
static/includes/_data_uris.scss: $(wildcard static/includes/img/*)
|
||||
python3 make_data_uris.py static/includes/
|
||||
|
||||
static/toodego/_data_uris.scss: $(wildcard static/toodego/img/*)
|
||||
python3 make_data_uris.py static/toodego/
|
||||
|
||||
static/lille/_data_uris.scss: $(wildcard static/lille/img/*)
|
||||
python3 make_data_uris.py static/lille/
|
||||
|
||||
static/lomme/_data_uris.scss: $(wildcard static/lomme/img/*)
|
||||
python3 make_data_uris.py static/lomme/
|
||||
|
||||
static/hellemmes/_data_uris.scss: $(wildcard static/hellemmes/img/*)
|
||||
python3 make_data_uris.py static/hellemmes/
|
||||
|
||||
static/toulouse-2022/_data_uris.scss: $(wildcard static/toulouse-2022/img/*)
|
||||
python3 make_data_uris.py static/toulouse-2022/
|
||||
|
||||
themes.json: $(wildcard static/*/config.json) help/fr/misc-scss.page
|
||||
python3 create_themes_json.py
|
||||
|
||||
%.css: export LC_ALL=C.UTF-8
|
||||
.SECONDEXPANSION:
|
||||
%.css: %.scss $(wildcard static/includes/*.scss static/includes/*/*.scss) static/includes/_data_uris.scss static/lille/_data_uris.scss static/lomme/_data_uris.scss static/hellemmes/_data_uris.scss static/toodego/_data_uris.scss static/toulouse-2022/_data_uris.scss $$(wildcard $$(@D)/*.scss)
|
||||
sassc --sourcemap $< $@
|
||||
|
||||
css: $(shell python3 get_themes.py) static/portal-agent/css/agent-portal.css static/includes/gadjo-extra.css
|
||||
rm -rf static/*/.sass-cache/
|
||||
|
||||
icons:
|
||||
# chateauroux
|
||||
cd src/ && python3 render-imgs-dashboard.py ../static/chateauroux/img/ --normal 333333 --selected 0779B7 --title FFFFFF --title-width 80
|
||||
# orleans
|
||||
cd src/ && python3 render-imgs-categories.py ../static/orleans/img/ --primary f05923 --secondary 34697D
|
||||
cd src/ && python3 render-imgs-dashboard.py ../static/orleans/img/ --normal FFFFFF --normal-width 30 --selected f05923 --selected-width 30 --title FFFFFF --title-width 80
|
||||
# publik
|
||||
cd src/ && python3 render-imgs-categories.py ../static/publik/img/
|
||||
cd src/ && python3 render-imgs-dashboard.py ../static/publik/img/ --normal 4D4D4D --selected DF017A --title FFFFFF --title-width 80
|
||||
# somme
|
||||
cd src/ && python3 render-imgs-categories.py ../static/somme-cd80/img/ --primary A8002B --secondary A8002B
|
||||
cd src/ && python3 render-imgs-dashboard.py ../static/somme-cd80/img/ --normal 4D4D4D --selected 87A738 --title FFFFFF --title-width 80
|
||||
# tournai
|
||||
cd static/tournai/ && for F in assets/*.svg; do $(INKSCAPE) --without-gui --file $$F --export-area-drawing --export-area-snap --export-png img/$$(basename $$F .svg).png --export-width 40; done
|
||||
|
||||
clean:
|
||||
rm -rf sdist
|
||||
rm -f src/tmp-*.svg
|
||||
rm -f static/*/_data_uris.scss
|
||||
-rm $$(python3 get_themes.py --include-map-files)
|
||||
-rm static/portal-agent/css/agent-portal.css static/portal-agent/css/agent-portal.css.map static/includes/gadjo-extra.css static/includes/gadjo-extra.css.map
|
||||
|
||||
DIST_FILES = \
|
||||
Makefile \
|
||||
desc.xml \
|
||||
create_themes_json.py \
|
||||
get_themes.py \
|
||||
make_data_uris.py \
|
||||
static templates \
|
||||
src \
|
||||
help
|
||||
|
||||
dist: clean
|
||||
-mkdir sdist
|
||||
rm -rf sdist/$(NAME)-$(VERSION)
|
||||
mkdir -p sdist/$(NAME)-$(VERSION)
|
||||
for i in $(DIST_FILES); do \
|
||||
cp -R "$$i" sdist/$(NAME)-$(VERSION); \
|
||||
done
|
||||
|
||||
install:
|
||||
mkdir -p $(DESTDIR)$(prefix)/share/publik/themes/publik-base
|
||||
cp -r static templates themes.json desc.xml $(DESTDIR)$(prefix)/share/publik/themes/publik-base
|
||||
rm $(DESTDIR)$(prefix)/share/publik/themes/publik-base/static/*/config.json
|
||||
mkdir -p $(DESTDIR)$(prefix)/share/wcs/themes/
|
||||
ln -s $(prefix)/share/publik/themes/publik-base $(DESTDIR)$(prefix)/share/wcs/themes/publik-base
|
||||
|
||||
dist-bzip2: dist
|
||||
-mkdir sdist
|
||||
cd sdist && tar cfj ../sdist/$(NAME)-$(VERSION).tar.bz2 $(NAME)-$(VERSION)
|
||||
|
||||
version:
|
||||
@(echo $(VERSION))
|
||||
|
||||
name:
|
||||
@(echo $(NAME))
|
||||
|
||||
fullname:
|
||||
@(echo $(NAME)-$(VERSION))
|
|
@ -0,0 +1,274 @@
|
|||
#! /usr/bin/env python
|
||||
|
||||
import glob
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from distutils.cmd import Command as BaseCommand
|
||||
from distutils.command.build import build as _build
|
||||
from distutils.command.sdist import sdist
|
||||
from distutils.errors import CompileError
|
||||
from distutils.spawn import find_executable
|
||||
from multiprocessing import Pool
|
||||
|
||||
from setuptools import find_packages, setup
|
||||
from setuptools.command.install_lib import install_lib as _install_lib
|
||||
|
||||
inkscape = os.path.abspath(os.path.join(os.path.dirname(__file__), 'src', 'inkscape_wrapper.py'))
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
user_options = []
|
||||
|
||||
def initialize_options(self):
|
||||
pass
|
||||
|
||||
def finalize_options(self):
|
||||
pass
|
||||
|
||||
|
||||
class eo_sdist(sdist):
|
||||
def run(self):
|
||||
print('creating VERSION file')
|
||||
if os.path.exists('VERSION'):
|
||||
os.remove('VERSION')
|
||||
version = get_version()
|
||||
version_file = open('VERSION', 'w')
|
||||
version_file.write(version)
|
||||
version_file.close()
|
||||
sdist.run(self)
|
||||
print('removing VERSION file')
|
||||
if os.path.exists('VERSION'):
|
||||
os.remove('VERSION')
|
||||
|
||||
|
||||
def get_version():
|
||||
'''Use the VERSION, if absent generates a version with git describe, if not
|
||||
tag exists, take 0.0- and add the length of the commit log.
|
||||
'''
|
||||
if os.path.exists('VERSION'):
|
||||
with open('VERSION') as v:
|
||||
return v.read()
|
||||
if os.path.exists('.git'):
|
||||
p = subprocess.Popen(
|
||||
['git', 'describe', '--dirty=.dirty', '--match=v*'],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
result = p.communicate()[0]
|
||||
if p.returncode == 0:
|
||||
result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v
|
||||
if '-' in result: # not a tagged version
|
||||
real_number, commit_count, commit_hash = result.split('-', 2)
|
||||
version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
|
||||
else:
|
||||
version = result.replace('.dirty', '+dirty')
|
||||
return version
|
||||
else:
|
||||
return '0.0.post%s' % len(subprocess.check_output(['git', 'rev-list', 'HEAD']).splitlines())
|
||||
return '0.0'
|
||||
|
||||
|
||||
class compile_translations(Command):
|
||||
description = 'compile message catalogs to MO files via django compilemessages'
|
||||
user_options = []
|
||||
|
||||
def run(self):
|
||||
curdir = os.getcwd()
|
||||
try:
|
||||
from django.core.management import call_command
|
||||
|
||||
for path, dirs, files in os.walk('publik_base_theme'):
|
||||
if 'locale' not in dirs:
|
||||
continue
|
||||
os.chdir(os.path.realpath(path))
|
||||
call_command('compilemessages')
|
||||
os.chdir(curdir)
|
||||
except ImportError:
|
||||
sys.stderr.write('!!! Please install Django >= 1.4 to build translations\n')
|
||||
finally:
|
||||
os.chdir(curdir)
|
||||
|
||||
|
||||
class build_themes_json(Command):
|
||||
def run(self):
|
||||
subprocess.run(['python3', 'create_themes_json.py'])
|
||||
|
||||
|
||||
def get_css_files(include_map_files=False):
|
||||
for dirname in sorted(os.listdir('static')):
|
||||
config = os.path.join('static', dirname, 'config.json')
|
||||
if not os.path.exists(config):
|
||||
continue
|
||||
yield 'static/%s/style.css' % dirname
|
||||
if include_map_files:
|
||||
yield 'static/%s/style.css.map' % dirname
|
||||
if os.path.exists(os.path.join('static', dirname, 'backoffice.scss')):
|
||||
yield 'static/%s/backoffice.css' % dirname
|
||||
if include_map_files:
|
||||
yield 'static/%s/backoffice.css.map' % dirname
|
||||
yield 'static/portal-agent/css/agent-portal.css'
|
||||
yield 'static/includes/gadjo-extra.css'
|
||||
|
||||
|
||||
def subprocess_run(command):
|
||||
kwargs = {
|
||||
'env': {'LC_ALL': 'C.UTF-8'},
|
||||
}
|
||||
if isinstance(command, list):
|
||||
print(' '.join(command))
|
||||
else:
|
||||
print(command)
|
||||
kwargs['shell'] = True
|
||||
return bool(subprocess.run(command, **kwargs).returncode == 0)
|
||||
|
||||
|
||||
class compile_scss(Command):
|
||||
description = 'compile scss files into css files'
|
||||
|
||||
def run(self):
|
||||
sass_bin = find_executable('sassc')
|
||||
if not sass_bin:
|
||||
raise CompileError(
|
||||
'A sass compiler is required but none was found. See sass-lang.com for choices.'
|
||||
)
|
||||
|
||||
for dirname in ('includes', 'toodego', 'lille', 'lomme', 'hellemmes', 'toulouse-2022'):
|
||||
subprocess.run(['python3', 'make_data_uris.py', os.path.join('static', dirname)], check=True)
|
||||
|
||||
def get_build_commands():
|
||||
for css_filename in get_css_files():
|
||||
yield ['sassc', '--sourcemap', css_filename.replace('.css', '.scss'), css_filename]
|
||||
|
||||
with Pool() as pool:
|
||||
for result in pool.imap_unordered(subprocess_run, get_build_commands()):
|
||||
if not result:
|
||||
raise CompileError('error compiling css')
|
||||
|
||||
|
||||
class build_icons(Command):
|
||||
def run(self):
|
||||
cmds = [
|
||||
'python3 src/render-imgs-dashboard.py static/chateauroux/img/ --normal 333333 '
|
||||
'--selected 0779B7 --title FFFFFF --title-width 80',
|
||||
'python3 src/render-imgs-categories.py static/orleans/img/ --primary f05923 --secondary 34697D',
|
||||
'python3 src/render-imgs-dashboard.py static/orleans/img/ --normal FFFFFF '
|
||||
'--normal-width 30 --selected f05923 --selected-width 30 --title FFFFFF --title-width 80',
|
||||
'python3 src/render-imgs-categories.py static/publik/img/',
|
||||
'python3 src/render-imgs-dashboard.py static/publik/img/ --normal 4D4D4D '
|
||||
'--selected DF017A --title FFFFFF --title-width 80',
|
||||
'python3 src/render-imgs-categories.py static/somme-cd80/img/ --primary A8002B '
|
||||
'--secondary A8002B',
|
||||
'python3 src/render-imgs-dashboard.py static/somme-cd80/img/ --normal 4D4D4D '
|
||||
'--selected 87A738 --title FFFFFF --title-width 80',
|
||||
]
|
||||
if not os.path.exists('static/tournai/img'):
|
||||
os.mkdir('static/tournai/img')
|
||||
for image in glob.glob('static/tournai/assets/*.svg'):
|
||||
target_filename = 'static/tournai/img/' + os.path.basename(image).replace('.svg', '.png')
|
||||
if (
|
||||
os.path.exists(target_filename)
|
||||
and os.stat(image).st_mtime < os.stat(target_filename).st_mtime
|
||||
):
|
||||
continue
|
||||
cmds.append(
|
||||
[
|
||||
inkscape,
|
||||
'--without-gui',
|
||||
'--file',
|
||||
image,
|
||||
'--export-area-drawing',
|
||||
'--export-area-snap',
|
||||
'--export-png',
|
||||
target_filename,
|
||||
'--export-width',
|
||||
'40',
|
||||
]
|
||||
)
|
||||
|
||||
with Pool() as pool:
|
||||
for result in pool.imap_unordered(subprocess_run, cmds):
|
||||
if not result:
|
||||
raise CompileError('error building icons')
|
||||
|
||||
|
||||
class build(_build):
|
||||
sub_commands = [
|
||||
('build_themes_json', None),
|
||||
('build_icons', None),
|
||||
('compile_scss', None),
|
||||
('compile_translations', None),
|
||||
] + _build.sub_commands
|
||||
|
||||
|
||||
class install_lib(_install_lib):
|
||||
def run(self):
|
||||
self.run_command('compile_translations')
|
||||
super().run()
|
||||
|
||||
|
||||
def data_tree(destdir, sourcedir):
|
||||
extensions = [
|
||||
'.html',
|
||||
'.txt',
|
||||
'.scss',
|
||||
'.css',
|
||||
'.js',
|
||||
'.ico',
|
||||
'.gif',
|
||||
'.png',
|
||||
'.jpg',
|
||||
'.jpeg',
|
||||
'.woff',
|
||||
'.woff2',
|
||||
'.ttf',
|
||||
'.css',
|
||||
'.map',
|
||||
'.svg',
|
||||
'.eot',
|
||||
'.otf',
|
||||
]
|
||||
r = []
|
||||
for root, dirs, files in os.walk(sourcedir):
|
||||
l = [os.path.join(root, x) for x in files if os.path.splitext(x)[1] in extensions]
|
||||
r.append((root.replace(sourcedir, destdir, 1), l))
|
||||
return r
|
||||
|
||||
|
||||
setup(
|
||||
name='publik_base_theme',
|
||||
version=get_version(),
|
||||
license='AGPLv3 or later',
|
||||
description='Themes for Publik',
|
||||
url='https://dev.entrouvert.org/projects/publik-base-theme/',
|
||||
author='Entr’ouvert',
|
||||
author_email='info@entrouvert.com',
|
||||
packages=find_packages(),
|
||||
include_package_data=True,
|
||||
data_files=data_tree('share/publik/themes/publik-base/static', 'static')
|
||||
+ data_tree('share/publik/themes/publik-base/templates', 'templates')
|
||||
+ [('share/publik/themes/publik-base', ['themes.json'])],
|
||||
setup_requires=[
|
||||
'django>=2.2',
|
||||
],
|
||||
classifiers=[
|
||||
'Development Status :: 5 - Stable',
|
||||
'Environment :: Web Environment',
|
||||
'Framework :: Django',
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
|
||||
'Operating System :: OS Independent',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 3',
|
||||
],
|
||||
zip_safe=False,
|
||||
cmdclass={
|
||||
'build': build,
|
||||
'build_icons': build_icons,
|
||||
'build_themes_json': build_themes_json,
|
||||
'compile_scss': compile_scss,
|
||||
'compile_translations': compile_translations,
|
||||
'install_lib': install_lib,
|
||||
'sdist': eo_sdist,
|
||||
},
|
||||
)
|
Loading…
Reference in New Issue