Skip to content

Commit

Permalink
Start working on 3.0
Browse files Browse the repository at this point in the history
- BREAKING: The minimum supported Django version is now 3.2 (other versions may work, but are not tested)
- BREAKING: Drop support for Python 3.7 and below
- BREAKING: Drop support for Ruby-based Sass compiler
  • Loading branch information
andreyfedoseev committed Aug 19, 2023
1 parent 26fab45 commit 7abbc54
Show file tree
Hide file tree
Showing 49 changed files with 84 additions and 620 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-ast
- id: check-merge-conflict
Expand All @@ -14,14 +14,14 @@ repos:
- id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.198'
rev: 'v0.0.285'
hooks:
- id: ruff
# Respect `exclude` and `extend-exclude` settings.
args: ["--force-exclude", "--fix"]
args: ["--fix"]
exclude: ^docs/.*
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/keewis/blackdoc
Expand All @@ -30,11 +30,11 @@ repos:
- id: blackdoc
files: ^docs/.*\.rst$
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.8.0.4
rev: v0.9.0.5
hooks:
- id: shellcheck
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
rev: v2.2.5
hooks:
- id: codespell
files: ^docs/.*\.rst$
Expand All @@ -44,7 +44,7 @@ repos:
- id: woke-from-source
files: ^docs/.*\.rst$
- repo: https://github.com/jackdewinter/pymarkdown
rev: v0.9.8
rev: v0.9.12
hooks:
- id: pymarkdown
args: [--disable-rules, MD041, scan]
13 changes: 8 additions & 5 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
# Required
version: 2

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py
build:
os: ubuntu-22.04
tools:
python: "3"

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3
install:
- method: pip
path: .

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Changelog

### 3.0

- BREAKING: The minimum supported Django version is now 3.2
(other versions may work, but are not tested)
- BREAKING: Drop support for Python 3.7 and below
- BREAKING: Drop support for Ruby-based Sass compiler

### 2.4

#### Deprecation
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
FROM andreyfedoseev/django-static-precompiler:18.04-2
FROM andreyfedoseev/django-static-precompiler:20.04-1
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
RUN apt update && \
apt install software-properties-common -y && \
add-apt-repository ppa:deadsnakes/ppa -y && \
apt install -y \
python3.6-dev \
python3.8-dev \
python3.9-dev \
python3.9-distutils \
python3.10-dev \
python3.10-distutils \
python3.11-dev \
python3.11-distutils \
python3.12-dev \
python3.12-distutils \
python3-pip \
sqlite3
RUN mkdir /app
WORKDIR /app
ADD requirements-*.txt /app/
RUN pip3 install -r requirements-test.txt
ADD . /app/
RUN pip3 install -e .[libsass]
RUN pip3 install .[libsass]
12 changes: 6 additions & 6 deletions Dockerfile-base
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM ubuntu:18.04
MAINTAINER Andrey Fedoseev <andrey.fedoseev@gmail.com>
RUN apt-get update && apt-get install -y autoconf libtool ruby-dev npm wget
FROM ubuntu:20.04
MAINTAINER Andrey Fedoseev <andrey@andreyfedoseev.com>
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y autoconf libtool npm wget
RUN ln -s /usr/bin/nodejs /usr/local/bin/node
RUN npm install -g coffeescript@2.7.0
RUN npm install -g livescript@1.6.0
RUN npm install -g less@4.1.3
RUN npm install -g babel-cli@6.26.0
RUN npm install -g stylus@0.50.0
RUN npm install -g handlebars@4.7.7
RUN gem install sass -v 3.4.22
RUN gem install compass -v 1.0.1
RUN wget -O /tmp/dart-sass.tar.gz https://github.com/sass/dart-sass/releases/download/1.56.1/dart-sass-1.56.1-linux-x64.tar.gz && \
RUN wget -O /tmp/dart-sass.tar.gz https://github.com/sass/dart-sass/releases/download/1.66.0/dart-sass-1.66.0-linux-x64.tar.gz && \
tar -xzf /tmp/dart-sass.tar.gz -C /opt && \
rm -rf /tmp/dart-sass.tar.gz
ENV PATH="/opt/dart-sass:${PATH}"
49 changes: 0 additions & 49 deletions docs/compiler-settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,55 +119,6 @@ Example:
SASS / SCSS
===========

Ruby-based (legacy) SASS compiler.

``executable``
Path to SASS compiler executable. Default: "sass".

``sourcemap_enabled``
Boolean. Set to ``True`` to enable source maps. Default: ``False``.

``compass_enabled``
Boolean. Whether to use compass or not. Compass must be installed in your system.
Run ``sass --compass`` and if no error is shown it means that compass is installed.

``load_paths``
List of additional directories to look imported files (``--load-path`` command line option). Default: ``None``.

``precision``
How many digits of precision to use when outputting decimal numbers. Default: ``None``.
Set this to 8 or more if you compile Bootstrap.

``output_style``
Output style. Default: ``None``.
Can be nested, compact, compressed, or expanded.

Example:

.. code-block:: python
STATIC_PRECOMPILER_COMPILERS = (
(
"static_precompiler.compilers.SCSS",
{
"executable": "/usr/bin/sass",
"sourcemap_enabled": True,
"compass_enabled": True,
"load_paths": ["/path"],
"precision": 8,
"output_style": "compressed",
},
),
)
Dart Sass
=========

