fxcss 0.22.1__tar.gz → 0.23.0__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 (43) hide show
  1. {fxcss-0.22.1 → fxcss-0.23.0}/PKG-INFO +39 -6
  2. {fxcss-0.22.1 → fxcss-0.23.0}/README.md +38 -5
  3. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/__init__.py +1 -1
  4. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/cli.py +41 -10
  5. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/fetch.py +114 -14
  6. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss.egg-info/PKG-INFO +39 -6
  7. {fxcss-0.22.1 → fxcss-0.23.0}/tests/test_units.py +100 -0
  8. {fxcss-0.22.1 → fxcss-0.23.0}/tests/test_workflows.py +4 -7
  9. {fxcss-0.22.1 → fxcss-0.23.0}/LICENSE +0 -0
  10. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/__main__.py +0 -0
  11. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/adopt.py +0 -0
  12. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/audit.py +0 -0
  13. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/capture.py +0 -0
  14. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/catalogue.py +0 -0
  15. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/check.py +0 -0
  16. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/compare.py +0 -0
  17. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/complete.py +0 -0
  18. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/core.py +0 -0
  19. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/install.py +0 -0
  20. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/omni.py +0 -0
  21. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/probe.py +0 -0
  22. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/scaffold.py +0 -0
  23. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/sheets.py +0 -0
  24. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/templates/firefox-watch.yml +0 -0
  25. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/templates/pr-preview-cleanup.yml +0 -0
  26. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/templates/pr-preview-publish.yml +0 -0
  27. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/templates/pr-preview.yml +0 -0
  28. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/templates/readme-previews.yml +0 -0
  29. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/templates/showcase.yml +0 -0
  30. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/templates/starter/chrome/userChrome.css +0 -0
  31. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/templates/starter/custom/accent-red.css +0 -0
  32. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss/tweaks.py +0 -0
  33. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss.egg-info/SOURCES.txt +0 -0
  34. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss.egg-info/dependency_links.txt +0 -0
  35. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss.egg-info/entry_points.txt +0 -0
  36. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss.egg-info/requires.txt +0 -0
  37. {fxcss-0.22.1 → fxcss-0.23.0}/fxcss.egg-info/top_level.txt +0 -0
  38. {fxcss-0.22.1 → fxcss-0.23.0}/pyproject.toml +0 -0
  39. {fxcss-0.22.1 → fxcss-0.23.0}/setup.cfg +0 -0
  40. {fxcss-0.22.1 → fxcss-0.23.0}/tests/test_capture_coverage.py +0 -0
  41. {fxcss-0.22.1 → fxcss-0.23.0}/tests/test_checks.py +0 -0
  42. {fxcss-0.22.1 → fxcss-0.23.0}/tests/test_patch_duplicates.py +0 -0
  43. {fxcss-0.22.1 → fxcss-0.23.0}/tests/test_profile_safety.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fxcss
3
- Version: 0.22.1
3
+ Version: 0.23.0
4
4
  Summary: Live-reload, inspect and screenshot-test Firefox userChrome.css themes
5
5
  Author: AdamXweb
6
6
  License: MIT
@@ -21,6 +21,7 @@ Provides-Extra: images
21
21
  Requires-Dist: pillow>=10.1; extra == "images"
22
22
  Dynamic: license-file
23
23
 
24
+
24
25
  # fxcss
25
26
 
26
27
  <p align="center">
@@ -60,6 +61,9 @@ For local development and testing, run commands from the theme's root (the
60
61
  folder containing `chrome/`), or pass `--theme /path/to/theme`. Use
61
62
  `fxcss <command> --help` for its options.
62
63
 
64
+ https://github.com/user-attachments/assets/83dc3c67-6cad-432a-b841-d602a135a396
65
+
66
+
63
67
  ## Explore the toolkit
64
68
 
65
69
  | Section | What you can do |
@@ -94,6 +98,7 @@ repository to `fxcss try`.
94
98
  fxcss try adamXweb/WhiteSurFirefoxThemeMacOS
95
99
  fxcss try github.com/owner/theme --with compact-tabs
96
100
  fxcss try owner/theme --info # report what's there, launch nothing
101
+ fxcss try ~/src/my-theme # a theme folder on this computer
97
102
  ```
98
103
 
99
104
  **Test-drive a theme before committing to it.** Downloads it, installs it into a
@@ -130,6 +135,29 @@ a variant without hunting through install flags. `--shot dir` captures the
130
135
  standard screenshots instead of opening a window, and `--keep dir` leaves the
131
136
  download behind so you can start editing it with `watch`.
132
137
 
138
+ #### Private repositories and local folders
139
+
140
+ A private repository looks exactly like a missing one to anyone who cannot read
141
+ it. fxcss sends `GITHUB_TOKEN` or `GH_TOKEN` when either is set; otherwise, if a
142
+ repository is not publicly visible, it asks the GitHub CLI for its login
143
+ (`gh auth token`) and tries again. So after `gh auth login`, private themes your
144
+ account can read work like public ones. A token also raises GitHub's rate limit.
145
+
146
+ A theme that is not on GitHub, or not pushed yet, can be tried from its folder:
147
+ `fxcss try ~/src/my-theme`. The folder is read where it is and never modified;
148
+ `--with`, `--shot` and `--info` work as usual, while `--ref` and `--commit` do
149
+ not apply.
150
+
151
+ When a repository cannot be read, fxcss says why and what to try next rather
152
+ than printing a traceback:
153
+
154
+ ```
155
+ error: GitHub has no public repository owner/theme.
156
+ Check the name at https://github.com/owner/theme
157
+ If it is private, sign in with `gh auth login` or set GITHUB_TOKEN to a token that can read it.
158
+ For a theme on this computer, pass its folder instead, such as ~/src/my-theme
159
+ ```
160
+
133
161
  #### It does not run the theme's install script
134
162
 
135
163
  fxcss installs the theme's files and supported preferences itself. It reports
@@ -351,8 +379,8 @@ fxcss profiles --json # machine-readable
351
379
  ```
