django-tailwind-cli 4.8.2__tar.gz → 4.8.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/.github/dependabot.yml +4 -0
  2. django_tailwind_cli-4.8.3/.github/workflows/dependabot-auto-merge.yml +34 -0
  3. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/.github/workflows/release.yml +1 -1
  4. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/.github/workflows/test.yml +18 -5
  5. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/CHANGELOG.md +7 -0
  6. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/PKG-INFO +1 -1
  7. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/docs/settings.md +2 -0
  8. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/docs/usage.md +5 -3
  9. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/management/commands/_build.py +20 -15
  10. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/management/commands/_process.py +23 -2
  11. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/management/commands/_source_css.py +10 -5
  12. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/conftest.py +19 -0
  13. django_tailwind_cli-4.8.3/tests/helpers.py +106 -0
  14. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/test_integration.py +104 -1
  15. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/test_management_commands.py +35 -0
  16. django_tailwind_cli-4.8.2/tests/helpers.py +0 -46
  17. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/.gitignore +0 -0
  18. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/.mise/tasks/dev +0 -0
  19. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/.pre-commit-config.yaml +0 -0
  20. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/.readthedocs.yml +0 -0
  21. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/CODE_OF_CONDUCT.md +0 -0
  22. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/CONTRIBUTING.md +0 -0
  23. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/LICENSE +0 -0
  24. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/README.md +0 -0
  25. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/docs/base_template.md +0 -0
  26. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/docs/changelog.md +0 -0
  27. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/docs/conf.py +0 -0
  28. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/docs/contributing.md +0 -0
  29. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/docs/index.md +0 -0
  30. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/docs/installation.md +0 -0
  31. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/docs/requirements.txt +0 -0
  32. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/docs/template_tags.md +0 -0
  33. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/docs/whitenoise.md +0 -0
  34. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/docs/workflow.md +0 -0
  35. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/mise.toml +0 -0
  36. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/pyproject.toml +0 -0
  37. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/__init__.py +0 -0
  38. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/apps.py +0 -0
  39. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/checks.py +0 -0
  40. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/config.py +0 -0
  41. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/management/__init__.py +0 -0
  42. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/management/commands/__init__.py +0 -0
  43. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/management/commands/_download.py +0 -0
  44. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/management/commands/_errors.py +0 -0
  45. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/management/commands/_group.py +0 -0
  46. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/management/commands/_guides.py +0 -0
  47. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/management/commands/tailwind.py +0 -0
  48. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/py.typed +0 -0
  49. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/templates/tailwind_cli/base.html +0 -0
  50. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/templates/tailwind_cli/tailwind_css.html +0 -0
  51. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/templatetags/__init__.py +0 -0
  52. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/templatetags/tailwind_cli.py +0 -0
  53. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/utils/__init__.py +0 -0
  54. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/src/django_tailwind_cli/utils/http.py +0 -0
  55. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/.gitignore +0 -0
  56. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/__init__.py +0 -0
  57. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/assets/css/.gitkeep +0 -0
  58. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/assets/css/tailwind.css +0 -0
  59. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/settings.py +0 -0
  60. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/templates/tests/base.html +0 -0
  61. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/templates/tests/dummy.email +0 -0
  62. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/test_additional_commands.py +0 -0
  63. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/test_checks.py +0 -0
  64. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/test_config.py +0 -0
  65. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/test_error_scenarios.py +0 -0
  66. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/test_http.py +0 -0
  67. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tests/test_tailwind_css_tag.py +0 -0
  68. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/tox.ini +0 -0
  69. {django_tailwind_cli-4.8.2 → django_tailwind_cli-4.8.3}/uv.lock +0 -0
@@ -6,6 +6,10 @@ updates:
6
6
  interval: "weekly"
7
7
  cooldown:
8
8
  default-days: 7
9
+ groups:
10
+ github-actions:
11
+ patterns:
12
+ - "*"
9
13
 
10
14
  - package-ecosystem: "pip"
11
15
  directory: "/"
@@ -0,0 +1,34 @@
1
+ name: Dependabot auto-merge
2
+
3
+ # pull_request rather than pull_request_target: the job needs no secrets, and
4
+ # Dependabot pull requests honour the permissions block below.
5
+ on:
6
+ pull_request:
7
+
8
+ permissions: {}
9
+
10
+ jobs:
11
+ auto-merge:
12
+ name: Enable auto-merge
13
+ runs-on: ubuntu-latest
14
+ # The pull request author, not github.actor, which a re-run by anyone changes.
15
+ if: github.event.pull_request.user.login == 'dependabot[bot]'
16
+ permissions:
17
+ contents: write # gh pr merge needs it to merge into main
18
+ pull-requests: write # gh pr merge --auto enables auto-merge on the PR
19
+ steps:
20
+ - name: Fetch Dependabot metadata
21
+ id: metadata
22
+ uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
23
+
24
+ # Only action bumps below a major version. PR CI never runs release.yml,
25
+ # so a major bump of an action used there would pass unseen.
26
+ # The main ruleset holds the merge until the ci-ok check passes.
27
+ - name: Enable auto-merge for patch and minor action updates
28
+ if: >-
29
+ steps.metadata.outputs.package-ecosystem == 'github_actions' &&
30
+ steps.metadata.outputs.update-type != 'version-update:semver-major'
31
+ run: gh pr merge --auto --squash "$PR_URL"
32
+ env:
33
+ PR_URL: ${{ github.event.pull_request.html_url }}
34
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -25,7 +25,7 @@ jobs:
25
25
  with:
