diff --git a/debian/control b/debian/control index d11e709..8e86cad 100644 --- a/debian/control +++ b/debian/control @@ -12,7 +12,7 @@ Build-Depends: debhelper-compat (= 12), python3-pil, python3-setuptools, sassc, - zlib1g-dev + zlib1g-dev, Standards-Version: 3.9.1 Package: python3-gadjo diff --git a/gadjo/finders.py b/gadjo/finders.py index 4c2dee8..3caf558 100644 --- a/gadjo/finders.py +++ b/gadjo/finders.py @@ -11,6 +11,7 @@ from django.contrib.staticfiles import utils from django.contrib.staticfiles.finders import BaseFinder from django.core.exceptions import ImproperlyConfigured from django.core.files.storage import FileSystemStorage + try: from importlib import import_module except ImportError: @@ -22,6 +23,7 @@ class XStaticStorage(FileSystemStorage): A file system storage backend that takes an xstatic package module and works for the data contained in it. """ + prefix = 'xstatic' def __init__(self, package, *args, **kwargs): @@ -33,7 +35,7 @@ class XStaticStorage(FileSystemStorage): except ImportError: raise ImproperlyConfigured('Cannot import module "%s"' % package) location = package.BASE_DIR - super(XStaticStorage, self).__init__(location, *args, **kwargs) + super().__init__(location, *args, **kwargs) class XStaticFinder(BaseFinder): @@ -58,12 +60,12 @@ class XStaticFinder(BaseFinder): self.storages[app] = app_storage if app not in self.apps: self.apps.append(app) - super(XStaticFinder, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def find(self, path, all=False): """Look for files in the registered xstatic.* packages""" if path.startswith(self.storage_class.prefix + '/'): - path = path[len(self.storage_class.prefix)+1:] + path = path[len(self.storage_class.prefix) + 1 :] matches = [] for app, storage in self.storages.items(): if storage.exists(path): diff --git a/gadjo/templatetags/gadjo.py b/gadjo/templatetags/gadjo.py index 1f2106c..e75ada9 100644 --- a/gadjo/templatetags/gadjo.py +++ b/gadjo/templatetags/gadjo.py @@ -1,8 +1,6 @@ -from collections import OrderedDict import re import time - -from xstatic.main import XStatic +from collections import OrderedDict from django import template from django.conf import settings @@ -10,9 +8,11 @@ from django.core.exceptions import ImproperlyConfigured from django.forms import BoundField from django.utils.html import escape from django.utils.http import urlencode +from xstatic.main import XStatic register = template.Library() + @register.simple_tag def xstatic(modname, filename): if settings.DEBUG: @@ -22,6 +22,7 @@ def xstatic(modname, filename): START_TIMESTAMP = time.strftime('%Y%m%d.%H%M') + @register.simple_tag def start_timestamp(): return START_TIMESTAMP @@ -30,6 +31,7 @@ def start_timestamp(): # {% querystring %} bits originally from django-tables2. kwarg_re = re.compile(r"(?:(.+)=)?(.+)") + def token_kwargs(bits, parser): """ Based on Django's `~django.template.defaulttags.token_kwargs`, but with a @@ -50,9 +52,10 @@ def token_kwargs(bits, parser): kwargs[parser.compile_filter(key)] = parser.compile_filter(value) return kwargs + class QuerystringNode(template.Node): def __init__(self, updates, removals): - super(QuerystringNode, self).__init__() + super().__init__() self.updates = updates self.removals = removals @@ -69,6 +72,7 @@ class QuerystringNode(template.Node): params.pop(removal.resolve(context), None) return escape("?" + urlencode(params, doseq=True)) + @register.tag def querystring(parser, token): """ @@ -103,7 +107,7 @@ def with_template(form): widget = field.field.widget templates = ['gadjo/widget.html'] if hasattr(widget, 'input_type'): - templates.insert(0, 'gadjo/%s-widget.html' % widget.input_type) + templates.insert(0, 'gadjo/%s-widget.html' % widget.input_type) fields_with_templates.append( ( field, diff --git a/inkscape_wrapper.py b/inkscape_wrapper.py index b3ecf4e..ee326c0 100755 --- a/inkscape_wrapper.py +++ b/inkscape_wrapper.py @@ -10,6 +10,8 @@ args = sys.argv[1:] if b'Inkscape 0' not in inkscape_version: # --export-png replaced by --export-filename # --without-gui and --file removed - args = [x.replace('--export-png', '--export-filename') for x in args if x not in ('--without-gui', '--file')] + args = [ + x.replace('--export-png', '--export-filename') for x in args if x not in ('--without-gui', '--file') + ] sys.exit(subprocess.call(['inkscape'] + args)) diff --git a/setup.py b/setup.py index 2c919e2..8b771b7 100644 --- a/setup.py +++ b/setup.py @@ -1,26 +1,25 @@ #! /usr/bin/env python -# -*- coding: utf-8 -*- -import os import glob +import os import re -import sys import subprocess +import sys import tempfile import xml.etree.ElementTree as ET - from distutils.cmd import Command -from distutils.errors import CompileError -from distutils.spawn import find_executable -from setuptools.command.install_lib import install_lib as _install_lib from distutils.command.build import build as _build from distutils.command.sdist import sdist -from setuptools import setup, find_packages +from distutils.errors import CompileError +from distutils.spawn import find_executable + +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__), 'inkscape_wrapper.py')) -class eo_sdist(sdist): +class eo_sdist(sdist): def run(self): print("creating VERSION file") if os.path.exists('VERSION'): @@ -34,29 +33,31 @@ class eo_sdist(sdist): 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. + tag exists, take 0.0- and add the length of the commit log. ''' if os.path.exists('VERSION'): - with open('VERSION', 'r') as v: + 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) + 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 + 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 return version else: - return '0.0.post%s' % len( - subprocess.check_output( - ['git', 'rev-list', 'HEAD']).splitlines()) + return '0.0.post%s' % len(subprocess.check_output(['git', 'rev-list', 'HEAD']).splitlines()) return '0.0' @@ -74,6 +75,7 @@ class compile_translations(Command): curdir = os.getcwd() try: from django.core.management import call_command + for path, dirs, files in os.walk('gadjo'): if 'locale' not in dirs: continue @@ -103,7 +105,9 @@ class compile_scss(Command): if sass_bin: break if not sass_bin: - raise CompileError('A sass compiler is required but none was found. See sass-lang.com for choices.') + raise CompileError( + 'A sass compiler is required but none was found. See sass-lang.com for choices.' + ) for package in self.distribution.packages: for package_path in __import__(package).__path__: @@ -113,10 +117,14 @@ class compile_scss(Command): continue if filename.startswith('_'): continue - subprocess.check_call([sass_bin, '%s/%s' % (path, filename), - '%s/%s' % (path, filename.replace('.scss', '.css'))], - env={'LC_ALL': 'C.UTF-8'} - ) + subprocess.check_call( + [ + sass_bin, + '%s/%s' % (path, filename), + '%s/%s' % (path, filename.replace('.scss', '.css')), + ], + env={'LC_ALL': 'C.UTF-8'}, + ) class build_icons(Command): @@ -157,15 +165,14 @@ class build_icons(Command): for variant in variants: dest_filename = '%s.%s.png' % (basename, variant) destname = os.path.join(destpath, dest_filename) - self.generate(os.path.join(basepath, filename), destname, - **variants.get(variant)) + self.generate(os.path.join(basepath, filename), destname, **variants.get(variant)) def generate(self, src, dest, colour, width, **kwargs): if os.path.exists(dest) and os.stat(dest).st_mtime >= os.stat(src).st_mtime: return # default values - from PIL import Image - from PIL import PngImagePlugin + from PIL import Image, PngImagePlugin + license = 'Creative Commons Attribution-Share Alike 3.0' if 'old-set' in src: author = 'GNOME Project' @@ -183,12 +190,20 @@ class build_icons(Command): f.write(ET.tostring(tree)) f.close() - subprocess.call([inkscape, '--without-gui', - '--file', f.name, - '--export-area-drawing', - '--export-area-snap', - '--export-png', dest, - '--export-width', width]) + subprocess.call( + [ + inkscape, + '--without-gui', + '--file', + f.name, + '--export-area-drawing', + '--export-area-snap', + '--export-png', + dest, + '--export-width', + width, + ] + ) # write down licensing info in the png file meta = PngImagePlugin.PngInfo() @@ -198,9 +213,11 @@ class build_icons(Command): class build(_build): - sub_commands = [('compile_translations', None), - ('compile_scss', None), - ('build_icons', None)] + _build.sub_commands + sub_commands = [ + ('compile_translations', None), + ('compile_scss', None), + ('build_icons', None), + ] + _build.sub_commands class install_lib(_install_lib): @@ -208,6 +225,7 @@ class install_lib(_install_lib): self.run_command('compile_translations') _install_lib.run(self) + setup( name='gadjo', version=get_version(), @@ -224,7 +242,7 @@ setup( 'XStatic_jQuery', 'XStatic_jquery_ui', 'XStatic_OpenSans', - ], + ], setup_requires=[ 'Pillow', ], @@ -245,6 +263,6 @@ setup( 'compile_scss': compile_scss, 'compile_translations': compile_translations, 'install_lib': install_lib, - 'sdist': eo_sdist + 'sdist': eo_sdist, }, )