Dart Sass is the current implementation of SASS.

.. note:: Dart Sass compiler is not enabled by default. See the example below for how to enable it.

Options:

``sourcemap_enabled``
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
# built documents.
#
# The short X.Y version.
version = "2.4"
version = "3.0"
# The full version, including alpha/beta/rc tags.
release = version
release = "3.0a1"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion docs/general-settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ General settings
STATIC_PRECOMPILER_COMPILERS = (
("static_precompiler.compilers.CoffeeScript", {"executable": "/usr/bin/coffeescript"}),
("static_precompiler.compilers.SCSS", {"compass_enabled": True}),
("static_precompiler.compilers.SCSS", {"load_paths": ["/some/path"]}),
)
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ line-length = 120

[tool.ruff]
select = ["F", "E", "W", "I", "YTT", "B", "C4", "T10", "SIM", "ERA", "RUF", "UP"]
ignore = ["RUF001"]
ignore = ["RUF001", "RUF012"]
line-length = 120
target-version = "py36"
target-version = "py38"

[tool.ruff.isort]
known-first-party = ["static_precompiler"]

[tool.mypy]
python_version = "3.6"
python_version = "3.8"
plugins = ["mypy_django_plugin.main"]

[[tool.mypy.overrides]]
Expand Down
10 changes: 4 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = django-static-precompiler
version = 2.4
version = 3.0a1
author = Andrey Fedoseev
author_email = andrey@andreyfedoseev.com
description =
Expand All @@ -15,18 +15,16 @@ project_urls =
Documentation = https://django-static-precompiler.readthedocs.io/
classifiers =
Development Status :: 5 - Production/Stable
Framework :: Django :: 2
Framework :: Django :: 3
Framework :: Django :: 4
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Topic :: Internet :: WWW/HTTP
keywords =
sass
Expand All @@ -45,9 +43,9 @@ keywords =
package_dir =
= src
packages = find:
python_requires = >=3.6
python_requires = >=3.8
install_requires =
Django>=2.0
Django>=3.2
tests_require =
pytest
pytest-django
Expand Down
2 changes: 1 addition & 1 deletion src/static_precompiler/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.4"
__version__ = "3.0a1"
2 changes: 1 addition & 1 deletion src/static_precompiler/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def get_cache() -> BaseCache:
if settings.CACHE_NAME:
return django.core.cache.caches.get(settings.CACHE_NAME) # type: ignore
return django.core.cache.cache # type: ignore
return django.core.cache.cache


def get_cache_key(key: str) -> str:
Expand Down
13 changes: 5 additions & 8 deletions src/static_precompiler/compilers/babel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class Babel(base.BaseCompiler):

name = "babel"
input_extension = "es6"
output_extension = "js"
Expand All @@ -25,7 +24,9 @@ def __init__(
self.executable = executable
self.is_sourcemap_enabled = sourcemap_enabled
if modules:
warnings.warn("'modules' option is removed in Babel 6.0. Use `plugins` instead.", DeprecationWarning)
warnings.warn(
"'modules' option is removed in Babel 6.0. Use `plugins` instead.", DeprecationWarning, stacklevel=2
)
self.modules = modules
self.plugins = plugins
self.presets = presets
Expand All @@ -46,9 +47,7 @@ def get_extra_args(self) -> List[str]:
return args

def compile_file(self, source_path: str) -> str:
args = [
self.executable,
] + self.get_extra_args()
args = [self.executable, *self.get_extra_args()]

if self.is_sourcemap_enabled:
args.append("-s")
Expand All @@ -72,9 +71,7 @@ def compile_file(self, source_path: str) -> str:
return self.get_output_path(source_path)

def compile_source(self, source: str) -> str:
args = [
self.executable,
] + self.get_extra_args()
args = [self.executable, *self.get_extra_args()]

return_code, out, errors = utils.run_command(args, input=source)
if return_code:
Expand Down
9 changes: 3 additions & 6 deletions src/static_precompiler/compilers/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import logging
import os
import posixpath
Expand All @@ -17,7 +18,6 @@


class BaseCompiler:

name: str
supports_dependencies: bool = False
input_extension: str = ""
Expand Down Expand Up @@ -49,10 +49,8 @@ def get_full_source_path(self, source_path: str) -> str:
if os.path.exists(full_path):
return full_path

try:
full_path = finders.find(norm_source_path) # type: ignore
except django.core.exceptions.SuspiciousOperation:
pass
with contextlib.suppress(django.core.exceptions.SuspiciousOperation):
full_path = finders.find(norm_source_path)

if full_path is None:
raise ValueError(f"Can't find staticfile named: {source_path}")
Expand Down Expand Up @@ -157,7 +155,6 @@ def compile(self, source_path: str, from_management: bool = False, verbosity: in
compiled_path = self.get_output_path(source_path)

if self.should_compile(source_path, from_management=from_management):

compiled_path = self.compile_file(source_path)

if self.supports_dependencies:
Expand Down
1 change: 0 additions & 1 deletion src/static_precompiler/compilers/coffeescript.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class CoffeeScript(base.BaseCompiler):

name = "coffeescript"
input_extension = "coffee"
output_extension = "js"
Expand Down
Loading

0 comments on commit 7abbc54

Please sign in to comment.