26
26
  persist-credentials: false
27
27
  - name: Set up Python
28
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
28
+ uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
29
29
  with:
30
30
  python-version: "3.x"
31
31
  - name: Install pypa/build
@@ -32,7 +32,7 @@ jobs:
32
32
  persist-credentials: false
33
33
 
34
34
  - name: Set up mise
35
- uses: jdx/mise-action@9b200bcecbfd6303e69a4a261b2e09e3757440a7 # v5.2.0
35
+ uses: jdx/mise-action@b44d12e7d0d8ee7461bb893e1b1993500433185b # v5.2.7
36
36
  with:
37
37
  install: true
38
38
  cache: true
@@ -91,7 +91,7 @@ jobs:
91
91
  persist-credentials: false
92
92
 
93
93
  - name: Set up mise
94
- uses: jdx/mise-action@9b200bcecbfd6303e69a4a261b2e09e3757440a7 # v5.2.0
94
+ uses: jdx/mise-action@b44d12e7d0d8ee7461bb893e1b1993500433185b # v5.2.7
95
95
  with:
96
96
  install: true
97
97
  cache: true
@@ -126,7 +126,7 @@ jobs:
126
126
  persist-credentials: false
127
127
 
128
128
  - name: Set up mise
129
- uses: jdx/mise-action@9b200bcecbfd6303e69a4a261b2e09e3757440a7 # v5.2.0
129
+ uses: jdx/mise-action@b44d12e7d0d8ee7461bb893e1b1993500433185b # v5.2.7
130
130
  with:
131
131
  install: true
132
132
  cache: true
@@ -162,7 +162,7 @@ jobs:
162
162
  persist-credentials: false
163
163
 
164
164
  - name: Set up mise
165
- uses: jdx/mise-action@9b200bcecbfd6303e69a4a261b2e09e3757440a7 # v5.2.0
165
+ uses: jdx/mise-action@b44d12e7d0d8ee7461bb893e1b1993500433185b # v5.2.7
166
166
  with:
167
167
  install: true
168
168
  cache: true
@@ -190,4 +190,17 @@ jobs:
190
190
  with:
191
191
  persist-credentials: false
192
192
 
193
- - uses: zizmorcore/zizmor-action@85b2b9fb8e3325e7a23d7d0a9d7ba5ae0f999e3e # v0.7.1
193
+ - uses: zizmorcore/zizmor-action@45d7276c9ca790aabd705e31ca99c6185c3e76dd # v0.8.1
194
+
195
+ # The main ruleset requires this one check instead of every job, so a new
196
+ # matrix entry needs no ruleset change. always() is required: a job skipped
197
+ # after a failed dependency reports as passing to a required status check.
198
+ ci-ok:
199
+ name: ci-ok
200
+ if: always()
201
+ needs: [lint, build, coverage, docs, zizmor]
202
+ runs-on: ubuntu-latest
203
+ steps:
204
+ - name: Fail unless every job succeeded
205
+ if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped')
206
+ run: exit 1
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.8.3 (2026-11-18)
4
+
5
+ ### 🐛 Bug Fixes
6
+ - **`tailwind watch` keeps watching without a terminal.** The Tailwind 4 CLI stops `--watch` when its stdin closes. A parallel `mise run` task or a container without `tty: true` has no open stdin. There the watcher stopped after the first build. The CLI now reads stdin from a pipe that only the Python process holds. This also fixes `tailwind runserver`, which starts `tailwind watch`.
7
+ - **The Tailwind CLI exits with `tailwind watch` and `tailwind runserver`.** A SIGTERM or SIGINT sent to the command alone left the CLI running. Only Ctrl+C in a terminal, which signals the whole process group, stopped it. Now the CLI exits on both signals.
8
+ - **Generated source CSS uses UTF-8 on every platform.** External app paths containing non-ASCII characters no longer fail to write on Windows, and existing UTF-8 source files can be checked and backed up without decoding errors. Backups preserve the original bytes.
9
+
3
10
  ## 4.8.2 (2026-10-27)
4
11
 
5
12
  ### 🐛 Bug Fixes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: django-tailwind-cli
3
- Version: 4.8.2
3
+ Version: 4.8.3
4
4
  Summary: Django and Tailwind integration based on the prebuilt Tailwind CSS CLI.
