Skip to content

Commit 1ed6cc8

Browse files
committed
feat: lock major tailwind-cli-extra version
1 parent 02e1e6b commit 1ed6cc8

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ build-backend = "hatchling.build"
4848

4949
[tool.rye]
5050
managed = true
51-
dev-dependencies = []
51+
dev-dependencies = [
52+
"pytest==8.*",
53+
]
5254

5355
[tool.hatch.metadata]
5456
allow-direct-references = true

pytailwindcss_extra/main.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
from platform import system, machine
55
from subprocess import run, CompletedProcess
66
from pathlib import Path
7+
from json import loads
78

89
import niquests
910

1011
from pytailwindcss_extra.logger import log
1112

1213
GITHUB_REPO = "dobicinaitis/tailwind-cli-extra"
14+
MAJOR_TAILWIND_CLI_EXTRA_VERSION = 2
1315

1416

1517
def main() -> None:
@@ -20,9 +22,11 @@ def main() -> None:
2022
bin_dir_path = Path(temp_bin_dir_path)
2123

2224
# TODO: cache the latest version so it doesn't need to send a request each run
23-
version = environ.get("PYTAILWINDCSS_EXTRA_VERSION", "latest")
25+
version = environ.get("PYTAILWINDCSS_EXTRA_VERSION")
2426
if version == "latest":
2527
version = get_latest_version_tag()
28+
elif not version:
29+
version = get_latest_major_version_tag(MAJOR_TAILWIND_CLI_EXTRA_VERSION)
2630

2731
bin_path = bin_dir_path / f"tailwindcss-extra-{version.replace('.', '-')}"
2832
if not bin_path.exists():
@@ -95,6 +99,17 @@ def get_latest_version_tag() -> str:
9599
return response.json()["tag_name"]
96100

97101

102+
def get_latest_major_version_tag(major_version: int) -> str:
103+
log.info(f"Getting latest tailwind-cli-extra version for v{major_version} ...")
104+
response = niquests.get(f"https://api.github.com/repos/{GITHUB_REPO}/releases")
105+
response.raise_for_status()
106+
if not response.text:
107+
raise RuntimeError("No releases found")
108+
releases = loads(response.text)
109+
matching_releases = [release for release in releases if release["tag_name"].startswith(f"v{major_version}.")]
110+
return matching_releases[0]["tag_name"]
111+
112+
98113
def run_file_with_arguments(file_path: Path, arguments: list[str]) -> CompletedProcess[bytes]:
99114
return run([file_path] + arguments, check=False)
100115

requirements-dev.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@ charset-normalizer==3.4.1
1414
# via niquests
1515
h11==0.14.0
1616
# via urllib3-future
17+
iniconfig==2.1.0
18+
# via pytest
1719
jh2==5.0.8
1820
# via urllib3-future
1921
niquests==3.14.0
2022
# via pytailwindcss-extra
23+
packaging==24.2
24+
# via pytest
25+
pluggy==1.5.0
26+
# via pytest
27+
pytest==8.3.5
2128
qh3==1.4.4
2229
# via urllib3-future
2330
urllib3-future==2.12.917

tests/test_main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pytailwindcss_extra.main import get_latest_major_version_tag
2+
3+
4+
def test_get_latest_major_version_tag() -> None:
5+
assert get_latest_major_version_tag(1) == "v1.7.27"

0 commit comments

Comments
 (0)