Skip to content

Commit d69f93b

Browse files
authored
Merge pull request #66 from roverdotcom/DEV-103519-add-gha
2 parents aca7106 + a9f5320 commit d69f93b

16 files changed

Lines changed: 244 additions & 246 deletions
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Run Tests and Linter
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- main
8+
9+
jobs:
10+
lint-and-test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: [3.8.18, 3.9.18, 3.10.13, 3.11.8]
16+
django-version: [3.2, 4.2]
17+
18+
name: Lint and Test (Python ${{ matrix.python-version }} - Django ${{ matrix.django-version }})
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
28+
- name: Install dependencies
29+
run: |
30+
pip install -q Django==${{ matrix.django-version }}
31+
pip install -e .[flake8,tests]
32+
33+
- name: Add current directory to PYTHONPATH
34+
run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV
35+
36+
- name: Lint with flake8
37+
run: flake8
38+
39+
- name: Test with pytest
40+
run: pytest

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: trailing-whitespace
6+
args: [--markdown-linebreak-ext=md]
7+
- id: end-of-file-fixer
8+
- id: check-toml
9+
- id: check-added-large-files
10+
- id: debug-statements
11+
- repo: https://github.com/PyCQA/flake8
12+
rev: "7.0.0"
13+
hooks:
14+
- id: flake8
15+
additional_dependencies:
16+
- flake8-bugbear
17+
- flake8-isort
18+
- repo: https://github.com/psf/black
19+
rev: "24.2.0"
20+
hooks:
21+
- id: black
22+
- repo: https://github.com/pycqa/isort
23+
rev: 5.13.2
24+
hooks:
25+
- id: isort
26+
name: isort (python)
27+
- repo: https://github.com/myint/autoflake
28+
rev: v2.2.1
29+
hooks:
30+
- id: autoflake