5
5
  Project-URL: Home, https://django-tailwind-cli.rtfd.io/
6
6
  Project-URL: Documentation, https://django-tailwind-cli.rtfd.io/
@@ -79,6 +79,8 @@ This setting only affects the **auto-generated** default source CSS. If you set
79
79
 
80
80
  The list of external apps is re-evaluated whenever the source CSS is written. When combined with the `tailwind watch` auto-reloader, installing a new app or editing `INSTALLED_APPS` automatically regenerates the declarations and triggers a Tailwind rebuild.
81
81
 
82
+ Generated source CSS uses UTF-8 on every platform, including when external app paths contain non-ASCII characters.
83
+
82
84
  ### TAILWIND_CLI_USE_SYSTEM_BINARY
83
85
 
84
86
  **Default**: `False`
@@ -34,6 +34,8 @@ Run `python manage.py tailwind watch` to start a Tailwind watcher process on its
34
34
 
35
35
  By default the watch command runs under Django's own auto-reloader (the same one `runserver` uses). Whenever you change a Python file — including `settings.py` — the watcher restarts its Python process, regenerates the default source CSS file (picking up freshly added `INSTALLED_APPS`), and respawns the Tailwind CLI subprocess. This pairs nicely with [`TAILWIND_CLI_AUTO_SOURCE_EXTERNAL_APPS`](settings.md#tailwind_cli_auto_source_external_apps): adding an editable-installed app and updating `INSTALLED_APPS` is enough — no manual restart needed.
36
36
 
37
+ The watch command does not need a terminal or an open stdin. It runs as a parallel task under `mise run` or in a Docker container without `tty: true`. The Tailwind CLI stops watching when its stdin closes. The command therefore gives it a pipe that only the Python process holds. On SIGTERM or SIGINT to `tailwind watch` or `tailwind runserver`, the Tailwind CLI exits too. A SIGKILL to the command skips the cleanup of Django's auto-reloader, and its child process keeps running. With `--noreload`, the Tailwind CLI exits on SIGKILL too.
38
+
37
39
  Pass `--noreload` if you want a single-process watch loop (e.g. in CI or when debugging the watcher itself):
38
40
 
39
41
  ```bash
@@ -130,20 +132,20 @@ Run `python manage.py tailwind remove_cli` to remove the installed CLI binary. T
130
132
 
131
133
  ## Use with Docker Compose
132
134
 
133
- When used in the `watch` mode, the Tailwind CLI requires a TTY-enabled environment to function correctly. In a Docker Compose setup, ensure that the container executing the Tailwind style rebuild command (either `python manage.py tailwind runserver` or `python manage.py tailwind watch`, as noted above) is configured with the `tty: true` setting in your `docker-compose.yml`.
135
+ Both `python manage.py tailwind runserver` and `python manage.py tailwind watch` run in a container without further settings:
134
136
 
135
137
  ```yaml
136
138
  web:
137
139
  command: python manage.py tailwind runserver
138
- tty: true
139
140
 
140
141
  # or
141
142
 
142
143
  tailwind-sidecar:
143
144
  command: python manage.py tailwind watch
