fasthtml-tailwindcss 4.3.3.post1__py3-none-any.whl
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.
- fasthtml_tailwindcss/__init__.py +42 -0
- fasthtml_tailwindcss/build.py +64 -0
- fasthtml_tailwindcss/client.py +128 -0
- fasthtml_tailwindcss/compiler.py +40 -0
- fasthtml_tailwindcss/config.py +57 -0
- fasthtml_tailwindcss/py.typed +0 -0
- fasthtml_tailwindcss/worker.py +122 -0
- fasthtml_tailwindcss-4.3.3.post1.dist-info/METADATA +153 -0
- fasthtml_tailwindcss-4.3.3.post1.dist-info/RECORD +12 -0
- fasthtml_tailwindcss-4.3.3.post1.dist-info/WHEEL +4 -0
- fasthtml_tailwindcss-4.3.3.post1.dist-info/entry_points.txt +2 -0
- fasthtml_tailwindcss-4.3.3.post1.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from collections.abc import Sequence
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from weakref import finalize
|
|
4
|
+
|
|
5
|
+
from fasthtml.common import Link, vurl
|
|
6
|
+
|
|
7
|
+
from .client import Session
|
|
8
|
+
from .config import configuration
|
|
9
|
+
|
|
10
|
+
__all__ = ["TailwindHead"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TailwindHead:
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
*,
|
|
17
|
+
watch: bool = False,
|
|
18
|
+
sources: Sequence[str | Path] | None = None,
|
|
19
|
+
input: str | Path | None = None,
|
|
20
|
+
css: str | None = None,
|
|
21
|
+
output: str | Path = "./static/tailwind.css",
|
|
22
|
+
) -> None:
|
|
23
|
+
self._config = configuration(
|
|
24
|
+
sources=sources, input=input, css=css, output=output
|
|
25
|
+
)
|
|
26
|
+
(Path(self._config.root) / self._config.output).parent.mkdir(
|
|
27
|
+
parents=True, exist_ok=True
|
|
28
|
+
)
|
|
29
|
+
self._session = Session(self._config) if watch else None
|
|
30
|
+
if self._session is not None:
|
|
31
|
+
finalize(self, self._session.close)
|
|
32
|
+
|
|
33
|
+
def __deepcopy__(self, memo):
|
|
34
|
+
return self
|
|
35
|
+
|
|
36
|
+
def __ft__(self):
|
|
37
|
+
if self._session is not None:
|
|
38
|
+
self._session.start()
|
|
39
|
+
if self._session.error:
|
|
40
|
+
raise RuntimeError(self._session.error)
|
|
41
|
+
path = "/" + self._config.output
|
|
42
|
+
return Link(rel="stylesheet", href=vurl(path, root=self._config.root))
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import importlib
|
|
3
|
+
import importlib.util
|
|
4
|
+
import os
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from .compiler import binary_path, input_css
|
|
10
|
+
from .config import STATE_DIRECTORY, TailwindConfig
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def app_head(specification: str):
|
|
14
|
+
module_name, separator, object_name = specification.partition(":")
|
|
15
|
+
if not separator or not module_name or not object_name:
|
|
16
|
+
raise ValueError("Use an application reference such as app.main:app")
|
|
17
|
+
sys.path.insert(0, str(Path.cwd()))
|
|
18
|
+
module_spec = importlib.util.find_spec(module_name)
|
|
19
|
+
if module_spec is None or module_spec.origin is None:
|
|
20
|
+
raise ModuleNotFoundError(f"Cannot locate application module {module_name!r}")
|
|
21
|
+
os.chdir(Path(module_spec.origin).resolve().parent)
|
|
22
|
+
sys.path.insert(0, str(Path.cwd()))
|
|
23
|
+
value = importlib.import_module(module_name)
|
|
24
|
+
for part in object_name.split("."):
|
|
25
|
+
value = getattr(value, part)
|
|
26
|
+
from . import TailwindHead
|
|
27
|
+
|
|
28
|
+
heads = [
|
|
29
|
+
item for item in getattr(value, "hdrs", ()) if isinstance(item, TailwindHead)
|
|
30
|
+
]
|
|
31
|
+
if len(heads) != 1:
|
|
32
|
+
raise ValueError("The application must have exactly one TailwindHead in hdrs")
|
|
33
|
+
return heads[0]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def build(config: TailwindConfig) -> None:
|
|
37
|
+
root = Path(config.root)
|
|
38
|
+
directory = root / STATE_DIRECTORY
|
|
39
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
40
|
+
source = directory / "build-input.css"
|
|
41
|
+
source.write_text(input_css(config), encoding="utf-8")
|
|
42
|
+
output = root / config.output
|
|
43
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
44
|
+
subprocess.run(
|
|
45
|
+
[str(binary_path()), "-i", str(source), "-o", str(output), "--minify"],
|
|
46
|
+
cwd=root,
|
|
47
|
+
env={**os.environ, "NO_COLOR": "1"},
|
|
48
|
+
check=True,
|
|
49
|
+
)
|
|
50
|
+
print(f"Built {output}")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def main() -> None:
|
|
54
|
+
parser = argparse.ArgumentParser(prog="fasthtml-tailwindcss")
|
|
55
|
+
commands = parser.add_subparsers(dest="command", required=True)
|
|
56
|
+
build_command = commands.add_parser("build")
|
|
57
|
+
build_command.add_argument(
|
|
58
|
+
"app", help="Python app reference, for example app.main:app"
|
|
59
|
+
)
|
|
60
|
+
build(app_head(parser.parse_args().app)._config)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
main()
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import subprocess
|
|
3
|
+
import sys
|
|
4
|
+
import time
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from threading import Event, Lock, Thread
|
|
7
|
+
|
|
8
|
+
from filelock import FileLock, Timeout
|
|
9
|
+
|
|
10
|
+
from .compiler import stop_process
|
|
11
|
+
from .config import TailwindConfig, config_json, state_directory
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def running(directory: Path) -> bool:
|
|
15
|
+
try:
|
|
16
|
+
with FileLock(str(directory / "worker.lock"), timeout=0):
|
|
17
|
+
return False
|
|
18
|
+
except Timeout:
|
|
19
|
+
return True
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Session:
|
|
23
|
+
def __init__(self, config: TailwindConfig):
|
|
24
|
+
self.config_text = config_json(config)
|
|
25
|
+
self.directory = state_directory(config)
|
|
26
|
+
self.output = Path(config.root) / config.output
|
|
27
|
+
self.error = ""
|
|
28
|
+
self._closed = Event()
|
|
29
|
+
self._start_lock = Lock()
|
|
30
|
+
self._thread = Thread(target=self.heartbeat, daemon=True)
|
|
31
|
+
self._started = False
|
|
32
|
+
|
|
33
|
+
def start(self) -> None:
|
|
34
|
+
with self._start_lock:
|
|
35
|
+
if self._started:
|
|
36
|
+
return
|
|
37
|
+
self.connect()
|
|
38
|
+
self._thread.start()
|
|
39
|
+
try:
|
|
40
|
+
self.wait_for_css()
|
|
41
|
+
self._started = True
|
|
42
|
+
except BaseException:
|
|
43
|
+
self.close()
|
|
44
|
+
raise
|
|
45
|
+
|
|
46
|
+
def connect(self) -> None:
|
|
47
|
+
self.directory.mkdir(parents=True, exist_ok=True)
|
|
48
|
+
with FileLock(str(self.directory / "startup.lock"), timeout=30):
|
|
49
|
+
(self.directory / "heartbeat").touch()
|
|
50
|
+
self.wait_for_worker()
|
|
51
|
+
if not running(self.directory):
|
|
52
|
+
self.start_worker()
|
|
53
|
+
|
|
54
|
+
def wait_for_worker(self) -> None:
|
|
55
|
+
deadline = time.monotonic() + 10
|
|
56
|
+
while running(self.directory):
|
|
57
|
+
active = self.directory / "active.json"
|
|
58
|
+
if active.is_file() and (self.directory / "pid").exists():
|
|
59
|
+
if active.read_text(encoding="utf-8") == self.config_text:
|
|
60
|
+
return
|
|
61
|
+
(self.directory / "stop").touch()
|
|
62
|
+
if time.monotonic() > deadline:
|
|
63
|
+
raise RuntimeError("Tailwind helper did not stop after settings changed")
|
|
64
|
+
time.sleep(0.05)
|
|
65
|
+
|
|
66
|
+
def start_worker(self) -> None:
|
|
67
|
+
for name in ("error", "pid", "active.json", "ready", "stop"):
|
|
68
|
+
(self.directory / name).unlink(missing_ok=True)
|
|
69
|
+
flags = 0
|
|
70
|
+
if os.name == "nt":
|
|
71
|
+
flags = subprocess.DETACHED_PROCESS | subprocess.CREATE_NEW_PROCESS_GROUP
|
|
72
|
+
with (self.directory / "helper.log").open("w") as log:
|
|
73
|
+
process = subprocess.Popen(
|
|
74
|
+
[
|
|
75
|
+
sys.executable,
|
|
76
|
+
"-m",
|
|
77
|
+
"fasthtml_tailwindcss.worker",
|
|
78
|
+
self.config_text,
|
|
79
|
+
],
|
|
80
|
+
stdin=subprocess.DEVNULL,
|
|
81
|
+
stdout=log,
|
|
82
|
+
stderr=log,
|
|
83
|
+
start_new_session=os.name != "nt",
|
|
84
|
+
creationflags=flags,
|
|
85
|
+
)
|
|
86
|
+
deadline = time.monotonic() + 10
|
|
87
|
+
pid = self.directory / "pid"
|
|
88
|
+
while not pid.exists():
|
|
89
|
+
if process.poll() is not None or time.monotonic() > deadline:
|
|
90
|
+
stop_process(process)
|
|
91
|
+
raise RuntimeError(
|
|
92
|
+
(self.directory / "helper.log").read_text()
|
|
93
|
+
or "Cannot start Tailwind helper"
|
|
94
|
+
)
|
|
95
|
+
time.sleep(0.05)
|
|
96
|
+
|
|
97
|
+
def wait_for_css(self) -> None:
|
|
98
|
+
deadline = time.monotonic() + 120
|
|
99
|
+
ready = self.directory / "ready"
|
|
100
|
+
while (
|
|
101
|
+
not ready.is_file()
|
|
102
|
+
or ready.read_text(encoding="utf-8") != self.config_text
|
|
103
|
+
):
|
|
104
|
+
error = self.directory / "error"
|
|
105
|
+
if error.is_file():
|
|
106
|
+
raise RuntimeError(error.read_text(encoding="utf-8"))
|
|
107
|
+
if time.monotonic() > deadline:
|
|
108
|
+
raise RuntimeError(
|
|
109
|
+
"Tailwind initial build timed out; see compiler.log in .fasthtml-tailwindcss"
|
|
110
|
+
)
|
|
111
|
+
time.sleep(0.05)
|
|
112
|
+
|
|
113
|
+
def heartbeat(self) -> None:
|
|
114
|
+
while not self._closed.is_set():
|
|
115
|
+
error = self.directory / "error"
|
|
116
|
+
if error.is_file():
|
|
117
|
+
self.error = error.read_text(encoding="utf-8")
|
|
118
|
+
elif not running(self.directory):
|
|
119
|
+
self.error = "Tailwind helper stopped; restart the application"
|
|
120
|
+
if self.error:
|
|
121
|
+
return
|
|
122
|
+
(self.directory / "heartbeat").touch()
|
|
123
|
+
self._closed.wait(2)
|
|
124
|
+
|
|
125
|
+
def close(self) -> None:
|
|
126
|
+
self._closed.set()
|
|
127
|
+
if self._thread.ident is not None:
|
|
128
|
+
self._thread.join()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import subprocess
|
|
3
|
+
from importlib import import_module
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from .config import TailwindConfig
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def binary_path():
|
|
10
|
+
try:
|
|
11
|
+
package = import_module("fasthtml_tailwindcss_cli")
|
|
12
|
+
except ModuleNotFoundError as error:
|
|
13
|
+
raise RuntimeError(
|
|
14
|
+
'Install fasthtml-tailwindcss with the "dev" extra to use Tailwind'
|
|
15
|
+
) from error
|
|
16
|
+
return package.binary_path()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def stop_process(process: subprocess.Popen) -> None:
|
|
20
|
+
if process.poll() is not None:
|
|
21
|
+
return
|
|
22
|
+
process.terminate()
|
|
23
|
+
try:
|
|
24
|
+
process.wait(timeout=5)
|
|
25
|
+
except subprocess.TimeoutExpired:
|
|
26
|
+
process.kill()
|
|
27
|
+
process.wait()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def input_css(config: TailwindConfig) -> str:
|
|
31
|
+
def quote(path):
|
|
32
|
+
return json.dumps(Path(path).as_posix(), ensure_ascii=False)
|
|
33
|
+
|
|
34
|
+
base = (
|
|
35
|
+
f"@import {quote(config.input)};"
|
|
36
|
+
if config.input
|
|
37
|
+
else '@import "tailwindcss" source(none);'
|
|
38
|
+
)
|
|
39
|
+
sources = "\n".join(f"@source {quote(path)};" for path in config.sources)
|
|
40
|
+
return f"{base}\n{sources}\n{config.css}\n"
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
from collections.abc import Sequence
|
|
4
|
+
from dataclasses import asdict, dataclass
|
|
5
|
+
from importlib.metadata import version
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
STATE_DIRECTORY = ".fasthtml-tailwindcss"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class TailwindConfig:
|
|
13
|
+
root: str
|
|
14
|
+
sources: tuple[str, ...]
|
|
15
|
+
input: str | None
|
|
16
|
+
css: str
|
|
17
|
+
output: str
|
|
18
|
+
version: str
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def config_json(config: TailwindConfig) -> str:
|
|
22
|
+
return json.dumps(asdict(config), sort_keys=True)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def configuration(
|
|
26
|
+
*,
|
|
27
|
+
sources: Sequence[str | Path] | None,
|
|
28
|
+
input: str | Path | None,
|
|
29
|
+
css: str | None,
|
|
30
|
+
output: str | Path = "./static/tailwind.css",
|
|
31
|
+
) -> TailwindConfig:
|
|
32
|
+
if isinstance(sources, (str, Path)):
|
|
33
|
+
raise TypeError("sources must be a sequence of paths, for example ['app']")
|
|
34
|
+
root = Path.cwd().resolve()
|
|
35
|
+
input_path = (root / input).resolve() if input is not None else None
|
|
36
|
+
if input_path is not None and not input_path.is_file():
|
|
37
|
+
raise FileNotFoundError(input_path)
|
|
38
|
+
output_path = Path(output)
|
|
39
|
+
if output_path.is_absolute():
|
|
40
|
+
output_path = output_path.resolve().relative_to(root)
|
|
41
|
+
output_path = Path(os.path.normpath(output_path))
|
|
42
|
+
if output_path.is_absolute() or ".." in output_path.parts:
|
|
43
|
+
raise ValueError("output must be inside the working directory")
|
|
44
|
+
if sources is None:
|
|
45
|
+
sources = [root] if input is None else []
|
|
46
|
+
return TailwindConfig(
|
|
47
|
+
root=str(root),
|
|
48
|
+
sources=tuple(str((root / path).resolve()) for path in sources),
|
|
49
|
+
input=str(input_path) if input_path is not None else None,
|
|
50
|
+
css=css or "",
|
|
51
|
+
output=output_path.as_posix(),
|
|
52
|
+
version=version("fasthtml-tailwindcss"),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def state_directory(config: TailwindConfig) -> Path:
|
|
57
|
+
return Path(config.root) / STATE_DIRECTORY
|
|
File without changes
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import re
|
|
4
|
+
import signal
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import time
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from filelock import FileLock, Timeout
|
|
11
|
+
|
|
12
|
+
from .compiler import binary_path, input_css, stop_process
|
|
13
|
+
from .config import TailwindConfig, state_directory
|
|
14
|
+
|
|
15
|
+
IDLE_TIMEOUT = 15
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Worker:
|
|
19
|
+
def __init__(self, config_text: str):
|
|
20
|
+
self.config_text = config_text
|
|
21
|
+
values = json.loads(config_text)
|
|
22
|
+
values["sources"] = tuple(values["sources"])
|
|
23
|
+
self.config = TailwindConfig(**values)
|
|
24
|
+
self.directory = state_directory(self.config)
|
|
25
|
+
self.output = Path(self.config.root) / self.config.output
|
|
26
|
+
self.stopping = False
|
|
27
|
+
|
|
28
|
+
def stop(self, *_args) -> None:
|
|
29
|
+
self.stopping = True
|
|
30
|
+
|
|
31
|
+
def start_compiler(self) -> subprocess.Popen:
|
|
32
|
+
source = self.directory / "input.css"
|
|
33
|
+
source.write_text(input_css(self.config), encoding="utf-8")
|
|
34
|
+
command = [
|
|
35
|
+
str(binary_path()),
|
|
36
|
+
"-i",
|
|
37
|
+
str(source),
|
|
38
|
+
"-o",
|
|
39
|
+
str(self.directory / "building.css"),
|
|
40
|
+
"--watch=always",
|
|
41
|
+
]
|
|
42
|
+
with (self.directory / "compiler.log").open("w") as log:
|
|
43
|
+
return subprocess.Popen(
|
|
44
|
+
command,
|
|
45
|
+
cwd=self.config.root,
|
|
46
|
+
stdin=subprocess.DEVNULL,
|
|
47
|
+
stdout=log,
|
|
48
|
+
stderr=log,
|
|
49
|
+
env={**os.environ, "NO_COLOR": "1"},
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
def publish_css(self) -> None:
|
|
53
|
+
self.output.parent.mkdir(parents=True, exist_ok=True)
|
|
54
|
+
css = (self.directory / "building.css").read_bytes()
|
|
55
|
+
if not self.output.exists() or self.output.read_bytes() != css:
|
|
56
|
+
temporary = self.output.with_name(self.output.name + ".tmp")
|
|
57
|
+
temporary.write_bytes(css)
|
|
58
|
+
temporary.replace(self.output)
|
|
59
|
+
(self.directory / "ready").write_text(self.config_text, encoding="utf-8")
|
|
60
|
+
|
|
61
|
+
def idle(self) -> bool:
|
|
62
|
+
return time.time() - (self.directory / "heartbeat").stat().st_mtime > IDLE_TIMEOUT
|
|
63
|
+
|
|
64
|
+
def expired(self) -> bool:
|
|
65
|
+
if not self.idle():
|
|
66
|
+
return False
|
|
67
|
+
try:
|
|
68
|
+
with FileLock(str(self.directory / "startup.lock"), timeout=0):
|
|
69
|
+
if not self.idle():
|
|
70
|
+
return False
|
|
71
|
+
(self.directory / "pid").unlink(missing_ok=True)
|
|
72
|
+
return True
|
|
73
|
+
except Timeout:
|
|
74
|
+
return False
|
|
75
|
+
|
|
76
|
+
def monitor(self, process: subprocess.Popen) -> None:
|
|
77
|
+
with (self.directory / "compiler.log").open(
|
|
78
|
+
encoding="utf-8", errors="replace"
|
|
79
|
+
) as log:
|
|
80
|
+
pending = ""
|
|
81
|
+
while not self.stopping:
|
|
82
|
+
if (self.directory / "stop").exists() or self.expired():
|
|
83
|
+
return
|
|
84
|
+
code = process.poll()
|
|
85
|
+
pending += log.read()
|
|
86
|
+
message, _, pending = pending.rpartition("\n")
|
|
87
|
+
if re.search(r"\bDone in\b", message):
|
|
88
|
+
self.publish_css()
|
|
89
|
+
if code is not None:
|
|
90
|
+
details = (self.directory / "compiler.log").read_text(
|
|
91
|
+
encoding="utf-8", errors="replace"
|
|
92
|
+
)
|
|
93
|
+
raise RuntimeError(f"Tailwind stopped (exit {code}):\n{details}")
|
|
94
|
+
time.sleep(0.1)
|
|
95
|
+
|
|
96
|
+
def run(self) -> None:
|
|
97
|
+
process = None
|
|
98
|
+
(self.directory / "active.json").write_text(self.config_text, encoding="utf-8")
|
|
99
|
+
(self.directory / "pid").write_text(str(os.getpid()), encoding="utf-8")
|
|
100
|
+
try:
|
|
101
|
+
process = self.start_compiler()
|
|
102
|
+
self.monitor(process)
|
|
103
|
+
except (OSError, RuntimeError) as error:
|
|
104
|
+
(self.directory / "error").write_text(str(error), encoding="utf-8")
|
|
105
|
+
finally:
|
|
106
|
+
if process is not None:
|
|
107
|
+
stop_process(process)
|
|
108
|
+
(self.directory / "pid").unlink(missing_ok=True)
|
|
109
|
+
(self.directory / "active.json").unlink(missing_ok=True)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def main(config_text: str) -> None:
|
|
113
|
+
worker = Worker(config_text)
|
|
114
|
+
for name in ("SIGTERM", "SIGINT", "SIGBREAK"):
|
|
115
|
+
if signum := getattr(signal, name, None):
|
|
116
|
+
signal.signal(signum, worker.stop)
|
|
117
|
+
with FileLock(str(worker.directory / "worker.lock"), timeout=0):
|
|
118
|
+
worker.run()
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
if __name__ == "__main__":
|
|
122
|
+
main(sys.argv[1])
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: fasthtml-tailwindcss
|
|
3
|
+
Version: 4.3.3.post1
|
|
4
|
+
Summary: Tailwind CSS for FastHTML with a persistent development watcher and a build command for production CSS.
|
|
5
|
+
Project-URL: Documentation, https://github.com/SpaceShaman/fasthtml-tailwindcss#readme
|
|
6
|
+
Project-URL: Homepage, https://github.com/SpaceShaman/fasthtml-tailwindcss
|
|
7
|
+
Project-URL: Issues, https://github.com/SpaceShaman/fasthtml-tailwindcss/issues
|
|
8
|
+
Project-URL: Repository, https://github.com/SpaceShaman/fasthtml-tailwindcss
|
|
9
|
+
Author-email: SpaceShaman <spaceshaman@tuta.io>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: components,css,fasthtml,tailwindcss,web
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: filelock>=3.16
|
|
24
|
+
Requires-Dist: python-fasthtml>=0.14.13
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: fasthtml-tailwindcss-cli<5,>=4; extra == 'dev'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# fasthtml-tailwindcss
|
|
30
|
+
|
|
31
|
+
[](LICENSE)
|
|
32
|
+
[](https://github.com/SpaceShaman/fasthtml-tailwindcss/actions/workflows/release.yml)
|
|
33
|
+
[](https://pypi.org/project/fasthtml-tailwindcss/)
|
|
34
|
+
[](https://pypi.org/project/fasthtml-tailwindcss/)
|
|
35
|
+
[](https://github.com/AnswerDotAI/fasthtml)
|
|
36
|
+
[](https://tailwindcss.com/)
|
|
37
|
+
[](https://github.com/astral-sh/uv)
|
|
38
|
+
[](https://docs.pytest.org/)
|
|
39
|
+
[](https://github.com/astral-sh/ruff)
|
|
40
|
+
|
|
41
|
+
Tailwind CSS for [FastHTML](https://github.com/AnswerDotAI/fasthtml) with a persistent development watcher and a build command for production CSS.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
| Environment | uv | pip |
|
|
46
|
+
| --- | --- | --- |
|
|
47
|
+
| Development and builds | `uv add "fasthtml-tailwindcss[dev]"` | `pip install "fasthtml-tailwindcss[dev]"` |
|
|
48
|
+
| Production | `uv add fasthtml-tailwindcss` | `pip install fasthtml-tailwindcss` |
|
|
49
|
+
|
|
50
|
+
The `dev` extra installs the standalone compiler through [fasthtml-tailwindcss-cli](https://pypi.org/project/fasthtml-tailwindcss-cli/). No Node.js or npm is needed. Production only needs the wrapper and generated CSS.
|
|
51
|
+
|
|
52
|
+
On Alpine Linux, the compiler also needs:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
apk add --no-cache libstdc++ libgcc
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from fasthtml.common import Div, FastHTML, StaticImmutable
|
|
62
|
+
from fasthtml_tailwindcss import TailwindHead
|
|
63
|
+
|
|
64
|
+
app = FastHTML(hdrs=[TailwindHead(watch=True)])
|
|
65
|
+
app.mount("/static", StaticImmutable(directory="static"), name="static")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@app.route("/")
|
|
69
|
+
def get():
|
|
70
|
+
return Div("Hello", cls="rounded-lg bg-blue-500 p-4 text-white")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`TailwindHead` creates the output directory and adds a stylesheet link. `vurl` versions the URL by content, and `StaticImmutable` lets browsers cache the CSS until it changes.
|
|
74
|
+
|
|
75
|
+
### Watch mode
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
uv run uvicorn main:app --reload
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
For `app/main.py`, run `uv run --directory app uvicorn main:app --reload` from the project directory.
|
|
82
|
+
|
|
83
|
+
With `watch=True`, compilation starts on the first page render and CSS rebuilds when sources change. The watcher survives server reloads, restarts if settings change, and stops 15 seconds after the last application stops using it. Refresh the browser to see changes; automatic browser refresh and stylesheet updates during HTMX fragment swaps are not included.
|
|
84
|
+
|
|
85
|
+
### Production
|
|
86
|
+
|
|
87
|
+
Use `TailwindHead()` with the default `watch=False` in the application, then build CSS in your deployment pipeline with the `dev` extra installed:
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
uv run fasthtml-tailwindcss build main:app
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The command imports the app and builds minified CSS using its `TailwindHead` settings. The app must have exactly one `TailwindHead` in `hdrs`. For `app/main.py`, run `build app.main:app` from the project directory or `build main:app` from `app/`; both write to `app/static/tailwind.css` by default.
|
|
94
|
+
|
|
95
|
+
Deploy the generated CSS alongside the application. With `watch=False`, `TailwindHead` only links the stylesheet; it does not run the compiler.
|
|
96
|
+
|
|
97
|
+
## Options
|
|
98
|
+
|
|
99
|
+
All configuration is passed to `TailwindHead`:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
TailwindHead(
|
|
103
|
+
watch=True,
|
|
104
|
+
css="@theme { --color-brand: #7854f7; }",
|
|
105
|
+
output="static/app.css",
|
|
106
|
+
)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- `watch`: enable the persistent development compiler. Defaults to `False`.
|
|
110
|
+
- `sources`: files or directories to scan. Defaults to the working directory; with a custom input, its own source detection applies unless extra sources are supplied.
|
|
111
|
+
- `input`: custom stylesheet, such as `input="assets/app.css"`, replacing the built-in `@import "tailwindcss"`. Relative CSS imports resolve from that file.
|
|
112
|
+
- `css`: CSS appended after the input, useful for `@theme`, variants, and `@source inline(...)`.
|
|
113
|
+
- `output`: CSS file path, defaulting to `./static/tailwind.css`. The stylesheet URL follows this path, so mount its directory at the corresponding URL.
|
|
114
|
+
|
|
115
|
+
Paths are relative to the working directory. The build command uses the application module's directory; run the server from that directory too. Temporary files and compiler logs live in `.fasthtml-tailwindcss/`, which you can add to `.gitignore`.
|
|
116
|
+
|
|
117
|
+
Use complete class names such as `"bg-red-500"`; Tailwind cannot detect names constructed with `f"bg-{color}-500"`. Classes in installed component libraries need explicit sources or safelisting.
|
|
118
|
+
|
|
119
|
+
For inline Lucide SVG icons with typed names and editor autocomplete, see [fasthtml-lucide](https://github.com/SpaceShaman/fasthtml-lucide).
|
|
120
|
+
|
|
121
|
+
## Development
|
|
122
|
+
|
|
123
|
+
### Setup and tests
|
|
124
|
+
|
|
125
|
+
```sh
|
|
126
|
+
uv sync --group build --group test --extra dev
|
|
127
|
+
uv run --group test --extra dev pytest
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Build
|
|
131
|
+
|
|
132
|
+
```sh
|
|
133
|
+
uv build --no-sources
|
|
134
|
+
uv build packages/cli --no-sources
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
CLI wheel builds download and verify the official executable using SHA-256. Supported platforms are Linux x64/ARM64 (glibc 2.28+ or musl 1.2+), macOS 13+ (Intel/Apple Silicon), and Windows x64. Building a CLI wheel needs network access unless the verified binary is already available locally.
|
|
138
|
+
|
|
139
|
+
### Automated releases
|
|
140
|
+
|
|
141
|
+
GitHub Actions checks daily for a new stable [Tailwind CSS release](https://github.com/tailwindlabs/tailwindcss/releases), then builds and tests both packages before publishing them to PyPI. Both package versions track the Tailwind version; wrapper-only fixes may add a `.postN` suffix.
|
|
142
|
+
|
|
143
|
+
The [Release workflow](.github/workflows/release.yml) builds and tests both packages before publishing through PyPI Trusted Publishing. Configure the same publisher (`SpaceShaman/fasthtml-tailwindcss`, workflow `release.yml`, environment `pypi`) for both PyPI projects, and allow workflow version commits on the default branch.
|
|
144
|
+
|
|
145
|
+
## Links
|
|
146
|
+
|
|
147
|
+
- [GitHub repository](https://github.com/SpaceShaman/fasthtml-tailwindcss)
|
|
148
|
+
- [PyPI package](https://pypi.org/project/fasthtml-tailwindcss/)
|
|
149
|
+
- [Tailwind CLI package](https://pypi.org/project/fasthtml-tailwindcss-cli/)
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
The wrapper and Tailwind CSS are MIT licensed. The CLI package includes both license notices.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
fasthtml_tailwindcss/__init__.py,sha256=T2FXnG_P-Fy_LxOeRXtOvQ9L6DiJ-0obWOkGIqxchks,1257
|
|
2
|
+
fasthtml_tailwindcss/build.py,sha256=KPNhQcg2SdoV-cCZ4BEK6scaNhnMFq4-_sEQli6OZNI,2168
|
|
3
|
+
fasthtml_tailwindcss/client.py,sha256=BtU_JPCVepNbuC8gHWFd1jh3bJTlqpLWHmLwj_Dr8qQ,4517
|
|
4
|
+
fasthtml_tailwindcss/compiler.py,sha256=_kP40s11L0qx3IQALK9aU_JBa1W23PFBHzAX-whO5O4,1075
|
|
5
|
+
fasthtml_tailwindcss/config.py,sha256=fnJPWlBpBuFx8FHVPZivFaP-eds8s17tnfvPIFXAR84,1797
|
|
6
|
+
fasthtml_tailwindcss/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
fasthtml_tailwindcss/worker.py,sha256=5Gaj0sRQ5sKltNVprf2aMqZrq86LVsEUM4P9mObxvUQ,4311
|
|
8
|
+
fasthtml_tailwindcss-4.3.3.post1.dist-info/METADATA,sha256=ubF91a6lusBJQsTG9SXx835AYd2A4idMBvMPlo36Axg,7829
|
|
9
|
+
fasthtml_tailwindcss-4.3.3.post1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
10
|
+
fasthtml_tailwindcss-4.3.3.post1.dist-info/entry_points.txt,sha256=GDpYcNFmUIR984OelfswXRkiZ98jSoj0CCE4yxt26FI,73
|
|
11
|
+
fasthtml_tailwindcss-4.3.3.post1.dist-info/licenses/LICENSE,sha256=KYkziQfBpa3S7SN2jqaYr5uJyWlgUpnTzCAzRDPkZA4,1068
|
|
12
|
+
fasthtml_tailwindcss-4.3.3.post1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SpaceShaman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|