.travis.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
include README.md
2-
recursive-include django_inlinecss *.py
2+
recursive-include django_inlinecss *.py

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.org/roverdotcom/django-inlinecss.png?branch=master)](https://travis-ci.org/roverdotcom/django-inlinecss)
1+
[![Build Status](https://travis-ci.org/roverdotcom/django-inlinecss.svg?branch=master)](https://travis-ci.org/roverdotcom/django-inlinecss)
22

33
## About
44

@@ -14,8 +14,8 @@ template language.
1414

1515
- BeautifulSoup
1616
- cssutils
17-
- Python 2.7+,3.4+
18-
- Django 1.11+
17+
- Python 3.8+
18+
- Django 3.2+
1919

2020

2121
#### Step 2: Install django_inlinecss

django_inlinecss/__version__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
VERSION = (0, 3, 0)
1+
VERSION = (0, 4, 0)
22

3-
__version__ = '.'.join(map(str, VERSION))
3+
__version__ = ".".join(map(str, VERSION))

django_inlinecss/conf.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
1-
from __future__ import absolute_import
2-
from __future__ import division
3-
from __future__ import print_function
4-
from __future__ import unicode_literals
5-
6-
71
try:
82
import importlib
93
except ImportError:
104
from django.utils import importlib
115

12-
DEFAULT_ENGINE = 'django_inlinecss.engines.PynlinerEngine'
13-
DEFAULT_CSS_LOADER = 'django_inlinecss.css_loaders.StaticfilesStorageCSSLoader'
6+
DEFAULT_ENGINE = "django_inlinecss.engines.PynlinerEngine"
7+
DEFAULT_CSS_LOADER = "django_inlinecss.css_loaders.StaticfilesStorageCSSLoader"
148

159

1610
def load_class_by_path(path):
17-
i = path.rfind('.')
18-
module_path, class_name = path[:i], path[i + 1:]
11+
i = path.rfind(".")
12+
module_path, class_name = path[:i], path[i + 1 :]
1913
module = importlib.import_module(module_path)
2014
return getattr(module, class_name)
2115

2216

2317
def get_engine():
2418
from django.conf import settings
25-
engine_path = getattr(settings, 'INLINECSS_ENGINE', DEFAULT_ENGINE)
19+
20+
engine_path = getattr(settings, "INLINECSS_ENGINE", DEFAULT_ENGINE)
2621
return load_class_by_path(engine_path)
2722

2823

2924
def get_css_loader():
3025
from django.conf import settings
31-
engine_path = getattr(settings, 'INLINECSS_CSS_LOADER', DEFAULT_CSS_LOADER)
26+
27+
engine_path = getattr(settings, "INLINECSS_CSS_LOADER", DEFAULT_CSS_LOADER)
3228
return load_class_by_path(engine_path)

django_inlinecss/css_loaders.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
from __future__ import absolute_import
2-
from __future__ import division
3-
from __future__ import print_function
4-
from __future__ import unicode_literals
5-
61
from django.contrib.staticfiles import finders
72
from django.contrib.staticfiles.storage import staticfiles_storage
83

94

10-
class BaseCSSLoader(object):
5+
class BaseCSSLoader:
116
def __init__(self):
127
pass
138

@@ -28,15 +23,15 @@ def load(self, path):
2823
expanded_path = finders.find(path)
2924

3025
if expanded_path is None:
31-
raise IOError('{} does not exist'.format(path))
26+
raise OSError(f"{path} does not exist")
3227

33-
with open(expanded_path, 'rb') as css_file:
34-
return css_file.read().decode('utf-8')
28+
with open(expanded_path, "rb") as css_file:
29+
return css_file.read().decode("utf-8")
3530

3631

3732
class StaticfilesStorageCSSLoader(BaseCSSLoader):
3833
def load(self, path):
3934
"""
4035
Retrieve CSS contents with staticfiles storage
4136
"""
42-
return staticfiles_storage.open(path).read().decode('utf-8')
37+
return staticfiles_storage.open(path).read().decode("utf-8")

django_inlinecss/engines.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
from __future__ import absolute_import
2-
from __future__ import division
3-
from __future__ import print_function
4-
from __future__ import unicode_literals
5-
6-
from builtins import object
7-
81
import pynliner
92

103

11-
class EngineBase(object):
4+
class EngineBase:
125
def __init__(self, html, css):
136
self.html = html
147
self.css = css
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
from __future__ import absolute_import
2-
from __future__ import division
3-
from __future__ import print_function
4-
from __future__ import unicode_literals
5-
61
from django import template
7-
from django.utils.encoding import smart_text
2+
from django.utils.encoding import smart_str
83

94
from django_inlinecss import conf
105

11-
126
register = template.Library()
137

148

@@ -19,28 +13,26 @@ def __init__(self, nodelist, filter_expressions):
1913

2014
def render(self, context):
2115
rendered_contents = self.nodelist.render(context)
22-
css = ''
16+
css = ""
2317
for expression in self.filter_expressions:
2418
path = expression.resolve(context, True)
2519
if path is not None:
26-
path = smart_text(path)
20+
path = smart_str(path)
2721

2822
css_loader = conf.get_css_loader()()
29-
css = ''.join((css, css_loader.load(path)))
23+
css = "".join((css, css_loader.load(path)))
3024

3125
engine = conf.get_engine()(html=rendered_contents, css=css)
3226
return engine.render()
3327

3428

3529
@register.tag
3630
def inlinecss(parser, token):
37-
nodelist = parser.parse(('endinlinecss',))
31+
nodelist = parser.parse(("endinlinecss",))
3832

3933
# prevent second parsing of endinlinecss
4034
parser.delete_first_token()
4135

4236
args = token.split_contents()[1:]
4337

44-
return InlineCssNode(
45-
nodelist,
46-
[parser.compile_filter(arg) for arg in args])
38+
return InlineCssNode(nodelist, [parser.compile_filter(arg) for arg in args])

0 commit comments

Comments
 (0)