Skip to content

Commit

Permalink
feat: compile djlint wheels with mypyc
Browse files Browse the repository at this point in the history
  • Loading branch information
monosans authored Oct 31, 2024
1 parent 5446b6d commit dbc0961
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 22 deletions.
36 changes: 34 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,25 @@ on:
- v*
workflow_dispatch:
jobs:
publish-pypi:
build-compiled:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-13
- macos-latest
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v3
- run: uv tool run --from cibuildwheel@latest --no-cache --python 3.12 cibuildwheel --output-dir dist
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: dist
build-pure:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'djlint' }}
permissions:
Expand All @@ -14,10 +32,24 @@ jobs:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v3
- run: uv build --python 3.12 --no-cache
- uses: actions/upload-artifact@v4
with:
name: wheels-any
path: dist
publish-pypi:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'djlint' && startsWith(github.ref, 'refs/tags/') }}
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
- uses: pypa/gh-action-pypi-publish@release/v1
publish-npm:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'djlint' }}
if: ${{ github.repository_owner == 'djlint' && startsWith(github.ref, 'refs/tags/') }}
needs:
- build-compiled
- build-pure
permissions:
id-token: write
steps:
Expand Down
5 changes: 4 additions & 1 deletion djlint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
from .output import ProcessResult


@click.command(context_settings={"help_option_names": ["-h", "--help"]}) # type: ignore[operator]
@click.command( # type: ignore[operator]
context_settings={"help_option_names": ["-h", "--help"]},
help="djLint · HTML template linter and formatter.",
)
@click.argument(
"src",
type=click.Path(
Expand Down
14 changes: 7 additions & 7 deletions djlint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import TYPE_CHECKING

import regex as re
from typing_extensions import TypedDict

from .helpers import (
inside_ignored_linter_block,
Expand All @@ -18,15 +19,14 @@
from collections.abc import Mapping
from pathlib import Path

from typing_extensions import TypedDict

from .settings import Config

class LintError(TypedDict):
code: str
line: str
match: str
message: str

class LintError(TypedDict):
code: str
line: str
match: str
message: str


flags = {
Expand Down
10 changes: 5 additions & 5 deletions djlint/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
import regex as re
from click import echo
from colorama import Fore, Style
from typing_extensions import TypedDict

if TYPE_CHECKING:
from collections.abc import Collection, Iterable, Mapping, Sequence

from typing_extensions import TypedDict

from .lint import LintError
from .settings import Config

class ProcessResult(TypedDict, total=False):
format_message: dict[str, tuple[str, ...]]
lint_message: dict[str, list[LintError]]

class ProcessResult(TypedDict, total=False):
format_message: dict[str, tuple[str, ...]]
lint_message: dict[str, list[LintError]]


try:
Expand Down
4 changes: 1 addition & 3 deletions djlint/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import logging
import sys
from itertools import chain

# get pyproject.toml settings
from pathlib import Path
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -227,7 +225,7 @@ class Config:

def __init__(
self,
src: str,
src: str = ".",
*,
ignore: str = "",
extension: str = "",
Expand Down
25 changes: 23 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies = [
"regex>=2023",
"tomli>=2.0.1; python_version<'3.11'",
"tqdm>=4.62.2",
"typing-extensions>=3.7.4",
]
urls.documentation = "https://djlint.com"
urls.repository = "https://github.com/djlint/djLint"
Expand All @@ -57,8 +58,28 @@ dev = [
"types-pyyaml==6.0.12.20240917",
"types-regex==2024.9.11.20240912",
"types-tqdm==4.66.0.20240417",
"typing-extensions==4.12.2",
]

[tool.hatch.build.targets.sdist]
include = ["djlint"]
include = ["djlint", "mypy.ini"]

[tool.hatch.build.targets.wheel.hooks.mypyc]
dependencies = [
"click",
"hatch-mypyc",
"json5",
"types-colorama",
"types-pyyaml",
"types-regex",
"types-tqdm",
"typing-extensions",
]
enable-by-default = false
exclude = ["djlint/__main__.py"]
options = { opt_level = "3", debug_level = "0" }

[tool.cibuildwheel]
build = "cp*"
build-frontend = "build[uv]"
environment.HATCH_BUILD_HOOK_ENABLE_MYPYC = "1"
linux.manylinux-x86_64-image = "manylinux_2_28"
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dbc0961

Please sign in to comment.