352
380
 
353
381
  Read-only. Firefox keeps its profiles in directories named after a hash, so
354
- "which profile has the theme in it" is a genuinely hard question to answer by
355
- looking:
382
+ it can be hard to tell which profile has the theme by looking at folder
383
+ names:
356
384
 
357
385
  ```console
358
386
  $ fxcss profiles --check
@@ -754,7 +782,7 @@ you want plain screenshots — `fxcss compare` writes a different shape, below.
754
782
  fxcss shot --out shots --variants all
755
783
  ```
756
784
 
757
- `--variants` additionally captures one view per optional stylesheet the theme
785
+ `--variants` also captures one view per optional stylesheet the theme
758
786
  ships (`custom/`, `optional/`, `variants/`…), each loaded on its own and removed
759
787
  again — so `tabs-swapclose` or `compact-tabs` are checked by CI without a
760
788
  separate install. Name specific ones (`--variants a,b`) or take them all.
@@ -1118,7 +1146,7 @@ text.
1118
1146
  For a custom workflow, the core capture-and-compare steps are:
1119
1147
 
1120
1148
  ```yaml
1121
- - run: pip install "fxcss[images]==0.22.0"
1149
+ - run: pip install "fxcss[images]==0.22.1"
1122
1150
  - run: fxcss shot --theme base --out shots/base
1123
1151
  - run: fxcss shot --theme head --out shots/head
1124
1152
  - run: fxcss compare --base shots/base --head shots/head --out out/ --platform ${{ runner.os }}
@@ -1273,7 +1301,7 @@ the [releases page](https://github.com/AdamXweb/fxcss/releases) has the latest.
1273
1301
  CI runners' Pythons are not externally managed, so plain pip is fine there:
1274
1302
 
1275
1303
  ```bash
1276
- pip install "fxcss[images]==0.22.0"
1304
+ pip install "fxcss[images]==0.22.1"
1277
1305
  ```
1278
1306
 
1279
1307
  Upgrade an existing pipx installation with `pipx upgrade fxcss`.
@@ -1407,6 +1435,11 @@ Issues and pull requests welcome — particularly landmark definitions for UI
1407
1435
  parts the catalogue doesn't cover yet, and reports of selectors that changed in
1408
1436
  a new Firefox release.
1409
1437
 
1438
+ The fxcss.com website lives on the repository's
1439
+ [`website` branch](https://github.com/AdamXweb/fxcss/tree/website), with its
1440
+ own README and `just` commands; send website changes there. Its documentation
1441
+ pages are generated from this README.
1442
+
1410
1443
  To work on fxcss itself, clone and install it in an editable environment:
1411
1444
 
1412
1445
  ```bash
@@ -1,3 +1,4 @@
1
+
1
2
  # fxcss
2
3
 
3
4
  <p align="center">
@@ -37,6 +38,9 @@ For local development and testing, run commands from the theme's root (the
37
38
  folder containing `chrome/`), or pass `--theme /path/to/theme`. Use
38
39
  `fxcss <command> --help` for its options.
39
40
 
41
+ https://github.com/user-attachments/assets/83dc3c67-6cad-432a-b841-d602a135a396
42
+
43
+
40
44
  ## Explore the toolkit
41
45
 
42
46
  | Section | What you can do |
@@ -71,6 +75,7 @@ repository to `fxcss try`.
71
75
  fxcss try adamXweb/WhiteSurFirefoxThemeMacOS
72
76
  fxcss try github.com/owner/theme --with compact-tabs
73
77
  fxcss try owner/theme --info # report what's there, launch nothing
