Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV-103519] Upgrade to Django 4.2. Switch from travis to GHA #66

Merged
merged 21 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Run Tests and Linter

on:
pull_request:
branches:
- master
- main

jobs:
lint-and-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
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
JVenberg marked this conversation as resolved.
Show resolved Hide resolved

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
JVenberg marked this conversation as resolved.
Show resolved Hide resolved

- name: Install dependencies
run: |
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

- name: Test with pytest
run: pytest
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
6 changes: 0 additions & 6 deletions django_inlinecss/conf.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
9 changes: 2 additions & 7 deletions django_inlinecss/css_loaders.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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')
Expand Down
9 changes: 1 addition & 8 deletions django_inlinecss/engines.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 2 additions & 7 deletions django_inlinecss/templatetags/inlinecss.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
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_text
from django.utils.encoding import smart_str

from django_inlinecss import conf

Expand All @@ -23,7 +18,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)))
Expand Down
9 changes: 2 additions & 7 deletions django_inlinecss/tests/test_css_loaders.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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')
Expand All @@ -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')
Expand Down
13 changes: 4 additions & 9 deletions django_inlinecss/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@
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
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 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 = (
Expand Down Expand Up @@ -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,
'<div class="bar" style="padding: 10px 15px 20px 25px">')
self.assertRegex(
rendered,
u'I love playing with my pi\xf1ata')
'I love playing with my pi\xf1ata')

def test_comments_are_ignored(self):
"""
Expand Down
24 changes: 12 additions & 12 deletions setup.cfg

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did we settle on these options?

Copy link
Contributor Author

@JVenberg JVenberg Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not actually sure. I merged in @facundojmaero's PR here and he had changed a few things. I assume it was to either get it to lint with the newer linter version and/or due to the formatting changes he made

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh gotcha. Yeah like the max line length change, for example. Not a huge deal since its just linting.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend you to migrate to ruff and deprecate all isort, flake8, pylint/black etc...

But it is up-to-you, just ruff is blazing fast and making what it should do without issues...

Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
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
DJANGO_SETTINGS_MODULE = test_settings
python_files = test_*.py
django_find_project=false
DJANGO_SETTINGS_MODULE=test_settings
python_files=test_*.py
Loading