Skip to content

Commit b5364a5

Browse files
committed
Removed django-appconf. Switched from pyright to mypy.
1 parent 88adcc5 commit b5364a5

File tree

10 files changed

+344
-235
lines changed

10 files changed

+344
-235
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@ jobs:
118118
# uses: pypa/gh-action-pypi-publish@release/v1.10
119119
# with:
120120
# repository-url: https://test.pypi.org/legacy/
121-
# skip-existing: true
121+
# skip-existing: true

.pre-commit-config.yaml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,34 @@ repos:
1616
- id: check-json
1717

1818
- repo: https://github.com/charliermarsh/ruff-pre-commit
19-
rev: "v0.6.9"
19+
rev: "v0.7.4"
2020
hooks:
2121
- id: ruff
2222
- id: ruff-format
2323

24-
- repo: https://github.com/RobertCraigie/pyright-python
25-
rev: v1.1.384
26-
hooks:
27-
- id: pyright
28-
29-
- repo: https://github.com/adamchainz/djade-pre-commit
30-
rev: "1.3.0"
31-
hooks:
32-
- id: djade
33-
args: [--target-version, "4.2"]
34-
3524
- repo: https://github.com/asottile/pyupgrade
36-
rev: v3.17.0
25+
rev: v3.19.0
3726
hooks:
3827
- id: pyupgrade
3928
args: [--py39-plus]
4029

4130
- repo: https://github.com/adamchainz/django-upgrade
42-
rev: "1.21.0"
31+
rev: "1.22.1"
4332
hooks:
4433
- id: django-upgrade
4534
args: [--target-version, "4.2"]
35+
36+
- repo: local
37+
hooks:
38+
- id: mypy
39+
name: mypy
40+
language: system
41+
types: [python]
42+
entry: uv run mypy
43+
require_serial: true
44+
45+
- repo: https://github.com/adamchainz/djade-pre-commit
46+
rev: "1.3.2"
47+
hooks:
48+
- id: djade
49+
args: [--target-version, "4.2"]

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 2.20.0
4+
5+
- Removed django-appconf again.
6+
- Switched from pyright to mypy for type checking.
7+
- Fixed broken links in the documentation.
8+
39
## 2.19.0
410

511
- Transfered the project to django-commons.

pyproject.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ dependencies = [
2828
"django>=4.2",
2929
"certifi>=2023.7.22,<2025.0.0",
3030
"django-typer>=2.1.2",
31-
"django-appconf>=1.0.6",
3231
]
3332

3433
[project.optional-dependencies]
@@ -41,13 +40,13 @@ Repository = "https://github.com/django-commons/django-tailwind-cli"
4140

4241
[tool.uv]
4342
dev-dependencies = [
44-
"django-types>=0.19.1",
4543
"pytest-cov>=5.0.0",
4644
"pytest-django>=4.9.0",
4745
"pytest-mock>=3.14.0",
4846
"pytest-randomly>=3.15.0",
4947
"pytest-sugar>=1.0.0",
5048
"pytest>=8.3.3",
49+
"django-stubs[compatible-mypy]>=5.1.1",
5150
]
5251

5352
[build-system]
@@ -74,12 +73,13 @@ exclude = '''
7473
)/
7574
'''
7675

77-
# Pyright
78-
[tool.pyright]
79-
venvPath = "."
80-
venv = ".venv"
81-
typeCheckingMode = "basic"
82-
ignore = ["./tests/**/*"]
76+
# mypy
77+
[tool.mypy]
78+
plugins = ["mypy_django_plugin.main"]
79+
80+
[tool.django-stubs]
81+
django_settings_module = "tests.settings"
82+
strict_settings = false
8383

8484
# Ruff
8585
[tool.ruff]

src/django_tailwind_cli/conf.py

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
1-
from appconf import AppConf
2-
from django.conf import settings # noqa: F401
1+
from django.conf import settings
32

43
DEFAULT_SRC_REPO = "tailwindlabs/tailwindcss"
54

65

7-
class TailwindCliAppConfig(AppConf):
8-
VERSION = "3.4.11"
9-
PATH = "~/.local/bin/"
10-
AUTOMATIC_DOWNLOAD = True
11-
SRC_CSS = None
12-
DIST_CSS = "css/tailwind.css"
13-
CONFIG_FILE = "tailwind.config.js"
14-
SRC_REPO = "tailwindlabs/tailwindcss"
15-
ASSET_NAME = "tailwindcss"
6+
def get_tailwind_cli_version() -> str:
7+
"""Get the version of the Tailwind CSS CLI."""
8+
return getattr(settings, "TAILWIND_CLI_VERSION", "3.4.11")
169

