From 3f0b5cac29167bc135438ed978f6d03f43674ec4 Mon Sep 17 00:00:00 2001 From: Jack Venberg Date: Thu, 22 Feb 2024 19:56:44 +0000 Subject: [PATCH 01/21] [DEV-103519] Switch from travis to GHA --- .github/workflows/lint-and-test.yml | 31 +++++++++++++++++++++++++++++ .travis.yml | 14 ------------- 2 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/lint-and-test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml new file mode 100644 index 0000000..e99967e --- /dev/null +++ b/.github/workflows/lint-and-test.yml @@ -0,0 +1,31 @@ +name: Run Tests and Linter + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: [2.7, 3.4, 3.5, 3.6] + django-version: [1.11] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + pip install -q Django==${{ matrix.django-version }} + pip install -e .[flake8,tests] + + - name: Lint with flake8 + run: flake8 + + - name: Test with pytest + run: pytest diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d7e53f1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: python -python: - - 2.7 - - 3.4 - - 3.5 - - 3.6 -env: - - DJANGO_VERSION=1.11 -install: - - pip install -q Django==$DJANGO_VERSION - - pip install -e .[flake8,tests] -script: - - flake8 - - pytest From b76d42b23a1f1fdeb8f1c627a54ec2e81d7c3990 Mon Sep 17 00:00:00 2001 From: Jack Venberg Date: Thu, 22 Feb 2024 20:04:06 +0000 Subject: [PATCH 02/21] [DEV-103519] Update versions --- .github/workflows/lint-and-test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index e99967e..14aa441 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -8,8 +8,9 @@ jobs: strategy: fail-fast: false matrix: - python-version: [2.7, 3.4, 3.5, 3.6] - django-version: [1.11] + python-version: + [3.4.10, 3.5.10, 3.6.15, 3.7.17, 3.8.18, 3.9.18, 3.10.13, 3.11.8] + django-version: [3.2, 4.2, 5.0] steps: - uses: actions/checkout@v2 From 29bf9c7545db159a32cd0cc2f4c075737ec622a2 Mon Sep 17 00:00:00 2001 From: Jack Venberg Date: Thu, 22 Feb 2024 20:08:48 +0000 Subject: [PATCH 03/21] [DEV-103519] Try newer setup version --- .github/workflows/lint-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 14aa441..0b1c42f 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} From 19fbdb2dae5455b2c2f35100d0a9dd189f8e28cd Mon Sep 17 00:00:00 2001 From: Jack Venberg Date: Thu, 22 Feb 2024 20:11:03 +0000 Subject: [PATCH 04/21] [DEV-103519] Smaller version scope --- .github/workflows/lint-and-test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 0b1c42f..d76b748 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -8,9 +8,8 @@ jobs: strategy: fail-fast: false matrix: - python-version: - [3.4.10, 3.5.10, 3.6.15, 3.7.17, 3.8.18, 3.9.18, 3.10.13, 3.11.8] - django-version: [3.2, 4.2, 5.0] + python-version: [3.8.18, 3.9.18, 3.10.13, 3.11.8] + django-version: [3.2, 4.2] steps: - uses: actions/checkout@v2 From 26d3109e554bf31bbe658081001f64bad0b803bc Mon Sep 17 00:00:00 2001 From: Jack Venberg Date: Thu, 22 Feb 2024 20:19:26 +0000 Subject: [PATCH 05/21] [DEV-103519] Update setup versions --- setup.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index c1ff0c5..5a03556 100644 --- a/setup.py +++ b/setup.py @@ -21,12 +21,12 @@ URL = 'https://github.com/roverdotcom/django-inlinecss' EMAIL = 'philip@rover.com' AUTHOR = 'Philip Kimmey' -REQUIRES_PYTHON = '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.7' +REQUIRES_PYTHON = '>=3.8' VERSION = None # What packages are required for this module to be executed? REQUIRED = [ - 'Django>=1.11', + 'Django>=3.2', 'pynliner', 'future>=0.16.0', ] @@ -41,10 +41,10 @@ # What packages are optional? EXTRAS = { 'flake8': [ - 'flake8==3.6.0', - 'flake8-isort==2.6.0', - 'isort==4.3.4', - 'testfixtures==6.3.0', + 'flake8==7.0.0', + 'flake8-isort==6.1.1', + 'isort==5.13.2', + 'testfixtures==8.0.0', ], 'tests': TESTS, } From 2f6536ffac28efe16d6956dd27159d789b1bbb49 Mon Sep 17 00:00:00 2001 From: Jack Venberg Date: Thu, 22 Feb 2024 20:23:07 +0000 Subject: [PATCH 06/21] [DEV-103519] Update test dependencies --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 5a03556..f70bd3e 100644 --- a/setup.py +++ b/setup.py @@ -33,9 +33,9 @@ # What packages are required only for tests? TESTS = [ - 'mock==2.0.0', - 'pytest==4.3.1', - 'pytest-django==3.4.8', + 'mock==5.1.0', + 'pytest==8.0.1', + 'pytest-django==4.8.0', ] # What packages are optional? From 389a8c7117f05c1e4e8a6abc273294b744e8a2ff Mon Sep 17 00:00:00 2001 From: Jack Venberg Date: Thu, 22 Feb 2024 20:55:11 +0000 Subject: [PATCH 07/21] [DEV-103519] Try adding current directory to PTYHONPATH --- .github/workflows/lint-and-test.yml | 3 +++ setup.cfg | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index d76b748..23dd861 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -24,6 +24,9 @@ jobs: pip install -q Django==${{ matrix.django-version }} pip install -e .[flake8,tests] + - name: Add current directory to PYTHONPATH + run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV + - name: Lint with flake8 run: flake8 diff --git a/setup.cfg b/setup.cfg index 427ef4c..7edd6f8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,6 +16,6 @@ lines_after_imports=2 use_parentheses=True [tool:pytest] -django_find_project = false -DJANGO_SETTINGS_MODULE = test_settings -python_files = test_*.py +django_find_project=false +DJANGO_SETTINGS_MODULE=test_settings +python_files=test_*.py From ea1e59659ed46b0695c9a5cb08277673ff3b4e4d Mon Sep 17 00:00:00 2001 From: Jack Venberg Date: Thu, 22 Feb 2024 20:59:22 +0000 Subject: [PATCH 08/21] [DEV-103519] Add name --- .github/workflows/lint-and-test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 23dd861..b2327a2 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -3,7 +3,7 @@ name: Run Tests and Linter on: [push, pull_request] jobs: - build: + lint-and-test: runs-on: ubuntu-latest strategy: fail-fast: false @@ -11,6 +11,8 @@ jobs: python-version: [3.8.18, 3.9.18, 3.10.13, 3.11.8] django-version: [3.2, 4.2] + name: Lint and Test (Python ${{ matrix.python-version }} - Django ${{ matrix.django-version }}) + steps: - uses: actions/checkout@v2 From b05a184a1e853578cfffe35c9910d47c5dade255 Mon Sep 17 00:00:00 2001 From: Jack Venberg Date: Thu, 22 Feb 2024 21:02:55 +0000 Subject: [PATCH 09/21] [DEV-103519] Only run on pull requests --- .github/workflows/lint-and-test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index b2327a2..c9a9cb2 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -1,6 +1,10 @@ name: Run Tests and Linter -on: [push, pull_request] +on: + pull_request: + branches: + - master + - main jobs: lint-and-test: From 19d70e2619461dac838adf65c541a9eaeb710f21 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Tue, 2 Jun 2020 11:24:30 +0200 Subject: [PATCH 10/21] Stop using deprecated smart_text --- django_inlinecss/templatetags/inlinecss.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django_inlinecss/templatetags/inlinecss.py b/django_inlinecss/templatetags/inlinecss.py index c778ddf..82b9728 100644 --- a/django_inlinecss/templatetags/inlinecss.py +++ b/django_inlinecss/templatetags/inlinecss.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals from django import template -from django.utils.encoding import smart_text +from django.utils.encoding import smart_str from django_inlinecss import conf @@ -23,7 +23,7 @@ def render(self, context): for expression in self.filter_expressions: path = expression.resolve(context, True) if path is not None: - path = smart_text(path) + path = smart_str(path) css_loader = conf.get_css_loader()() css = ''.join((css, css_loader.load(path))) From 9e9702acac95c00b22833dae23447c878ea7c3e1 Mon Sep 17 00:00:00 2001 From: Facundo Maero Date: Tue, 2 Jun 2020 11:29:25 +0200 Subject: [PATCH 11/21] Update supported Python versions --- README.md | 6 +-- django_inlinecss/conf.py | 6 --- django_inlinecss/css_loaders.py | 9 +--- django_inlinecss/engines.py | 9 +--- django_inlinecss/templatetags/inlinecss.py | 5 --- django_inlinecss/tests/test_css_loaders.py | 9 +--- django_inlinecss/tests/test_templatetags.py | 13 ++---- setup.py | 48 +++++++-------------- test_settings.py | 5 --- 9 files changed, 28 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index 3a67942..dbf4e07 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/roverdotcom/django-inlinecss.png?branch=master)](https://travis-ci.org/roverdotcom/django-inlinecss) +[![Build Status](https://travis-ci.org/roverdotcom/django-inlinecss.svg?branch=master)](https://travis-ci.org/roverdotcom/django-inlinecss) ## About @@ -14,8 +14,8 @@ template language. - BeautifulSoup - cssutils -- Python 2.7+,3.4+ -- Django 1.11+ +- Python 3.8+ +- Django 3.2+ #### Step 2: Install django_inlinecss diff --git a/django_inlinecss/conf.py b/django_inlinecss/conf.py index dc0448e..eea6976 100644 --- a/django_inlinecss/conf.py +++ b/django_inlinecss/conf.py @@ -1,9 +1,3 @@ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals - - try: import importlib except ImportError: diff --git a/django_inlinecss/css_loaders.py b/django_inlinecss/css_loaders.py index 3021874..c3253bc 100644 --- a/django_inlinecss/css_loaders.py +++ b/django_inlinecss/css_loaders.py @@ -1,13 +1,8 @@ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals - from django.contrib.staticfiles import finders from django.contrib.staticfiles.storage import staticfiles_storage -class BaseCSSLoader(object): +class BaseCSSLoader: def __init__(self): pass @@ -28,7 +23,7 @@ def load(self, path): expanded_path = finders.find(path) if expanded_path is None: - raise IOError('{} does not exist'.format(path)) + raise OSError(f'{path} does not exist') with open(expanded_path, 'rb') as css_file: return css_file.read().decode('utf-8') diff --git a/django_inlinecss/engines.py b/django_inlinecss/engines.py index 55ab018..8de801d 100644 --- a/django_inlinecss/engines.py +++ b/django_inlinecss/engines.py @@ -1,14 +1,7 @@ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals - -from builtins import object - import pynliner -class EngineBase(object): +class EngineBase: def __init__(self, html, css): self.html = html self.css = css diff --git a/django_inlinecss/templatetags/inlinecss.py b/django_inlinecss/templatetags/inlinecss.py index 82b9728..70a4bde 100644 --- a/django_inlinecss/templatetags/inlinecss.py +++ b/django_inlinecss/templatetags/inlinecss.py @@ -1,8 +1,3 @@ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals - from django import template from django.utils.encoding import smart_str diff --git a/django_inlinecss/tests/test_css_loaders.py b/django_inlinecss/tests/test_css_loaders.py index f79a1c2..fe969c3 100644 --- a/django_inlinecss/tests/test_css_loaders.py +++ b/django_inlinecss/tests/test_css_loaders.py @@ -1,11 +1,6 @@ """ Test CSS loaders """ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals - from django.conf import settings from django.test import TestCase from django.test import override_settings @@ -18,7 +13,7 @@ class StaticfilesFinderCSSLoaderTestCase(TestCase): def setUp(self): self.loader = StaticfilesFinderCSSLoader() - super(StaticfilesFinderCSSLoaderTestCase, self).setUp() + super().setUp() def test_loads_existing_css_file(self): css = self.loader.load('bar.css') @@ -34,7 +29,7 @@ def test_load_file_does_not_exist(self): class StaticfilesStorageCSSLoaderTestCase(TestCase): def setUp(self): self.loader = StaticfilesStorageCSSLoader() - super(StaticfilesStorageCSSLoaderTestCase, self).setUp() + super().setUp() def test_loads_existing_css_file(self): css = self.loader.load('bar.css') diff --git a/django_inlinecss/tests/test_templatetags.py b/django_inlinecss/tests/test_templatetags.py index 06d6227..9430444 100644 --- a/django_inlinecss/tests/test_templatetags.py +++ b/django_inlinecss/tests/test_templatetags.py @@ -4,11 +4,6 @@ The actual CSS inlining displayed here is extremely simple: tests of the CSS selector functionality is independent. """ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals - import os from django.conf import settings @@ -16,12 +11,12 @@ from django.test import TestCase from django.test.utils import override_settings from django.utils.safestring import mark_safe -from mock import patch +from unittest.mock import patch class InlinecssTests(TestCase): def setUp(self): - super(InlinecssTests, self).setUp() + super().setUp() def assert_foo_and_bar_rendered(self, rendered): foo_div_regex = ( @@ -119,13 +114,13 @@ def test_unicode_context_variables(self): template = get_template('unicode_context_variables.html') rendered = template.render({ - 'unicode_string': u'I love playing with my pi\xf1ata'}) + 'unicode_string': 'I love playing with my pi\xf1ata'}) self.assertRegex( rendered, '
') self.assertRegex( rendered, - u'I love playing with my pi\xf1ata') + 'I love playing with my pi\xf1ata') def test_comments_are_ignored(self): """ diff --git a/setup.py b/setup.py index f70bd3e..02b41d1 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals - -import io import os import sys from shutil import rmtree @@ -13,7 +6,6 @@ from setuptools import find_packages from setuptools import setup - # Package meta-data. NAME = 'django-inlinecss' SRC_DIR = 'django_inlinecss' @@ -56,13 +48,7 @@ # Note: this will only work if 'README.md' is present in your MANIFEST.in file! try: - # Python 3 will raise FileNotFoundError instead of IOError - FileNotFoundError = IOError -except NameError: - pass - -try: - with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f: + with open(os.path.join(here, 'README.md'), encoding='utf-8') as f: long_description = '\n' + f.read() except FileNotFoundError: long_description = DESCRIPTION @@ -85,7 +71,7 @@ class UploadCommand(Command): @staticmethod def status(s): """Prints things in bold.""" - print('\033[1m{0}\033[0m'.format(s)) + print(f'\033[1m{s}\033[0m') def initialize_options(self): pass @@ -101,13 +87,13 @@ def run(self): pass self.status('Building Source and Wheel (universal) distribution…') - os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable)) + os.system(f'{sys.executable} setup.py sdist bdist_wheel --universal') self.status('Uploading the package to PyPI via Twine…') os.system('twine upload dist/*') self.status('Pushing git tags…') - os.system('git tag v{0}'.format(about['__version__'])) + os.system('git tag v{}'.format(about['__version__'])) os.system('git push --tags') sys.exit() @@ -128,20 +114,18 @@ def run(self): zip_safe=False, keywords=['html', 'css', 'inline', 'style', 'email'], classifiers=[ - 'Environment :: Other Environment', - 'Environment :: Web Environment', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Topic :: Communications :: Email', - 'Topic :: Text Processing :: Markup :: HTML', + "Environment :: Other Environment", + "Environment :: Web Environment", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Topic :: Communications :: Email", + "Topic :: Text Processing :: Markup :: HTML", ], install_requires=REQUIRED, tests_require=TESTS, diff --git a/test_settings.py b/test_settings.py index 08b5b85..0a91aa4 100644 --- a/test_settings.py +++ b/test_settings.py @@ -9,11 +9,6 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.11/ref/settings/ """ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function -from __future__ import unicode_literals - import os From f9e8cfe3522571d08bfb95da5106515a1238ac92 Mon Sep 17 00:00:00 2001 From: Facundo Maero Date: Fri, 30 Jul 2021 22:18:48 +0200 Subject: [PATCH 12/21] Configure pre-commit --- .pre-commit-config.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..76b6d57 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + args: [--markdown-linebreak-ext=md] + - id: end-of-file-fixer + - id: check-toml + - id: check-added-large-files + - id: debug-statements + - repo: https://github.com/PyCQA/flake8 + rev: "7.0.0" + hooks: + - id: flake8 + additional_dependencies: + - flake8-bugbear + - flake8-isort + - repo: https://github.com/psf/black + rev: "24.2.0" + hooks: + - id: black + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + name: isort (python) + - repo: https://github.com/myint/autoflake + rev: v2.2.1 + hooks: + - id: autoflake From a0a98625841c9382c8d715db3458a6caf39d4fdc Mon Sep 17 00:00:00 2001 From: Facundo Maero Date: Fri, 30 Jul 2021 22:28:52 +0200 Subject: [PATCH 13/21] Configure flake8 and isort --- setup.cfg | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7edd6f8..9069fcf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,18 +2,18 @@ test=pytest [flake8] -max-line-length=120 +application-import-names=django_inlinecss +max-line-length = 88 +extend-ignore = + # Black-incompatible colon spacing. + E203, + # Line jump before binary operator. + W503, +exclude=.tox,build,.eggs [isort] +force_single_line=true skip=.eggs/ -line_length=119 -wrap_length=79 -known_first_party=django_inlinecss -indent=' ' -force_single_line=True -default_section=THIRDPARTY -lines_after_imports=2 -use_parentheses=True [tool:pytest] django_find_project=false From 5ef0d93785ae1c4076211bfc239205ba298697d3 Mon Sep 17 00:00:00 2001 From: Facundo Maero Date: Fri, 30 Jul 2021 20:36:42 +0000 Subject: [PATCH 14/21] Run pre-commit --- MANIFEST.in | 2 +- django_inlinecss/__version__.py | 2 +- django_inlinecss/conf.py | 14 ++-- django_inlinecss/css_loaders.py | 8 +- django_inlinecss/templatetags/inlinecss.py | 11 +-- django_inlinecss/tests/static/foobar.css | 2 +- django_inlinecss/tests/test_css_loaders.py | 19 ++--- django_inlinecss/tests/test_templatetags.py | 86 ++++++++++----------- setup.py | 40 +++++----- test_settings.py | 86 ++++++++++----------- 10 files changed, 133 insertions(+), 137 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 12119c8..164330d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ include README.md -recursive-include django_inlinecss *.py \ No newline at end of file +recursive-include django_inlinecss *.py diff --git a/django_inlinecss/__version__.py b/django_inlinecss/__version__.py index fbf0a5b..cfb0b13 100644 --- a/django_inlinecss/__version__.py +++ b/django_inlinecss/__version__.py @@ -1,3 +1,3 @@ VERSION = (0, 3, 0) -__version__ = '.'.join(map(str, VERSION)) +__version__ = ".".join(map(str, VERSION)) diff --git a/django_inlinecss/conf.py b/django_inlinecss/conf.py index eea6976..726dd92 100644 --- a/django_inlinecss/conf.py +++ b/django_inlinecss/conf.py @@ -3,24 +3,26 @@ except ImportError: from django.utils import importlib -DEFAULT_ENGINE = 'django_inlinecss.engines.PynlinerEngine' -DEFAULT_CSS_LOADER = 'django_inlinecss.css_loaders.StaticfilesStorageCSSLoader' +DEFAULT_ENGINE = "django_inlinecss.engines.PynlinerEngine" +DEFAULT_CSS_LOADER = "django_inlinecss.css_loaders.StaticfilesStorageCSSLoader" def load_class_by_path(path): - i = path.rfind('.') - module_path, class_name = path[:i], path[i + 1:] + i = path.rfind(".") + module_path, class_name = path[:i], path[i + 1 :] module = importlib.import_module(module_path) return getattr(module, class_name) def get_engine(): from django.conf import settings - engine_path = getattr(settings, 'INLINECSS_ENGINE', DEFAULT_ENGINE) + + engine_path = getattr(settings, "INLINECSS_ENGINE", DEFAULT_ENGINE) return load_class_by_path(engine_path) def get_css_loader(): from django.conf import settings - engine_path = getattr(settings, 'INLINECSS_CSS_LOADER', DEFAULT_CSS_LOADER) + + engine_path = getattr(settings, "INLINECSS_CSS_LOADER", DEFAULT_CSS_LOADER) return load_class_by_path(engine_path) diff --git a/django_inlinecss/css_loaders.py b/django_inlinecss/css_loaders.py index c3253bc..9a1aca3 100644 --- a/django_inlinecss/css_loaders.py +++ b/django_inlinecss/css_loaders.py @@ -23,10 +23,10 @@ def load(self, path): expanded_path = finders.find(path) if expanded_path is None: - raise OSError(f'{path} does not exist') + raise OSError(f"{path} does not exist") - with open(expanded_path, 'rb') as css_file: - return css_file.read().decode('utf-8') + with open(expanded_path, "rb") as css_file: + return css_file.read().decode("utf-8") class StaticfilesStorageCSSLoader(BaseCSSLoader): @@ -34,4 +34,4 @@ def load(self, path): """ Retrieve CSS contents with staticfiles storage """ - return staticfiles_storage.open(path).read().decode('utf-8') + return staticfiles_storage.open(path).read().decode("utf-8") diff --git a/django_inlinecss/templatetags/inlinecss.py b/django_inlinecss/templatetags/inlinecss.py index 70a4bde..a8979a8 100644 --- a/django_inlinecss/templatetags/inlinecss.py +++ b/django_inlinecss/templatetags/inlinecss.py @@ -3,7 +3,6 @@ from django_inlinecss import conf - register = template.Library() @@ -14,14 +13,14 @@ def __init__(self, nodelist, filter_expressions): def render(self, context): rendered_contents = self.nodelist.render(context) - css = '' + css = "" for expression in self.filter_expressions: path = expression.resolve(context, True) if path is not None: path = smart_str(path) css_loader = conf.get_css_loader()() - css = ''.join((css, css_loader.load(path))) + css = "".join((css, css_loader.load(path))) engine = conf.get_engine()(html=rendered_contents, css=css) return engine.render() @@ -29,13 +28,11 @@ def render(self, context): @register.tag def inlinecss(parser, token): - nodelist = parser.parse(('endinlinecss',)) + nodelist = parser.parse(("endinlinecss",)) # prevent second parsing of endinlinecss parser.delete_first_token() args = token.split_contents()[1:] - return InlineCssNode( - nodelist, - [parser.compile_filter(arg) for arg in args]) + return InlineCssNode(nodelist, [parser.compile_filter(arg) for arg in args]) diff --git a/django_inlinecss/tests/static/foobar.css b/django_inlinecss/tests/static/foobar.css index 6381e58..6239e62 100644 --- a/django_inlinecss/tests/static/foobar.css +++ b/django_inlinecss/tests/static/foobar.css @@ -2,5 +2,5 @@ div.foo { margin: 10px 15px 20px 25px; } div.bar { - padding: 10px 15px 20px 25px; + padding: 10px 15px 20px 25px; } diff --git a/django_inlinecss/tests/test_css_loaders.py b/django_inlinecss/tests/test_css_loaders.py index fe969c3..a8b7ed7 100644 --- a/django_inlinecss/tests/test_css_loaders.py +++ b/django_inlinecss/tests/test_css_loaders.py @@ -1,6 +1,7 @@ """ Test CSS loaders """ + from django.conf import settings from django.test import TestCase from django.test import override_settings @@ -9,21 +10,21 @@ from django_inlinecss.css_loaders import StaticfilesStorageCSSLoader -@override_settings(STATICFILES_DIRS=[settings.STATIC_ROOT], STATIC_ROOT='') +@override_settings(STATICFILES_DIRS=[settings.STATIC_ROOT], STATIC_ROOT="") class StaticfilesFinderCSSLoaderTestCase(TestCase): def setUp(self): self.loader = StaticfilesFinderCSSLoader() super().setUp() def test_loads_existing_css_file(self): - css = self.loader.load('bar.css') - self.assertIn('div.bar {', css) + css = self.loader.load("bar.css") + self.assertIn("div.bar {", css) def test_load_file_does_not_exist(self): with self.assertRaises(IOError) as e: - self.loader.load('missing.css') + self.loader.load("missing.css") - self.assertEqual(str(e.exception), 'missing.css does not exist') + self.assertEqual(str(e.exception), "missing.css does not exist") class StaticfilesStorageCSSLoaderTestCase(TestCase): @@ -32,11 +33,11 @@ def setUp(self): super().setUp() def test_loads_existing_css_file(self): - css = self.loader.load('bar.css') - self.assertIn('div.bar {', css) + css = self.loader.load("bar.css") + self.assertIn("div.bar {", css) def test_load_file_does_not_exist(self): with self.assertRaises(IOError) as e: - self.loader.load('missing.css') + self.loader.load("missing.css") - self.assertEqual(e.exception.strerror, 'No such file or directory') + self.assertEqual(e.exception.strerror, "No such file or directory") diff --git a/django_inlinecss/tests/test_templatetags.py b/django_inlinecss/tests/test_templatetags.py index 9430444..29055f5 100644 --- a/django_inlinecss/tests/test_templatetags.py +++ b/django_inlinecss/tests/test_templatetags.py @@ -4,14 +4,15 @@ The actual CSS inlining displayed here is extremely simple: tests of the CSS selector functionality is independent. """ + import os +from unittest.mock import patch from django.conf import settings from django.template.loader import get_template from django.test import TestCase from django.test.utils import override_settings from django.utils.safestring import mark_safe -from unittest.mock import patch class InlinecssTests(TestCase): @@ -22,25 +23,23 @@ def assert_foo_and_bar_rendered(self, rendered): foo_div_regex = ( r'
' r'\s+This is the "foo" div.\s+' - r'<\/div>') - self.assertRegex( - rendered, - foo_div_regex) + r"<\/div>" + ) + self.assertRegex(rendered, foo_div_regex) bar_div_regex = ( r'
' r'\s+This is the "bar" div.\s+' - r'<\/div>') - self.assertRegex( - rendered, - bar_div_regex) + r"<\/div>" + ) + self.assertRegex(rendered, bar_div_regex) def test_single_staticfiles_css(self): """ Test the basic inlining case of using the staticfiles loader to load a CSS file and inline it as part of a rendering step. """ - template = get_template('single_staticfiles_css.html') + template = get_template("single_staticfiles_css.html") rendered = template.render({}) self.assert_foo_and_bar_rendered(rendered) @@ -50,7 +49,7 @@ def test_multiple_staticfiles_css(self): This tests that passing two css files works. """ - template = get_template('multiple_staticfiles_css.html') + template = get_template("multiple_staticfiles_css.html") rendered = template.render({}) self.assert_foo_and_bar_rendered(rendered) @@ -59,8 +58,8 @@ def test_variable_defined_staticfiles_css(self): Test that the staticfiles paths passed to the templatetag may be defined as variables instead of strings. """ - template = get_template('variable_defined_staticfiles_css.html') - context = {'foo_css': 'foo.css', 'bar_css': 'bar.css'} + template = get_template("variable_defined_staticfiles_css.html") + context = {"foo_css": "foo.css", "bar_css": "bar.css"} rendered = template.render(context) self.assert_foo_and_bar_rendered(rendered) @@ -70,9 +69,8 @@ def test_variable_and_string_defined_staticfiles_css(self): Test that we can mix and match variable-defined CSS files & those defined quoted in the templatetag. """ - template = get_template( - 'variable_and_string_defined_staticfiles_css.html') - context = {'foo_css': 'foo.css'} + template = get_template("variable_and_string_defined_staticfiles_css.html") + context = {"foo_css": "foo.css"} rendered = template.render(context) self.assert_foo_and_bar_rendered(rendered) @@ -81,7 +79,7 @@ def test_inline_css(self): Test that