78
+ fxcss try ~/src/my-theme # a theme folder on this computer
74
79
  ```
75
80
 
76
81
  **Test-drive a theme before committing to it.** Downloads it, installs it into a
@@ -107,6 +112,29 @@ a variant without hunting through install flags. `--shot dir` captures the
107
112
  standard screenshots instead of opening a window, and `--keep dir` leaves the
108
113
  download behind so you can start editing it with `watch`.
109
114
 
115
+ #### Private repositories and local folders
116
+
117
+ A private repository looks exactly like a missing one to anyone who cannot read
118
+ it. fxcss sends `GITHUB_TOKEN` or `GH_TOKEN` when either is set; otherwise, if a
119
+ repository is not publicly visible, it asks the GitHub CLI for its login
120
+ (`gh auth token`) and tries again. So after `gh auth login`, private themes your
121
+ account can read work like public ones. A token also raises GitHub's rate limit.
122
+
123
+ A theme that is not on GitHub, or not pushed yet, can be tried from its folder:
124
+ `fxcss try ~/src/my-theme`. The folder is read where it is and never modified;
125
+ `--with`, `--shot` and `--info` work as usual, while `--ref` and `--commit` do
126
+ not apply.
127
+
128
+ When a repository cannot be read, fxcss says why and what to try next rather
129
+ than printing a traceback:
130
+
131
+ ```
132
+ error: GitHub has no public repository owner/theme.
133
+ Check the name at https://github.com/owner/theme
134
+ If it is private, sign in with `gh auth login` or set GITHUB_TOKEN to a token that can read it.
135
+ For a theme on this computer, pass its folder instead, such as ~/src/my-theme
136
+ ```
137
+
110
138
  #### It does not run the theme's install script
111
139
 
112
140
  fxcss installs the theme's files and supported preferences itself. It reports
@@ -328,8 +356,8 @@ fxcss profiles --json # machine-readable
328
356
  ```
329
357
 
330
358
  Read-only. Firefox keeps its profiles in directories named after a hash, so
331
- "which profile has the theme in it" is a genuinely hard question to answer by
332
- looking:
359
+ it can be hard to tell which profile has the theme by looking at folder
360
+ names:
333
361
 
334
362
  ```console
335
363
  $ fxcss profiles --check
@@ -731,7 +759,7 @@ you want plain screenshots — `fxcss compare` writes a different shape, below.
731
759
  fxcss shot --out shots --variants all
732
760
  ```
733
761
 
734
- `--variants` additionally captures one view per optional stylesheet the theme
762
+ `--variants` also captures one view per optional stylesheet the theme
735
763
  ships (`custom/`, `optional/`, `variants/`…), each loaded on its own and removed
736
764
  again — so `tabs-swapclose` or `compact-tabs` are checked by CI without a
737
765
  separate install. Name specific ones (`--variants a,b`) or take them all.
@@ -1095,7 +1123,7 @@ text.
1095
1123
  For a custom workflow, the core capture-and-compare steps are:
1096
1124
 
1097
1125
  ```yaml
1098
- - run: pip install "fxcss[images]==0.22.0"
1126
+ - run: pip install "fxcss[images]==0.22.1"
1099
1127
  - run: fxcss shot --theme base --out shots/base
1100
1128
  - run: fxcss shot --theme head --out shots/head
1101
1129
  - run: fxcss compare --base shots/base --head shots/head --out out/ --platform ${{ runner.os }}
@@ -1250,7 +1278,7 @@ the [releases page](https://github.com/AdamXweb/fxcss/releases) has the latest.
1250
1278
  CI runners' Pythons are not externally managed, so plain pip is fine there:
1251
1279
 
1252
1280
  ```bash
1253
- pip install "fxcss[images]==0.22.0"
1281
+ pip install "fxcss[images]==0.22.1"
1254
1282
  ```
1255
1283
 
1256
1284
  Upgrade an existing pipx installation with `pipx upgrade fxcss`.
@@ -1384,6 +1412,11 @@ Issues and pull requests welcome — particularly landmark definitions for UI
1384
1412
  parts the catalogue doesn't cover yet, and reports of selectors that changed in
1385
1413
  a new Firefox release.
1386
1414
 
1415
+ The fxcss.com website lives on the repository's
1416
+ [`website` branch](https://github.com/AdamXweb/fxcss/tree/website), with its
1417
+ own README and `just` commands; send website changes there. Its documentation
1418
+ pages are generated from this README.
1419
+
1387
1420
  To work on fxcss itself, clone and install it in an editable environment:
1388
1421
 
1389
1422
  ```bash
@@ -1,3 +1,3 @@
1
1
  """fxcss — a testing toolkit for Firefox userChrome.css themes."""
2
2
 
3
- __version__ = "0.22.1"
3
+ __version__ = "0.23.0"
@@ -199,9 +199,26 @@ def cmd_try(args):
199
199
  from . import fetch
200
200
 
201
201
  _install_signal_handlers()
202
- owner, name = fetch.parse_repo(args.repo)
202
+ # A folder on this computer, as `install` accepts: a theme being written,
203
+ # or one that is not on GitHub. It is read where it is, never modified.
204
+ local = Path(args.repo).expanduser()
205
+ if local.is_dir():
206
+ owner = name = None
207
+ if args.ref or args.commit:
208
+ print(" --ref and --commit choose a GitHub version; using the folder as it is.")
209
+ elif args.repo.startswith(("/", "~", ".")) or "\\" in args.repo:
210
+ print(f"error: no folder at {local}", file=sys.stderr)
211
+ return 2
212
+ else:
213
+ try:
214
+ owner, name = fetch.parse_repo(args.repo)
215
+ except fetch.RepoSpecError as exc:
216
+ print(f"error: {exc} Or pass the path of a theme folder.", file=sys.stderr)
217
+ return 2
203
218
 