144
- tty: true
145
145
  ```
146
146
 
147
+ Versions before 4.8.3 need `tty: true` on that service. Without it the watcher stops right after the first build.
148
+
147
149
  ## Use with WhiteNoise
148
150
 
149
151
  [WhiteNoise](https://whitenoise.readthedocs.io/) works with the defaults of this library and needs no extra configuration. See [Use with WhiteNoise](whitenoise.md) for a sample configuration and the traps around `collectstatic`.
@@ -15,7 +15,7 @@ from django.core.management.base import CommandError
15
15
 
16
16
  from django_tailwind_cli.config import get_config
17
17
  from django_tailwind_cli.management.commands._download import ensure_cli_binary, ensure_default_gitignore
18
- from django_tailwind_cli.management.commands._process import MultiWatchProcessManager
18
+ from django_tailwind_cli.management.commands._process import MultiWatchProcessManager, watcher_stdin
19
19
  from django_tailwind_cli.management.commands._source_css import ensure_source_css
20
20
 
21
21
 
@@ -44,19 +44,21 @@ def run_watch_loop(*, verbose: bool = False) -> None:
44
44
  if verbose:
45
45
  click.secho("🔄 Starting file watcher...", fg="cyan")
46
46
 
47
- if len(config.css_entries) == 1:
48
- execute_tailwind_command(
49
- config.watch_cmd,
50
- success_message="Stopped watching for changes.",
51
- error_message="Failed to start in watch mode",
52
- # The watcher runs until Ctrl+C: its rebuilds and errors belong on the terminal, and a
53
- # captured pipe would only grow for as long as it runs.
54
- capture_output=False,
55
- verbose=verbose,
56
- )
57
- else:
58
- manager = MultiWatchProcessManager()
59
- manager.start_watch_processes(config, verbose=verbose)
47
+ with watcher_stdin() as stdin:
48
+ if len(config.css_entries) == 1:
49
+ execute_tailwind_command(
50
+ config.watch_cmd,
51
+ success_message="Stopped watching for changes.",
52
+ error_message="Failed to start in watch mode",
53
+ # The watcher runs until Ctrl+C: its rebuilds and errors belong on the terminal, and a
54
+ # captured pipe would only grow for as long as it runs.
55
+ capture_output=False,
56
+ stdin=stdin,
57
+ verbose=verbose,
58
+ )
59
+ else:
60
+ manager = MultiWatchProcessManager()
61
+ manager.start_watch_processes(config, stdin=stdin, verbose=verbose)
60
62
 
61
63
 
62
64
  def setup_tailwind_environment(*, verbose: bool = False) -> None:
@@ -74,6 +76,7 @@ def execute_tailwind_command(
74
76
  success_message: str,
75
77
  error_message: str,
76
78
  capture_output: bool = True,
79
+ stdin: int | None = None,
77
80
  verbose: bool = False,
78
81
  ) -> bool:
79
82
  """Execute a Tailwind command with consistent error handling and optional verbose output.
@@ -83,6 +86,8 @@ def execute_tailwind_command(
83
86
  success_message: Message to display on success.
84
87
  error_message: Message prefix for errors.
85
88
  capture_output: Whether to capture subprocess output.
89
+ stdin: File descriptor for the command's stdin. Applies only with ``capture_output=False``,
90
+ the watch path. None inherits this process's stdin.
86
91
  verbose: Whether to show detailed execution information.
87
92
 
88
93
  Returns:
@@ -104,7 +109,7 @@ def execute_tailwind_command(
104
109
  click.secho("📤 Command output:", fg="blue")
105
110
  click.echo(result.stdout)
106
111
  else:
107
- subprocess.run(cmd, cwd=settings.BASE_DIR, check=True)
112
+ subprocess.run(cmd, cwd=settings.BASE_DIR, check=True, stdin=stdin)
108
113
 
109
114
  if verbose:
110
115
  end_time = time.time()
@@ -8,13 +8,15 @@ one place and the two entry points differ only in what they start and how they r
8
8
 
9
9
  from __future__ import annotations
10
10
 
11
+ import os
11
12
  import re
12
13
  import signal
13
14
  import sys
14
15
  import subprocess
15
16
  import threading
16
17
  import time
17
- from collections.abc import Callable
18
+ from collections.abc import Callable, Iterator
19
+ from contextlib import contextmanager
18
20
  from types import FrameType
19
21
  from typing import IO
20
22
 
@@ -51,6 +53,23 @@ _BUN_NOISE = re.compile(
51
53
  _WATCH_SPAWN_STAGGER_S = 0.3
52
54
 
53
55
 
56
+ @contextmanager
57
+ def watcher_stdin() -> Iterator[int]:
58
+ """Yield the read end of a pipe whose write end only this process holds, as a watcher's stdin.
59
+
60
+ The Tailwind 4 CLI ends `--watch` when its stdin reaches EOF. An inherited stdin can be at EOF
61
+ from the start, for example in a parallel `mise run` task. This pipe reaches EOF only when its
62
+ write end closes. That happens on leaving this block or when this process dies, also by
63
+ SIGKILL. The CLI then stops watching, so it does not outlive this process.
64
+ """
65
+ read_fd, write_fd = os.pipe()
66
+ try:
67
+ yield read_fd
68
+ finally:
69
+ os.close(write_fd)
70
+ os.close(read_fd)
71
+
72
+
54
73
  def _is_bun_noise(line: str) -> bool:
55
74
  """Return True if the line looks like a Bun native-runtime crash trace."""
56
75
  return bool(_BUN_NOISE.match(line))
@@ -195,11 +214,12 @@ class MultiWatchProcessManager(_BaseProcessManager):
195
214
  def _exit_notice(self, index: int, returncode: int) -> str:
196
215
  return f"Watch process {index} exited with code {returncode}"
197
216
 
198
- def start_watch_processes(self, config: Config, *, verbose: bool = False) -> None:
217
+ def start_watch_processes(self, config: Config, *, stdin: int | None = None, verbose: bool = False) -> None:
199
218
  """Start watch processes for all CSS entries.
200
219
 
201
220
  Args:
202
221
  config: Configuration object with css_entries.
222
+ stdin: File descriptor for every watcher's stdin, see `watcher_stdin`. None inherits it.
203
223
  verbose: Whether to show detailed information.
204
224
  """
205
225
  # SIGINT propagates as KeyboardInterrupt via Python's default handler.
@@ -228,6 +248,7 @@ class MultiWatchProcessManager(_BaseProcessManager):
228
248
  watch_cmd,
229
249
  cwd=settings.BASE_DIR,
230
250
  text=True,
251
+ stdin=stdin,
231
252
  stderr=subprocess.PIPE,
232
253
  )
233
254
  self.processes.append(process)
@@ -36,7 +36,7 @@ def _should_recreate_file(file_path: Path, content: str) -> bool:
36
36
  return True
37
37
 
38
38
  try:
39
- current_content = file_path.read_text()
39
+ current_content = file_path.read_text(encoding="utf-8")
40
40
  if current_content != content:
41
41
  return True
42
42
  except (OSError, UnicodeDecodeError):
@@ -165,7 +165,7 @@ def _preserve_hand_edits(src_css: Path) -> None:
165
165
  managed directory, which carries its own ``.gitignore``.
166
166
  """
167
167
  backup = src_css.with_suffix(".css.bak")
168
- backup.write_text(src_css.read_text())
168
+ backup.write_bytes(src_css.read_bytes())
169
169
 
170
170
  click.secho(
171
171
  f"⚠️ '{src_css}' has hand edits that are about to be replaced.",
@@ -239,14 +239,19 @@ def _ensure_one_source_css(src_css: Path, content: str, *, manages_the_file: boo
239
239
  click.secho("⏭️ Source CSS file is up-to-date, no changes needed", fg="green")
240
240
  return False
241
241
 
242
- if manages_the_file and src_css.exists() and not _looks_auto_generated(src_css.read_text()):
243
- _preserve_hand_edits(src_css)
242
+ if manages_the_file and src_css.exists():
243
+ try:
244
+ generated = _looks_auto_generated(src_css.read_text(encoding="utf-8"))
245
+ except UnicodeDecodeError:
246
+ generated = False
247
+ if not generated:
248
+ _preserve_hand_edits(src_css)
244
249
 
245
250
  if verbose:
246
251
  click.secho("📝 Creating/updating source CSS file...", fg="cyan")
247
252
 
248
253
  src_css.parent.mkdir(parents=True, exist_ok=True)
249
- src_css.write_text(content)
254
+ src_css.write_text(content, encoding="utf-8")
250
255
 
251
256
  if verbose:
252
257
  click.secho(f"✅ Created directory: {src_css.parent}", fg="green")
@@ -1,6 +1,7 @@
1
1
  """Shared fixtures for the test suite."""
2
2
 
3
3
  import hashlib
4
+ import os
4
5
  import socket
5
6
  from collections.abc import Iterator
6
7
  from pathlib import Path
@@ -188,6 +189,24 @@ def no_writes_into_the_checkout() -> Iterator[None]:
188
189
  )
189
190
 
190
191
 
192
+ @pytest.fixture
193
+ def stdin_from_dev_null() -> Iterator[None]:
194
+ """Point file descriptor 0 at /dev/null, as a task runner without a terminal does.
195
+
196
+ pytest's default fd capture does the same. Under ``-s``, fd 0 is the terminal instead.
197
+ This fixture makes the test independent of the capture mode.
198
+ """
199
+ saved = os.dup(0)
200
+ devnull = os.open(os.devnull, os.O_RDONLY)
201
+ os.dup2(devnull, 0)
202
+ os.close(devnull)
203
+ try:
204
+ yield
205
+ finally:
206
+ os.dup2(saved, 0)
207
+ os.close(saved)
208
+
209
+
191
210
  @pytest.fixture
192
211
  def stub_subprocess_run(mocker: MockerFixture) -> MagicMock:
193
212
  """A `subprocess.run` that succeeds and says nothing.
@@ -0,0 +1,106 @@
1
+ """Helpers shared across test modules.
2
+
3
+ Plain functions live here rather than in ``conftest.py``: pytest loads that module itself, and
4
+ importing from it is a pytest anti-pattern. Fixtures still belong in ``conftest.py``.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import sys
10
+ from collections.abc import Callable
11
+ from pathlib import Path
12
+
13
+
14
+ def write_fake_cli(
15
+ url: str,
16
+ filepath: Path,
17
+ timeout: int = 30,
18
+ progress_callback: Callable[[int, int, float], None] | None = None,
19
+ *,
20
+ content: bytes = b"fake-cli-binary",
21
+ ) -> None:
22
+ """Stand-in for ``http.download_with_progress`` that just puts bytes at the target path.
23
+
24
+ The signature mirrors the real function because it is installed as a ``side_effect``, so it is
25
+ called with the production call's arguments. ``content`` is keyword-only, which keeps it clear
26
+ of that call.
27
+
28
+ No chmod: the caller does that itself right after the download returns
29
+ (``ensure_cli_binary``), so a stub that sets the mode only hides whether it does.
30
+
31
+ Args:
32
+ content: Bytes to write. Tests that assert on the file's content pass their own.
33
+ """
34
+ filepath.parent.mkdir(parents=True, exist_ok=True)
35
+ filepath.write_bytes(content)
36
+
37
+
38
+ def install_fake_cli(path: Path, *, content: bytes = b"fake-cli-binary") -> Path:
39
+ """Put an executable fake CLI binary at ``path``, as if it had already been installed.
40
+
41
+ Not the same function as ``write_fake_cli``, and the chmod is why — see its docstring above.
42
+ This one claims the binary is already there, so the executable bit is part of the claim.
43
+ """
44
+ path.parent.mkdir(parents=True, exist_ok=True)
45
+ path.write_bytes(content)
46
+ path.chmod(0o755)
47
+ return path
48
+
49
+
50
+ # Shared start of the fake CLIs below: answer `--help` with a version line, otherwise find `--output`.
51
+ _FAKE_CLI_PREAMBLE = """\
52
+ import os
53
+ import select
54
+ import sys
55
+
56
+ if "--watch" not in sys.argv:
57
+ print("tailwindcss v4.0.0")
58
+ sys.exit(0)
59
+ output_path = sys.argv[sys.argv.index("--output") + 1]
60
+ os.makedirs(os.path.dirname(output_path), exist_ok=True)
61
+ """
62
+
63
+ _STDIN_PROBE_TAIL = """\
64
+ ready, _, _ = select.select([sys.stdin], [], [], 0.1)
65
+ state = "eof" if ready and sys.stdin.buffer.read(1) == b"" else "open"
66
+ with open(output_path, "w") as output:
67
+ output.write(state)
68
+ """
69
+
70
+ _STDIN_WAIT_TAIL = """\
71
+ with open(output_path, "w") as output:
72
+ output.write(str(os.getpid()))
73
+ sys.stdin.buffer.read()
74
+ """
75
+
76
+
77
+ def _install_python_cli(path: Path, tail: str) -> Path:
78
+ """Put an executable fake CLI at ``path`` that runs the preamble plus ``tail`` with this interpreter.
79
+
80
+ A ``/bin/sh`` wrapper rather than a ``#!python`` shebang: the kernel rejects a shebang with
81
+ spaces in the interpreter path or one longer than its limit.
82
+ """
83
+ script_path = path.with_name(f"{path.name}.py")
84
+ script_path.parent.mkdir(parents=True, exist_ok=True)
85
+ script_path.write_text(_FAKE_CLI_PREAMBLE + tail)
86
+ wrapper = f'#!/bin/sh\nexec "{sys.executable}" -I -S "{script_path}" "$@"\n'
87
+ return install_fake_cli(path, content=wrapper.encode())
88
+
89
+
90
+ def install_stdin_probe_cli(path: Path) -> Path:
91
+ """Put an executable fake CLI at ``path`` that reports its stdin state when watching.
92
+
93
+ The Tailwind 4 CLI ends ``--watch`` once stdin reaches EOF. This fake writes ``eof`` or
94
+ ``open`` to its ``--output`` file instead, then exits so the watch command returns.
95
+ POSIX only: ``select()`` on a pipe is not available on Windows.
96
+ """
97
+ return _install_python_cli(path, _STDIN_PROBE_TAIL)
98
+
99
+
100
+ def install_stdin_wait_cli(path: Path) -> Path:
101
+ """Put an executable fake CLI at ``path`` that watches until its stdin reaches EOF.
102
+
103
+ It writes its PID to its ``--output`` file, then blocks on stdin, as the Tailwind 4 CLI does.
104
+ POSIX only.
105
+ """
106
+ return _install_python_cli(path, _STDIN_WAIT_TAIL)
@@ -9,7 +9,11 @@ import io
9
9
  import os
10
10
  import platform
11
11
  import signal
12
+ import subprocess
13
+ import sys
12
14
  import threading
15
+ import time
16
+ from collections.abc import Callable
13
17
  from pathlib import Path
14
18
  from unittest.mock import Mock, patch
15
19
 
@@ -34,7 +38,7 @@ from django_tailwind_cli.management.commands._source_css import (
34
38
  DEFAULT_SOURCE_CSS,
35
39
  )
36
40
  from django_tailwind_cli.management.commands.tailwind import run_watch_loop
37
- from tests.helpers import write_fake_cli
41
+ from tests.helpers import install_stdin_probe_cli, install_stdin_wait_cli, write_fake_cli
38
42
 
39
43
 
40
44
  def _clear_legacy_css_settings(settings: LazySettings) -> None:
@@ -345,6 +349,26 @@ class TestWatchModeIntegration:
345
349
  assert not worker.is_alive(), "run_watch_loop did not terminate within 5s"
346
350
  assert not errors, f"run_watch_loop crashed in worker thread: {errors[0]!r}"
347
351
 
352
+ @pytest.mark.skipif(sys.platform == "win32", reason="select() does not accept pipes on Windows")
353
+ @pytest.mark.usefixtures("stdin_from_dev_null")
354
+ @pytest.mark.parametrize("css_map", [None, [("admin.css", "admin.output.css"), ("web.css", "web.output.css")]])
355
+ def test_watcher_stdin_stays_open_without_terminal(
356
+ self, settings: LazySettings, tmp_project: Path, mocker: MockerFixture, css_map: list[tuple[str, str]] | None
357
+ ):
358
+ """The Tailwind 4 CLI ends `--watch` on stdin EOF, which happens at once under `mise run`."""
359
+ if css_map:
360
+ settings.TAILWIND_CLI_CSS_MAP = css_map
361
+ _clear_legacy_css_settings(settings)
362
+ for src, _ in css_map:
363
+ (tmp_project / src).write_text('@import "tailwindcss";')
364
+ mocker.patch("django_tailwind_cli.management.commands._process._WATCH_SPAWN_STAGGER_S", 0)
365
+ install_stdin_probe_cli(settings.TAILWIND_CLI_PATH)
366
+
367
+ run_watch_loop()
368
+
369
+ entries = get_config().css_entries
370
+ assert [entry.dist_css.read_text() for entry in entries] == ["open"] * len(entries)
371
+
348
372
  @pytest.mark.parametrize(
349
373
  "entry_count,expected_staggers",
350
374
  [(2, 1), (3, 2), (4, 3)],
@@ -402,6 +426,85 @@ class TestWatchModeIntegration:
402
426
  assert "Stopped watching for changes." in captured.out
403
427
 
404
428
 
429
+ # Runs `run_watch_loop` in its own process, so the test can SIGKILL it. argv: BASE_DIR, "single" or "multi".
430
+ # Starts from tests.settings, as the suite does, and points the project at BASE_DIR like `tmp_project`.
431
+ _WATCH_PROCESS_SCRIPT = """\
432
+ import sys
433
+ from pathlib import Path
434
+
435
+ import django
436
+ from django.conf import settings
437
+
438
+ base = Path(sys.argv[1])
439
+ settings.BASE_DIR = base
440
+ settings.STATICFILES_DIRS = (base / "assets",)
441
+ settings.TAILWIND_CLI_PATH = base / "tailwindcss"
442
+ settings.TAILWIND_CLI_VERSION = "4.0.0"
443
+ if sys.argv[2] == "multi":
444
+ settings.TAILWIND_CLI_CSS_MAP = [("admin.css", "admin.output.css"), ("web.css", "web.output.css")]
445
+ django.setup()
446
+
447
+ from django_tailwind_cli.management.commands._build import run_watch_loop
448
+
449
+ run_watch_loop()
450
+ """
451
+
452
+
453
+ def _wait_for(condition: Callable[[], bool], what: str, timeout: float = 10) -> None:
454
+ deadline = time.monotonic() + timeout
455
+ while not condition():
456
+ assert time.monotonic() < deadline, f"timed out waiting for {what}"
457
+ time.sleep(0.05)
458
+
459
+
460
+ def _is_running(pid: int) -> bool:
461
+ try:
462
+ os.kill(pid, 0)
463
+ except ProcessLookupError:
464
+ return False
465
+ return True
466
+
467
+
468
+ @pytest.mark.skipif(sys.platform == "win32", reason="POSIX signals and pipes")
469
+ @pytest.mark.timeout(30)
470
+ @pytest.mark.parametrize(
471
+ "mode,outputs",
472
+ [("single", ["css/tailwind.css"]), ("multi", ["admin.output.css", "web.output.css"])],
473
+ )
474
+ def test_watcher_exits_when_the_watch_process_is_killed(tmp_path: Path, mode: str, outputs: list[str]):
475
+ """A watcher must not outlive the Python process that started it, even after SIGKILL."""
476
+ install_stdin_wait_cli(tmp_path / "tailwindcss")
477
+ (tmp_path / "admin.css").write_text('@import "tailwindcss";')
478
+ (tmp_path / "web.css").write_text('@import "tailwindcss";')
479
+ pid_files = [tmp_path / "assets" / output for output in outputs]
480
+ # The test holds this stdin open, as a terminal does, so only the watch command can end the watcher.
481
+ terminal_read, terminal_write = os.pipe()
482
+ watch_process = subprocess.Popen(
483
+ [sys.executable, "-c", _WATCH_PROCESS_SCRIPT, str(tmp_path), mode],
484
+ cwd=Path(__file__).resolve().parent.parent,
485
+ env={**os.environ, "DJANGO_SETTINGS_MODULE": "tests.settings"},
486
+ stdin=terminal_read,
487
+ stdout=subprocess.DEVNULL,
488
+ stderr=subprocess.DEVNULL,
489
+ )
490
+ os.close(terminal_read)
491
+ cli_pids: list[int] = []
492
+ try:
493
+ _wait_for(lambda: all(f.exists() and f.read_text() for f in pid_files), "the watchers to start")
494
+ cli_pids = [int(f.read_text()) for f in pid_files]
495
+
496
+ watch_process.kill()
497
+ watch_process.wait()
498
+
499
+ _wait_for(lambda: not any(_is_running(pid) for pid in cli_pids), "the watchers to exit", timeout=5)
500
+ finally:
501
+ os.close(terminal_write)
502
+ watch_process.kill()
503
+ watch_process.wait()
504
+ for pid in filter(_is_running, cli_pids):
505
+ os.kill(pid, signal.SIGKILL)
506
+
507
+
405
508
  class TestProcessManagerIntegration:
406
509
  """Test ProcessManager for runserver integration."""
407
510
 
@@ -710,6 +710,41 @@ pytestmark = [
710
710
  ]
711
711
 
712
712
 
713
+ class TestSourceCssEncoding:
714
+ @pytest.mark.parametrize("already_exists", [False, True])
715
+ def test_generated_unicode_source_is_written_once(self, tmp_path: Path, already_exists: bool):
716
+ from django_tailwind_cli.management.commands._source_css import _ensure_one_source_css
717
+
718
+ src_css = tmp_path / "source.css"
719
+ content = f'{DEFAULT_SOURCE_CSS}\n{AUTO_SOURCE_COMMENT}\n@source "/editable/\u0645\u0644\u0641\u0627\u062a";\n'
720
+ if already_exists:
721
+ src_css.write_bytes(content.encode("utf-8"))
722
+
723
+ assert _ensure_one_source_css(src_css, content, manages_the_file=True, verbose=False) is not already_exists
724
+ assert src_css.read_text(encoding="utf-8") == content
725
+ assert not _ensure_one_source_css(src_css, content, manages_the_file=True, verbose=False)
726
+ assert not src_css.with_suffix(".css.bak").exists()
727
+
728
+ @pytest.mark.parametrize(
729
+ "edited_bytes",
730
+ [
731
+ f'{DEFAULT_SOURCE_CSS}@source "../\u0645\u0644\u0641\u0627\u062a";\n'.encode(),
732
+ b'@import "tailwindcss";\n@source "../caf\xe9";\n',
733
+ ],
734
+ ids=["utf8", "legacy-encoding"],
735
+ )
736
+ def test_hand_edits_are_backed_up_without_changing_bytes(self, tmp_path: Path, edited_bytes: bytes):
737
+ from django_tailwind_cli.management.commands._source_css import _ensure_one_source_css
738
+
739
+ src_css = tmp_path / "source.css"
740
+ src_css.write_bytes(edited_bytes)
741
+
742
+ assert _ensure_one_source_css(src_css, DEFAULT_SOURCE_CSS, manages_the_file=True, verbose=False)
743
+
744
+ assert src_css.with_suffix(".css.bak").read_bytes() == edited_bytes
745
+ assert src_css.read_text(encoding="utf-8") == DEFAULT_SOURCE_CSS
746
+
747
+
713
748
  class TestSourceCssOverwriteWarning:
714
749
  """The managed source.css is overwritten; hand edits should not vanish silently."""
715
750
 
@@ -1,46 +0,0 @@
1
- """Helpers shared across test modules.
2
-
3
- Plain functions live here rather than in ``conftest.py``: pytest loads that module itself, and
4
- importing from it is a pytest anti-pattern. Fixtures still belong in ``conftest.py``.
5
- """
6
-
7
- from __future__ import annotations
8
-
9
- from collections.abc import Callable
10
- from pathlib import Path
11
-
12
-
13
- def write_fake_cli(
14
- url: str,
15
- filepath: Path,
16
- timeout: int = 30,
17
- progress_callback: Callable[[int, int, float], None] | None = None,
18
- *,
19
- content: bytes = b"fake-cli-binary",
20
- ) -> None:
21
- """Stand-in for ``http.download_with_progress`` that just puts bytes at the target path.
22
-
23
- The signature mirrors the real function because it is installed as a ``side_effect``, so it is
24
- called with the production call's arguments. ``content`` is keyword-only, which keeps it clear
25
- of that call.
26
-
27
- No chmod: the caller does that itself right after the download returns
28
- (``ensure_cli_binary``), so a stub that sets the mode only hides whether it does.
29
-
30
- Args:
31
- content: Bytes to write. Tests that assert on the file's content pass their own.
32
- """
33
- filepath.parent.mkdir(parents=True, exist_ok=True)
34
- filepath.write_bytes(content)
35
-
36
-
37
- def install_fake_cli(path: Path, *, content: bytes = b"fake-cli-binary") -> Path:
38
- """Put an executable fake CLI binary at ``path``, as if it had already been installed.
39
-
40
- Not the same function as ``write_fake_cli``, and the chmod is why — see its docstring above.
41
- This one claims the binary is already there, so the executable bit is part of the claim.
42
- """
43
- path.parent.mkdir(parents=True, exist_ok=True)
44
- path.write_bytes(content)
45
- path.chmod(0o755)
46
- return path