17-
class Meta:
18-
prefix = "TAILWIND_CLI"
10+
11+
def get_tailwind_cli_path() -> str:
12+
"""Get the path to the Tailwind CSS CLI."""
13+
return getattr(settings, "TAILWIND_CLI_PATH", "~/.local/bin/")
14+
15+
16+
def get_tailwind_cli_automatic_download() -> bool:
17+
"""Get the automatic download setting for the Tailwind CSS CLI."""
18+
return getattr(settings, "TAILWIND_CLI_AUTOMATIC_DOWNLOAD", True)
19+
20+
21+
def get_tailwind_cli_src_css() -> None | str:
22+
"""Get the source css file for the Tailwind CSS CLI."""
23+
return getattr(settings, "TAILWIND_CLI_SRC_CSS", None)
24+
25+
26+
def get_tailwind_cli_dist_css() -> str:
27+
"""Get the dist css file for the Tailwind CSS CLI."""
28+
return getattr(settings, "TAILWIND_CLI_DIST_CSS", "css/tailwind.css")
29+
30+
31+
def get_tailwind_cli_config_file() -> str:
32+
"""Get the config file for the Tailwind CSS CLI."""
33+
return getattr(settings, "TAILWIND_CLI_CONFIG_FILE", "tailwind.config.js")
34+
35+
36+
def get_tailwind_cli_src_repo() -> str:
37+
"""Get the source repository for the Tailwind CSS CLI."""
38+
return getattr(settings, "TAILWIND_CLI_SRC_REPO", DEFAULT_SRC_REPO)
39+
40+
41+
def get_tailwind_cli_asset_name() -> str:
42+
"""Get the asset name for the Tailwind CSS CLI."""
43+
return getattr(settings, "TAILWIND_CLI_ASSET_NAME", "tailwindcss")

src/django_tailwind_cli/management/commands/tailwind.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
import certifi
1515
import typer
16+
from django.conf import settings
1617
from django.core.management.base import CommandError
1718
from django.template.utils import get_app_template_dirs
1819
from django_typer.management import TyperCommand, command, initialize
1920

20-
from django_tailwind_cli import utils
21-
from django_tailwind_cli.conf import DEFAULT_SRC_REPO, settings
21+
from django_tailwind_cli import conf, utils
2222

2323

2424
class Command(TyperCommand):
@@ -35,7 +35,7 @@ def init(self):
3535

3636
# Before running the actual subcommand, we need to make sure that the CLI is installed and
3737
# the config file exists.
38-
if settings.TAILWIND_CLI_AUTOMATIC_DOWNLOAD:
38+
if conf.get_tailwind_cli_automatic_download():
3939
self.download_cli()
4040
self._create_tailwind_config_if_not_exists()
4141

