Skip to content

Commit 9f81973

Browse files
committed
Moved default storage location BASE_DIR/.django_tailwind_cli
1 parent 12e880c commit 9f81973

File tree

6 files changed

+27
-30
lines changed

6 files changed

+27
-30
lines changed

CHANGELOG.md

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

3+
## 4.2.3
4+
5+
- Reverted the decision to store the CLI and the default config file in proper platform dirs.
6+
7+
* Windows has issues with the paths or sometimes it is not possible to create them.
8+
* VSCode Tailwind Plugin relies on the the existance of the config within the current project.
9+
* Decision: Create a folder named `.django_tailwind_cli` within the project and store the files there.
10+
311
## 4.2.2
412

513
- Default configuration stored in the user cache directory is overwritten on every start of the debug server or other management command.

docs/settings.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ your project.
2525
```
2626

2727
`TAILWIND_CLI_PATH`
28-
: **Default**: `None`
28+
: **Default**: `.django_tailwind_cli`
2929

3030
This allows you to override the default of the library where to store the CLI binary.
3131

32-
The default behaviour is to store the CLI binary in the directory returned by this call `platformdirs.user_data_dir("django-tailwind-cli", "django-commons")`. Checkout [platformdirs](https://pypi.org/project/platformdirs/) for details.
32+
The default behaviour is to store the CLI binary in the hidden directory `.django_tailwind_cli` within the project.
3333

3434
But if you want to store it elsewhere or plan to use a custom build binary stored locally, change this setting either to a path to a directory or the full path to the binary. If it points to a directory, this is the download destination otherwise it directly tries to use the referenced binary.
3535

@@ -66,11 +66,9 @@ your project.
6666
> ```
6767

6868
`TAILWIND_CLI_SRC_CSS`
69-
**Default**: `None`
69+
**Default**: `.django_tailwind_cli/source.css`
7070

71-
This variable can be set to `None`, a relative path and an absolute path.
72-
73-
If it is set to `None`, the library creates file with the name `source.css` in the directory returned by this call `platformdirs.user_cache_dir("django-tailwind-cli", "django-commons")`. Checkout [platformdirs](https://pypi.org/project/platformdirs/) for details.
71+
This variable can be set to a relative path and an absolute path.
7472

7573
If it is a relative path it is assumed to be relative to `settings.BASE_DIR`. If `settings.BASE_DIR` is not defined or the file doesn't exist a `ValueError` is raised.
7674

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ requires-python = ">=3.9"
3030
dependencies = [
3131
"django>=4.0",
3232
"django-typer>=2.1.2",
33-
"platformdirs>=4.3.7",
3433
"requests>=2.32.3",
3534
"semver>=3.0.4",
3635
]

src/django_tailwind_cli/config.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from dataclasses import dataclass
44
from pathlib import Path
55

6-
import platformdirs
76
import requests
87
from django.conf import settings
98
from semver import Version
@@ -123,10 +122,14 @@ def get_config() -> Config:
123122
raise ValueError("TAILWIND_CLI_ASSET_NAME must not be None.")
124123

125124
# Determine the full path to the CLI
126-
cli_path = Path(
127-
getattr(settings, "TAILWIND_CLI_PATH", None)
128-
or platformdirs.user_data_dir("django-tailwind-cli", "django-commons")
129-
)
125+
cli_path = getattr(settings, "TAILWIND_CLI_PATH", None)
126+
if not cli_path:
127+
cli_path = ".django_tailwind_cli"
128+
129+
cli_path = Path(cli_path)
130+
if not cli_path.is_absolute():
131+
cli_path = Path(settings.BASE_DIR) / cli_path
132+
130133
if cli_path.exists() and cli_path.is_file() and os.access(cli_path, os.X_OK):
131134
cli_path = cli_path.expanduser().resolve()
132135
else:
@@ -150,15 +153,15 @@ def get_config() -> Config:
150153
# Determine the full path to the source css file.
151154
src_css = getattr(settings, "TAILWIND_CLI_SRC_CSS", None)
152155
if not src_css:
153-
user_cache_dir = platformdirs.user_cache_dir("django-tailwind-cli", "django-commons")
154-
src_css = Path(user_cache_dir) / "source.css"
156+
src_css = ".django_tailwind_cli/source.css"
155157
overwrite_default_config = True
156158
else:
157-
src_css = Path(src_css)
158-
if not src_css.is_absolute():
159-
src_css = Path(settings.BASE_DIR) / src_css
160159
overwrite_default_config = False
161160

161+
src_css = Path(src_css)
162+
if not src_css.is_absolute():
163+
src_css = Path(settings.BASE_DIR) / src_css
164+
162165
# Determine if the CLI should be downloaded automatically
163166
automatic_download = getattr(settings, "TAILWIND_CLI_AUTOMATIC_DOWNLOAD", True)
164167

tests/test_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ def test_get_version_with_unofficial_repo_and_version_3(settings: SettingsWrappe
7878
def test_default_config():
7979
c = get_config()
8080
assert c.version.major >= 4
81-
assert "django-tailwind-cli/tailwindcss" in str(c.cli_path)
81+
assert ".django_tailwind_cli/tailwindcss" in str(c.cli_path)
8282
assert c.version_str in str(c.cli_path)
8383
assert c.download_url.startswith(
8484
f"https://github.com/tailwindlabs/tailwindcss/releases/download/v{c.version_str}/tailwindcss-"
8585
)
8686
assert str(c.dist_css) == "/home/user/project/assets/css/tailwind.css"
8787
assert c.src_css is not None
88-
assert str(c.src_css).endswith("django-tailwind-cli/source.css")
88+
assert str(c.src_css).endswith(".django_tailwind_cli/source.css")
8989
assert c.overwrite_default_config
9090

9191

uv.lock

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)