Skip to content

Commit 12e880c

Browse files
committed
Default configuration in user cache directory is always overwritten.
1 parent 0022605 commit 12e880c

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 4.2.2
4+
5+
- Default configuration stored in the user cache directory is overwritten on every start of the debug server or other management command.
6+
37
## 4.2.1
48

59
- Bugfix for determining the latest release of the used version of Tailwind CSS.

src/django_tailwind_cli/config.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import platform
33
from dataclasses import dataclass
44
from pathlib import Path
5-
from typing import Optional
65

76
import platformdirs
87
import requests
@@ -20,7 +19,8 @@ class Config:
2019
download_url: str
2120
dist_css: Path
2221
dist_css_base: str
23-
src_css: Optional[Path]
22+
src_css: Path
23+
overwrite_default_config: bool = True
2424
automatic_download: bool = True
2525
use_daisy_ui: bool = False
2626

@@ -152,10 +152,12 @@ def get_config() -> Config:
152152
if not src_css:
153153
user_cache_dir = platformdirs.user_cache_dir("django-tailwind-cli", "django-commons")
154154
src_css = Path(user_cache_dir) / "source.css"
155+
overwrite_default_config = True
155156
else:
156157
src_css = Path(src_css)
157158
if not src_css.is_absolute():
158159
src_css = Path(settings.BASE_DIR) / src_css
160+
overwrite_default_config = False
159161

160162
# Determine if the CLI should be downloaded automatically
161163
automatic_download = getattr(settings, "TAILWIND_CLI_AUTOMATIC_DOWNLOAD", True)
@@ -169,6 +171,7 @@ def get_config() -> Config:
169171
dist_css=dist_css,
170172
dist_css_base=dist_css_base,
171173
src_css=src_css,
174+
overwrite_default_config=overwrite_default_config,
172175
automatic_download=automatic_download,
173176
use_daisy_ui=use_daisy_ui,
174177
)

src/django_tailwind_cli/management/commands/tailwind.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def _create_standard_config() -> None:
286286
"""Create a standard Tailwind CSS config file."""
287287
c = get_config()
288288

289-
if c.src_css and not c.src_css.exists():
289+
if c.src_css and (c.overwrite_default_config or not c.src_css.exists()):
290290
c.src_css.parent.mkdir(parents=True, exist_ok=True)
291291
if c.use_daisy_ui:
292292
c.src_css.write_text(DAISY_UI_SOURCE_CSS)

tests/test_config.py

+12
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ def test_default_config():
8686
assert str(c.dist_css) == "/home/user/project/assets/css/tailwind.css"
8787
assert c.src_css is not None
8888
assert str(c.src_css).endswith("django-tailwind-cli/source.css")
89+
assert c.overwrite_default_config
90+
91+
92+
@pytest.mark.parametrize(
93+
"src_path",
94+
["relative/source.css", "/absolute/src.css"],
95+
)
96+
def test_overwrite_src_css(settings: SettingsWrapper, src_path: str):
97+
settings.TAILWIND_CLI_SRC_CSS = src_path
98+
c = get_config()
99+
assert not c.overwrite_default_config
100+
assert str(c.src_css).endswith(src_path)
89101

90102

91103
def test_invalid_settings_for_staticfiles_dirs(settings: SettingsWrapper):

0 commit comments

Comments
 (0)