@@ -50,7 +50,7 @@ def build(self):
5050
str(utils.get_full_dist_css_path()),
5151
"--minify",
5252
]
53-
if settings.TAILWIND_CLI_SRC_CSS is not None:
53+
if conf.get_tailwind_cli_src_css() is not None:
5454
build_cmd.extend(
5555
[
5656
"--input",
@@ -75,7 +75,7 @@ def watch(self):
7575
str(utils.get_full_dist_css_path()),
7676
"--watch",
7777
]
78-
if settings.TAILWIND_CLI_SRC_CSS is not None:
78+
if conf.get_tailwind_cli_src_css() is not None:
7979
watch_cmd.extend(
8080
[
8181
"--input",
@@ -89,7 +89,7 @@ def watch(self):
8989
self._write_success("Stopped watching for changes.")
9090

9191
@command(name="list_templates", help="List the templates of your django project.")
92-
def list_templates(self):
92+
def list_templates(self) -> None:
9393
template_files: list[str] = []
9494
app_template_dirs = get_app_template_dirs("templates")
9595
for app_template_dir in app_template_dirs:
@@ -272,8 +272,8 @@ def download_cli(self) -> None:
272272
dest_file = utils.get_full_cli_path()
273273
extra_msg = (
274274
""
275-
if settings.TAILWIND_CLI_SRC_REPO == DEFAULT_SRC_REPO
276-
else f" from '{settings.TAILWIND_CLI_SRC_REPO}'"
275+
if conf.get_tailwind_cli_src_repo() == conf.DEFAULT_SRC_REPO
276+
else f" from '{conf.get_tailwind_cli_src_repo()}'"
277277
)
278278

279279
if dest_file.exists():

src/django_tailwind_cli/templatetags/tailwind_cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
from typing import Union
44

55
from django import template
6+
from django.conf import settings
67

7-
from django_tailwind_cli.conf import settings
8+
from django_tailwind_cli import conf
89

910
register = template.Library()
1011

1112

1213
@register.inclusion_tag("tailwind_cli/tailwind_css.html")
1314
def tailwind_css() -> dict[str, Union[bool, str]]:
1415
"""Template tag to include the css files into the html templates."""
15-
return {"debug": settings.DEBUG, "tailwind_dist_css": settings.TAILWIND_CLI_DIST_CSS}
16+
return {"debug": settings.DEBUG, "tailwind_dist_css": conf.get_tailwind_cli_dist_css()}

src/django_tailwind_cli/utils.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import platform
1010
from pathlib import Path
1111

12-
from django_tailwind_cli.conf import settings
12+
from django.conf import settings
13+
14+
from django_tailwind_cli import conf
1315

1416

1517
def get_system_and_machine() -> tuple[str, str]:
@@ -32,15 +34,17 @@ def get_download_url() -> str:
3234
system, machine = get_system_and_machine()
3335
extension = ".exe" if system == "windows" else ""
3436
return (
35-
f"https://github.com/{settings.TAILWIND_CLI_SRC_REPO}/releases/download/"
36-
f"v{settings.TAILWIND_CLI_VERSION}/{settings.TAILWIND_CLI_ASSET_NAME}-{system}-{machine}{extension}"
37+
f"https://github.com/{conf.get_tailwind_cli_src_repo}/releases/download/"
38+
f"v{conf.get_tailwind_cli_version()}/{conf.get_tailwind_cli_asset_name()}-{system}-{machine}{extension}"
3739
)
3840

3941

4042
def get_full_cli_path() -> Path:
4143
"""Get path to the Tailwind CSS CLI."""
4244

43-
cli_path = Path(settings.TAILWIND_CLI_PATH).expanduser() if settings.TAILWIND_CLI_PATH else None
45+
cli_path = (
46+
Path(conf.get_tailwind_cli_path()).expanduser() if conf.get_tailwind_cli_path() else None
47+
)
4448

4549
# If Tailwind CSS CLI path points to an existing executable use is.
4650
if cli_path and cli_path.exists() and cli_path.is_file() and os.access(cli_path, os.X_OK):
@@ -49,7 +53,7 @@ def get_full_cli_path() -> Path:
4953
# Otherwise try to calculate the full cli path as usual.
5054
system, machine = get_system_and_machine()
5155
extension = ".exe" if system == "windows" else ""
52-
executable_name = f"tailwindcss-{system}-{machine}-{settings.TAILWIND_CLI_VERSION}{extension}"
56+
executable_name = f"tailwindcss-{system}-{machine}-{conf.get_tailwind_cli_version()}{extension}"
5357
if cli_path is None:
5458
return Path(settings.BASE_DIR) / executable_name
5559
else:
@@ -58,10 +62,11 @@ def get_full_cli_path() -> Path:
5862

5963
def get_full_src_css_path() -> Path:
6064
"""Get path to the source css."""
61-
if settings.TAILWIND_CLI_SRC_CSS is None:
65+
cli_src_css = conf.get_tailwind_cli_src_css()
66+
if cli_src_css is None:
6267
msg = "No source CSS file specified. Please set TAILWIND_SRC_CSS in your settings."
6368
raise ValueError(msg)
64-
return Path(settings.BASE_DIR) / settings.TAILWIND_CLI_SRC_CSS
69+
return Path(settings.BASE_DIR) / cli_src_css
6570

6671

6772
def get_full_dist_css_path() -> Path:
@@ -70,12 +75,12 @@ def get_full_dist_css_path() -> Path:
7075
msg = "STATICFILES_DIRS is empty. Please add a path to your static files."
7176
raise ValueError(msg)
7277

73-
return Path(settings.STATICFILES_DIRS[0]) / settings.TAILWIND_CLI_DIST_CSS
78+
return Path(settings.STATICFILES_DIRS[0]) / conf.get_tailwind_cli_dist_css()
7479

7580

7681
def get_full_config_file_path() -> Path:
7782
"""Get path to the tailwind.config.js file."""
78-
return Path(settings.BASE_DIR) / settings.TAILWIND_CLI_CONFIG_FILE
83+
return Path(settings.BASE_DIR) / conf.get_tailwind_cli_config_file()
7984

8085

8186
def validate_settings() -> None:

tests/test_conf.py

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

0 commit comments

Comments
 (0)