204
- if args.ref:
219
+ if owner is None:
220
+ ref, why, info = None, None, None
221
+ elif args.ref:
205
222
  ref, why = args.ref, f"ref {args.ref}"
206
223
  info = None
207
224
  else:
@@ -217,17 +234,24 @@ def cmd_try(args):
217
234
  workdir = Path(tempfile.mkdtemp(prefix="fxcss-try-"))
218
235
  keep = args.keep.resolve() if args.keep else None
219
236
  try:
220
- print(f"\n fetching {why} …")
221
- repo_root = fetch.download(owner, name, ref, workdir / "src")
237
+ if owner is None:
238
+ repo_root = local.resolve()
239
+ print(f"\n trying {repo_root}")
240
+ else:
241
+ print(f"\n fetching {why} …")
242
+ repo_root = fetch.download(owner, name, ref, workdir / "src")
222
243
  theme_root = fetch.find_theme_root(repo_root)
223
244
  if theme_root is None:
224
- print("\n No chrome/userChrome.css anywhere in this repository, so "
225
- "there is\n nothing for Firefox to load. Is it a userChrome theme?")
245
+ where = "folder" if owner is None else "repository"
246
+ print(f"\n No userChrome.css anywhere in this {where}, so there is\n"
247
+ " nothing for Firefox to load. Is it a userChrome theme?",
248
+ file=sys.stderr)
226
249
  return 2
227
250
 
228
251
  facts = fetch.describe(repo_root, theme_root)
229
252
  where = theme_root.relative_to(repo_root)
230
- print(f" theme found at {where if str(where) != '.' else 'the repository root'}"
253
+ top = "the top of the folder" if owner is None else "the repository root"
254
+ print(f" theme found at {where if str(where) != '.' else top}"
231
255
  f" ({facts['stylesheets']} stylesheets, {facts['bytes'] // 1024} KB)")
232
256
 
233
257
  if facts["scripts"]:
@@ -1868,10 +1892,10 @@ def build_parser():
1868
1892
  sub = ap.add_subparsers(dest="cmd", required=False)
1869
1893
 
1870
1894
  tr = sub.add_parser(
1871
- "try", help="download a theme from GitHub and test-drive it",
1895
+ "try", help="test-drive a theme from GitHub or a folder in a throwaway profile",
1872
1896
  epilog="Looking for themes? Browse firefoxcss-store.github.io or "
1873
1897
  "r/FirefoxCSS — anything with a userChrome.css on GitHub works.")
1874
- tr.add_argument("repo", help="owner/name, or a github.com URL")
1898
+ tr.add_argument("repo", help="owner/name, a github.com URL, or a local theme folder")
1875
1899
  tr.add_argument("--firefox", default=None,
1876
1900
  help="a channel/fork name (e.g. nightly, dev, esr) or a binary path")
1877
1901
  tr.add_argument("--ref", default=None, help="tag, branch or commit to fetch")
@@ -2203,7 +2227,14 @@ def main(argv=None):
2203
2227
  sys.stdout.reconfigure(line_buffering=True)
2204
2228
  except AttributeError:
2205
2229
  pass
2206
- return args.func(args)
2230
+ from .fetch import FetchError
2231
+ try:
2232
+ return args.func(args)
2233
+ except FetchError as exc:
2234
+ # Expected problems (a missing or private repository, no network, a
2235
+ # refused download) get a message saying what to try, not a traceback.
2236
+ print(f"\nerror: {exc}", file=sys.stderr)
2237
+ return 2
2207
2238
 
2208
2239
 
2209
2240
  if __name__ == "__main__":
@@ -23,6 +23,7 @@ import json
23
23
  import os
24
24
  import re
25
25
  import shutil
26
+ import subprocess
26
27
  import tarfile
27
28
  import tempfile
28
29
  import urllib.error
@@ -30,6 +31,14 @@ import urllib.request
30
31
  from pathlib import Path
31
32
 
32
33
  API = "https://api.github.com"
34
+
35
+
36
+ class FetchError(RuntimeError):
37
+ """A problem reaching or reading a theme, reported as a message, not a traceback."""
38
+
39
+
40
+ class RepoSpecError(FetchError, ValueError):
41
+ """The argument is neither owner/name nor a github.com URL."""
33
42
  USER_AGENT = "fxcss (+https://github.com/AdamXweb/fxcss)"
34
43
 
35
44
  # A theme is small. Anything wildly bigger than this is not one, and unpacking it
@@ -55,21 +64,63 @@ FLAG_LINE = re.compile(r"^\s*[-*+]\s*`?(-{1,2}[\w-]+)`?\s*[—:-]?\s+(.{4,120}?)
55
64
  def parse_repo(spec: str):
56
65
  match = REPO_SPEC.match(spec.strip())
57
66
  if not match:
58
- raise ValueError(
67
+ raise RepoSpecError(
59
68
  f"could not read {spec!r} as a GitHub repo. "
60
69
  "Use owner/name or a github.com URL.")
61
70
  return match.group(1), match.group(2)
62
71
 
63
72
 
73
+ # A token is optional. GITHUB_TOKEN or GH_TOKEN, when set, is sent with every
74
+ # request: it raises the anonymous rate limit and opens private repositories.
75
+ # Without one, fxcss asks the GitHub CLI for its login, but only after an
76
+ # anonymous request found nothing, since a private repository looks exactly
77
+ # like a missing one to anyone who cannot read it.
78
+ _cli_login = {"token": None, "tried": False}
79
+
80
+
81
+ def _token():
82
+ """The token in use and where it came from, or (None, None)."""
83
+ for var in ("GITHUB_TOKEN", "GH_TOKEN"):
84
+ if os.environ.get(var):
85
+ return os.environ[var], var
86
+ if _cli_login["token"]:
87
+ return _cli_login["token"], "gh auth token"
88
+ return None, None
89
+
90
+
91
+ def _use_cli_login():
92
+ """Pick up `gh auth token` once. True when a new token is now in use."""
93
+ if _token()[0] or _cli_login["tried"]:
94
+ return False
95
+ _cli_login["tried"] = True
96
+ gh = shutil.which("gh")
97
+ if not gh:
98
+ return False
99
+ try:
100
+ result = subprocess.run([gh, "auth", "token"], capture_output=True,
101
+ text=True, timeout=15)
102
+ except (OSError, subprocess.SubprocessError):
103
+ return False
104
+ token = result.stdout.strip()
105
+ if result.returncode != 0 or not token:
106
+ return False
107
+ _cli_login["token"] = token
108
+ return True
109
+
110
+
64
111
  def _request(url, accept="application/vnd.github+json"):
65
112
  headers = {"User-Agent": USER_AGENT, "Accept": accept}
66
- # Only raises the anonymous rate limit; never required.
67
- token = os.environ.get("GITHUB_TOKEN") or os.environ.get("GH_TOKEN")
113
+ token = _token()[0]
68
114
  if token:
69
115
  headers["Authorization"] = f"Bearer {token}"
70
116
  return urllib.request.Request(url, headers=headers)
71
117
 
72
118
 
119
+ def _unreachable(exc):
120
+ return FetchError(f"could not reach GitHub ({getattr(exc, 'reason', exc)}). "
121
+ "Check the connection and try again.")
122
+
123
+
73
124
  def _api(path):
74
125
  try:
75
126
  with urllib.request.urlopen(_request(API + path), timeout=45) as response:
@@ -77,18 +128,49 @@ def _api(path):
77
128
  except urllib.error.HTTPError as exc:
78
129
  if exc.code == 404:
79
130
  return None
131
+ if exc.code == 401:
132
+ raise FetchError(
133
+ f"GitHub rejected the token from {_token()[1]} (401 Unauthorized). "
134
+ "It may have expired or been revoked: replace it, or unset it to "
135
+ "use public repositories without one.") from exc
80
136
  if exc.code in (403, 429):
81
- raise RuntimeError(
82
- "GitHub refused the request (rate limit). Set GITHUB_TOKEN to "
83
- "raise it, or pass --ref to skip the lookups.") from exc
84
- raise
137
+ raise FetchError(
138
+ "GitHub refused the request (rate limit). Set GITHUB_TOKEN, or "
139
+ "sign in with `gh auth login`, to raise it; or pass --ref to "
140
+ "skip the lookups.") from exc
141
+ raise FetchError(f"GitHub answered {exc.code} {exc.reason} for {path}") from exc
142
+ except urllib.error.URLError as exc:
143
+ raise _unreachable(exc) from exc
144
+
145
+
146
+ def not_found(owner, name):
147
+ """What to say when a repository cannot be read, and what to try next."""
148
+ token, source = _token()
149
+ if token:
150
+ first = (f"no repository {owner}/{name} that the GitHub token from "
151
+ f"{source} can read.")
152
+ access = (" If it is private, use a token or `gh` login whose account "
153
+ "can read it.")
154
+ else:
155
+ first = f"GitHub has no public repository {owner}/{name}."
156
+ access = (" If it is private, sign in with `gh auth login` or set "
157
+ "GITHUB_TOKEN to a token that can read it.")
158
+ return FetchError("\n".join([
159
+ first,
160
+ f" Check the name at https://github.com/{owner}/{name}",
161
+ access,
162
+ " For a theme on this computer, pass its folder instead, "
163
+ "such as ~/src/my-theme",
164
+ ]))
85
165
 
86
166
 
87
167
  def resolve(owner, name):
88
168
  """Report what is available: the default branch tip and the latest release."""
89
169
  repo = _api(f"/repos/{owner}/{name}")
170
+ if repo is None and _use_cli_login():
171
+ repo = _api(f"/repos/{owner}/{name}")
90
172
  if repo is None:
91
- raise RuntimeError(f"no such repository: {owner}/{name}")
173
+ raise not_found(owner, name)
92
174
 
93
175
  branch = repo.get("default_branch", "main")
94
176
  commit = _api(f"/repos/{owner}/{name}/commits/{branch}") or {}
@@ -283,23 +365,41 @@ def _safe_members(archive, destination: Path):
283
365
  continue
284
366
  target = (root / member.name).resolve()
285
367
  if not str(target).startswith(str(root) + os.sep):
286
- raise RuntimeError(f"archive tried to write outside the target: {member.name}")
368
+ raise FetchError(f"archive tried to write outside the target: {member.name}")
287
369
  total += max(member.size, 0)
288
370
  if total > MAX_UNPACKED_BYTES:
289
- raise RuntimeError("archive unpacks to more than 200 MB; refusing")
371
+ raise FetchError("archive unpacks to more than 200 MB; refusing")
290
372
  yield member
291
373
 
292
374
 
293
375
  def download(owner, name, ref, into: Path):
294
376
  """Download and unpack a repository at a ref. Returns the unpacked root."""
295
377
  url = f"https://codeload.github.com/{owner}/{name}/tar.gz/{ref}"
296
- try:
378
+
379
+ def fetch():
297
380
  with urllib.request.urlopen(_request(url, accept="*/*"), timeout=180) as response:
298
- payload = response.read(MAX_ARCHIVE_BYTES + 1)
381
+ return response.read(MAX_ARCHIVE_BYTES + 1)
382
+
383
+ try:
384
+ try:
385
+ payload = fetch()
386
+ except urllib.error.HTTPError as exc:
387
+ # With --ref there was no lookup first, so this may be the first
388
+ # sign that the repository is private.
389
+ if exc.code != 404 or not _use_cli_login():
390
+ raise
391
+ payload = fetch()
299
392
  except urllib.error.HTTPError as exc:
300
- raise RuntimeError(f"could not download {owner}/{name}@{ref}: {exc}") from exc
393
+ if exc.code == 404:
394
+ raise FetchError(
395
+ f"could not download {owner}/{name} at {ref!r}: that repository "
396
+ "or ref was not found.\n"
397
+ f" {not_found(owner, name).args[0].splitlines()[0]}") from exc
398
+ raise FetchError(f"could not download {owner}/{name}@{ref}: {exc}") from exc
399
+ except urllib.error.URLError as exc:
400
+ raise _unreachable(exc) from exc
301
401
  if len(payload) > MAX_ARCHIVE_BYTES:
302
- raise RuntimeError("archive is larger than 80 MB; refusing")
402
+ raise FetchError("archive is larger than 80 MB; refusing")
303
403
 
304
404
  into.mkdir(parents=True, exist_ok=True)
305
405
  with tarfile.open(fileobj=io.BytesIO(payload), mode="r:gz") as archive:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fxcss
3
- Version: 0.22.1
3
+ Version: 0.23.0
4
4
  Summary: Live-reload, inspect and screenshot-test Firefox userChrome.css themes
5
5
  Author: AdamXweb
6
6
  License: MIT
@@ -21,6 +21,7 @@ Provides-Extra: images
21
21
  Requires-Dist: pillow>=10.1; extra == "images"
22
22
  Dynamic: license-file
23
23
 
24
+
24
25
  # fxcss
25
26
 
26
27
  <p align="center">
@@ -60,6 +61,9 @@ For local development and testing, run commands from the theme's root (the
60
61
  folder containing `chrome/`), or pass `--theme /path/to/theme`. Use
61
62
  `fxcss <command> --help` for its options.
62
63
 
64
+ https://github.com/user-attachments/assets/83dc3c67-6cad-432a-b841-d602a135a396
65
+
66
+
63
67
  ## Explore the toolkit
64
68
 
65
69
  | Section | What you can do |
@@ -94,6 +98,7 @@ repository to `fxcss try`.
94
98
  fxcss try adamXweb/WhiteSurFirefoxThemeMacOS
95
99
  fxcss try github.com/owner/theme --with compact-tabs
96
100
  fxcss try owner/theme --info # report what's there, launch nothing
101
+ fxcss try ~/src/my-theme # a theme folder on this computer
97
102
  ```
98
103
 
99
104
  **Test-drive a theme before committing to it.** Downloads it, installs it into a
@@ -130,6 +135,29 @@ a variant without hunting through install flags. `--shot dir` captures the
130
135
  standard screenshots instead of opening a window, and `--keep dir` leaves the
131
136
  download behind so you can start editing it with `watch`.
132
137
 
138
+ #### Private repositories and local folders
139
+
140
+ A private repository looks exactly like a missing one to anyone who cannot read
141
+ it. fxcss sends `GITHUB_TOKEN` or `GH_TOKEN` when either is set; otherwise, if a
142
+ repository is not publicly visible, it asks the GitHub CLI for its login
143
+ (`gh auth token`) and tries again. So after `gh auth login`, private themes your
144
+ account can read work like public ones. A token also raises GitHub's rate limit.
145
+
146
+ A theme that is not on GitHub, or not pushed yet, can be tried from its folder:
147
+ `fxcss try ~/src/my-theme`. The folder is read where it is and never modified;
148
+ `--with`, `--shot` and `--info` work as usual, while `--ref` and `--commit` do
149
+ not apply.
150
+
151
+ When a repository cannot be read, fxcss says why and what to try next rather
152
+ than printing a traceback:
153
+
154
+ ```
155
+ error: GitHub has no public repository owner/theme.
156
+ Check the name at https://github.com/owner/theme
157
+ If it is private, sign in with `gh auth login` or set GITHUB_TOKEN to a token that can read it.
158
+ For a theme on this computer, pass its folder instead, such as ~/src/my-theme
159
+ ```
160
+
133
161
  #### It does not run the theme's install script
134
162
 
135
163
  fxcss installs the theme's files and supported preferences itself. It reports
@@ -351,8 +379,8 @@ fxcss profiles --json # machine-readable
351
379
  ```
352
380
 
353
381
  Read-only. Firefox keeps its profiles in directories named after a hash, so
354
- "which profile has the theme in it" is a genuinely hard question to answer by
355
- looking:
382
+ it can be hard to tell which profile has the theme by looking at folder
383
+ names:
356
384
 
357
385
  ```console
358
386
  $ fxcss profiles --check
@@ -754,7 +782,7 @@ you want plain screenshots — `fxcss compare` writes a different shape, below.
754
782
  fxcss shot --out shots --variants all
755
783
  ```
756
784
 
757
- `--variants` additionally captures one view per optional stylesheet the theme
785
+ `--variants` also captures one view per optional stylesheet the theme
758
786
  ships (`custom/`, `optional/`, `variants/`…), each loaded on its own and removed
759
787
  again — so `tabs-swapclose` or `compact-tabs` are checked by CI without a
760
788
  separate install. Name specific ones (`--variants a,b`) or take them all.
@@ -1118,7 +1146,7 @@ text.
1118
1146
  For a custom workflow, the core capture-and-compare steps are:
1119
1147
 
1120
1148
  ```yaml
1121
- - run: pip install "fxcss[images]==0.22.0"
1149
+ - run: pip install "fxcss[images]==0.22.1"
1122
1150
  - run: fxcss shot --theme base --out shots/base
1123
1151
  - run: fxcss shot --theme head --out shots/head
1124
1152
  - run: fxcss compare --base shots/base --head shots/head --out out/ --platform ${{ runner.os }}
@@ -1273,7 +1301,7 @@ the [releases page](https://github.com/AdamXweb/fxcss/releases) has the latest.
1273
1301
  CI runners' Pythons are not externally managed, so plain pip is fine there:
1274
1302
 
1275
1303
  ```bash
1276
- pip install "fxcss[images]==0.22.0"
1304
+ pip install "fxcss[images]==0.22.1"
1277
1305
  ```
1278
1306
 
1279
1307
  Upgrade an existing pipx installation with `pipx upgrade fxcss`.
@@ -1407,6 +1435,11 @@ Issues and pull requests welcome — particularly landmark definitions for UI
1407
1435
  parts the catalogue doesn't cover yet, and reports of selectors that changed in
1408
1436
  a new Firefox release.
1409
1437
 
1438
+ The fxcss.com website lives on the repository's
1439
+ [`website` branch](https://github.com/AdamXweb/fxcss/tree/website), with its
1440
+ own README and `just` commands; send website changes there. Its documentation
1441
+ pages are generated from this README.
1442
+
1410
1443
  To work on fxcss itself, clone and install it in an editable environment:
1411
1444
 
1412
1445
  ```bash
@@ -349,6 +349,106 @@ class ParseRepoTests(unittest.TestCase):
349
349
  parse_repo(spec)
350
350
 
351
351
 
352
+ class FetchFailureTests(unittest.TestCase):
353
+ """A repository that cannot be read is a message, not a traceback."""
354
+
355
+ def setUp(self):
356
+ import os
357
+ from unittest import mock
358
+ from fxcss import fetch
359
+ self.fetch = fetch
360
+ # No token from the environment, and a fresh gh-login lookup each test.
361
+ self.env = mock.patch.dict(os.environ, {}, clear=False)
362
+ self.env.start()
363
+ for var in ("GITHUB_TOKEN", "GH_TOKEN"):
364
+ os.environ.pop(var, None)
365
+ self.addCleanup(self.env.stop)
366
+ self.login = mock.patch.dict(fetch._cli_login, {"token": None, "tried": False})
367
+ self.login.start()
368
+ self.addCleanup(self.login.stop)
369
+
370
+ def run_cli(self, *argv):
371
+ import contextlib
372
+ import io
373
+ from fxcss import cli
374
+ out, err = io.StringIO(), io.StringIO()
375
+ with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
376
+ code = cli.main(list(argv))
377
+ return code, out.getvalue(), err.getvalue()
378
+
379
+ def test_missing_public_repo_explains_what_to_try(self):
380
+ from unittest import mock
381
+ with mock.patch.object(self.fetch, "_api", return_value=None), \
382
+ mock.patch.object(self.fetch.shutil, "which", return_value=None):
383
+ code, _, err = self.run_cli("try", "owner/missing", "--info")
384
+ self.assertEqual(code, 2)
385
+ self.assertNotIn("Traceback", err)
386
+ self.assertIn("GitHub has no public repository owner/missing", err)
387
+ self.assertIn("gh auth login", err)
388
+ self.assertIn("pass its folder instead", err)
389
+
390
+ def test_private_repo_uses_the_gh_login_after_an_anonymous_miss(self):
391
+ from unittest import mock
392
+ seen = []
393
+
394
+ def api(path):
395
+ token = self.fetch._token()[0]
396
+ seen.append(token)
397
+ if token != "gho_example":
398
+ return None
399
+ return {"default_branch": "main"} if path == "/repos/me/private" else None
400
+
401
+ done = mock.Mock(returncode=0, stdout="gho_example\n")
402
+ with mock.patch.object(self.fetch, "_api", side_effect=api), \
403
+ mock.patch.object(self.fetch.shutil, "which", return_value="/usr/bin/gh"), \
404
+ mock.patch.object(self.fetch.subprocess, "run", return_value=done) as run:
405
+ info = self.fetch.resolve("me", "private")
406
+ self.assertEqual(info["default_branch"], "main")
407
+ self.assertEqual(seen[0], None) # the first lookup is anonymous
408
+ self.assertEqual(seen[1], "gho_example")
409
+ run.assert_called_once()
410
+ self.assertEqual(self.fetch._token(), ("gho_example", "gh auth token"))
411
+
412
+ def test_not_found_with_a_token_names_where_it_came_from(self):
413
+ import os
414
+ os.environ["GITHUB_TOKEN"] = "ghp_example"
415
+ message = str(self.fetch.not_found("me", "private"))
416
+ self.assertIn("token from GITHUB_TOKEN can read", message)
417
+
418
+ def test_unreachable_network_is_a_message(self):
419
+ import urllib.error
420
+ from unittest import mock
421
+ failure = urllib.error.URLError("Connection refused")
422
+ with mock.patch.object(self.fetch.urllib.request, "urlopen", side_effect=failure):
423
+ with self.assertRaisesRegex(self.fetch.FetchError, "could not reach GitHub"):
424
+ self.fetch.resolve("owner", "name")
425
+
426
+ def test_spec_errors_are_still_value_errors(self):
427
+ with self.assertRaises(ValueError):
428
+ self.fetch.parse_repo("owner")
429
+
430
+ def test_try_reads_a_local_folder(self):
431
+ with tempfile.TemporaryDirectory() as td:
432
+ (Path(td) / "chrome").mkdir()
433
+ (Path(td) / "chrome/userChrome.css").write_text("#nav-bar { }\n")
434
+ code, out, _ = self.run_cli("try", td, "--info")
435
+ self.assertEqual(code, 0)
436
+ self.assertIn("trying", out)
437
+ self.assertIn("theme found at the top of the folder", out)
438
+
439
+ def test_try_reports_a_missing_folder(self):
440
+ code, _, err = self.run_cli("try", "./no-such-theme-folder", "--info")
441
+ self.assertEqual(code, 2)
442
+ self.assertIn("no folder at", err)
443
+
444
+ def test_try_reports_a_folder_without_a_theme(self):
445
+ with tempfile.TemporaryDirectory() as td:
446
+ (Path(td) / "README.md").write_text("not a theme\n")
447
+ code, _, err = self.run_cli("try", td, "--info")
448
+ self.assertEqual(code, 2)
449
+ self.assertIn("No userChrome.css anywhere in this folder", err)
450
+
451
+
352
452
  class FlagLineTests(unittest.TestCase):
353
453
  def test_readme_flag_bullets_parse(self):
354
454
  from fxcss.fetch import FLAG_LINE
@@ -86,9 +86,9 @@ class WorkflowBehaviorTests(unittest.TestCase):
86
86
  self.assertEqual(result.returncode, 1, result.stderr)
87
87
  self.assertIn("no pixel difference", result.stdout)
88
88
 
89
- def test_website_changes_skip_expensive_ci_for_pushes_and_pull_requests(self):
89
+ def test_readme_changes_skip_expensive_ci_for_pushes_and_pull_requests(self):
90
90
  ci = (Path(__file__).resolve().parents[1] / ".github/workflows/ci.yml").read_text()
91
- body = script(ci, "Identify website-only changes")
91
+ body = script(ci, "Identify README-only changes")
92
92
  repo = self.root / "scope"
93
93
  repo.mkdir()
94
94
 
@@ -100,19 +100,16 @@ class WorkflowBehaviorTests(unittest.TestCase):
100
100
  git("init")
101
101
  git("config", "user.name", "CI test")
102
102
  git("config", "user.email", "ci@example.invalid")
103
- (repo / "website").mkdir()
104
103
  (repo / "fxcss").mkdir()
105
104
  (repo / "README.md").write_text("before")
106
- (repo / "website/index.html").write_text("before")
107
105
  (repo / "fxcss/core.py").write_text("before")
108
106
  git("add", ".")
109
107
  git("commit", "-m", "base")
110
108
  base = git("rev-parse", "HEAD")
111
109
 
112
- (repo / "README.md").write_text("website documentation")
113
- (repo / "website/index.html").write_text("website update")
110
+ (repo / "README.md").write_text("documentation update")
114
111
  git("add", ".")
115
- git("commit", "-m", "website")
112
+ git("commit", "-m", "readme")
116
113
  site = git("rev-parse", "HEAD")
117
114
 
118
115
  (repo / "fxcss/core.py").write_text("toolkit update")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes