fxcss 0.22.1__tar.gz → 0.24.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.
- {fxcss-0.22.1 → fxcss-0.24.0}/PKG-INFO +39 -6
- {fxcss-0.22.1 → fxcss-0.24.0}/README.md +38 -5
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/__init__.py +1 -1
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/cli.py +61 -12
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/core.py +3 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/fetch.py +114 -14
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/templates/firefox-watch.yml +13 -7
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss.egg-info/PKG-INFO +39 -6
- {fxcss-0.22.1 → fxcss-0.24.0}/tests/test_units.py +174 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/tests/test_workflows.py +21 -7
- {fxcss-0.22.1 → fxcss-0.24.0}/LICENSE +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/__main__.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/adopt.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/audit.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/capture.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/catalogue.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/check.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/compare.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/complete.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/install.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/omni.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/probe.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/scaffold.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/sheets.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/templates/pr-preview-cleanup.yml +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/templates/pr-preview-publish.yml +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/templates/pr-preview.yml +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/templates/readme-previews.yml +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/templates/showcase.yml +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/templates/starter/chrome/userChrome.css +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/templates/starter/custom/accent-red.css +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss/tweaks.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss.egg-info/SOURCES.txt +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss.egg-info/dependency_links.txt +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss.egg-info/entry_points.txt +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss.egg-info/requires.txt +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/fxcss.egg-info/top_level.txt +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/pyproject.toml +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/setup.cfg +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/tests/test_capture_coverage.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/tests/test_checks.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.0}/tests/test_patch_duplicates.py +0 -0
- {fxcss-0.22.1 → fxcss-0.24.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.
|
|
3
|
+
Version: 0.24.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
|
-
|
|
355
|
-
|
|
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`
|
|
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.
|
|
1149
|
+
- run: pip install "fxcss[images]==0.23.0"
|
|
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.
|
|
1304
|
+
pip install "fxcss[images]==0.23.0"
|
|
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
|
-
|
|
332
|
-
|
|
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`
|
|
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.
|
|
1126
|
+
- run: pip install "fxcss[images]==0.23.0"
|
|
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.
|
|
1281
|
+
pip install "fxcss[images]==0.23.0"
|
|
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
|
|
@@ -199,9 +199,26 @@ def cmd_try(args):
|
|
|
199
199
|
from . import fetch
|
|
200
200
|
|
|
201
201
|
_install_signal_handlers()
|
|
202
|
-
|
|
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
|
|
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
|
-
|
|
221
|
-
|
|
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
|
-
|
|
225
|
-
|
|
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
|
-
|
|
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"]:
|
|
@@ -1581,6 +1605,16 @@ def cmd_inspect(args):
|
|
|
1581
1605
|
|
|
1582
1606
|
|
|
1583
1607
|
def cmd_audit(args):
|
|
1608
|
+
try:
|
|
1609
|
+
return _run_audit(args)
|
|
1610
|
+
except (OSError, ValueError, RuntimeError) as exc:
|
|
1611
|
+
# 1 means a completed audit found something actionable. A broken
|
|
1612
|
+
# browser/session is a different result, not evidence of dead CSS.
|
|
1613
|
+
print(f"error: audit could not complete: {exc}", file=sys.stderr)
|
|
1614
|
+
return 2
|
|
1615
|
+
|
|
1616
|
+
|
|
1617
|
+
def _run_audit(args):
|
|
1584
1618
|
from . import audit, omni
|
|
1585
1619
|
theme = args.theme.resolve()
|
|
1586
1620
|
firefox = choose_firefox(args.firefox)
|
|
@@ -1589,7 +1623,8 @@ def cmd_audit(args):
|
|
|
1589
1623
|
if pack:
|
|
1590
1624
|
print(f" shipped chrome read from "
|
|
1591
1625
|
f"{', '.join(str(p) for p in pack['paths'])}\n")
|
|
1592
|
-
static =
|
|
1626
|
+
static = (audit.collect_unused(theme)
|
|
1627
|
+
if args.strict_vars or not args.no_unused else None)
|
|
1593
1628
|
with core.Session(theme, firefox) as session:
|
|
1594
1629
|
result = audit.audit(session, theme, pack=pack)
|
|
1595
1630
|
|
|
@@ -1612,7 +1647,7 @@ def cmd_audit(args):
|
|
|
1612
1647
|
known = audit.probe_properties(vanilla, candidates)
|
|
1613
1648
|
unused = audit.classify_unused(static, known, pack=pack)
|
|
1614
1649
|
audit.report(result, show_all=args.all, colour=not args.no_colour)
|
|
1615
|
-
if unused:
|
|
1650
|
+
if unused and not args.no_unused:
|
|
1616
1651
|
audit.report_unused(unused, colour=not args.no_colour, show_all=args.all)
|
|
1617
1652
|
if args.patch:
|
|
1618
1653
|
files = audit.write_patch(result, theme, args.patch.resolve())
|
|
@@ -1635,6 +1670,13 @@ def cmd_audit(args):
|
|
|
1635
1670
|
f"propert{'ies' if len(dead_vars) != 1 else 'y'} no longer "
|
|
1636
1671
|
f"do{'es' if len(dead_vars) == 1 else ''} anything "
|
|
1637
1672
|
f"(mark deliberate ones /* fxcss-keep */)\n")
|
|
1673
|
+
if args.no_unused:
|
|
1674
|
+
# The report that names them was hidden, and a failure that
|
|
1675
|
+
# does not say which properties is not actionable.
|
|
1676
|
+
for item in dead_vars:
|
|
1677
|
+
where = f"{item['file']}:{item['line']}" if item.get("file") else ""
|
|
1678
|
+
print(f" {item['name']:<44} {where}".rstrip())
|
|
1679
|
+
print()
|
|
1638
1680
|
failing = 1
|
|
1639
1681
|
return failing
|
|
1640
1682
|
|
|
@@ -1868,10 +1910,10 @@ def build_parser():
|
|
|
1868
1910
|
sub = ap.add_subparsers(dest="cmd", required=False)
|
|
1869
1911
|
|
|
1870
1912
|
tr = sub.add_parser(
|
|
1871
|
-
"try", help="
|
|
1913
|
+
"try", help="test-drive a theme from GitHub or a folder in a throwaway profile",
|
|
1872
1914
|
epilog="Looking for themes? Browse firefoxcss-store.github.io or "
|
|
1873
1915
|
"r/FirefoxCSS — anything with a userChrome.css on GitHub works.")
|
|
1874
|
-
tr.add_argument("repo", help="owner/name,
|
|
1916
|
+
tr.add_argument("repo", help="owner/name, a github.com URL, or a local theme folder")
|
|
1875
1917
|
tr.add_argument("--firefox", default=None,
|
|
1876
1918
|
help="a channel/fork name (e.g. nightly, dev, esr) or a binary path")
|
|
1877
1919
|
tr.add_argument("--ref", default=None, help="tag, branch or commit to fetch")
|
|
@@ -2203,7 +2245,14 @@ def main(argv=None):
|
|
|
2203
2245
|
sys.stdout.reconfigure(line_buffering=True)
|
|
2204
2246
|
except AttributeError:
|
|
2205
2247
|
pass
|
|
2206
|
-
|
|
2248
|
+
from .fetch import FetchError
|
|
2249
|
+
try:
|
|
2250
|
+
return args.func(args)
|
|
2251
|
+
except FetchError as exc:
|
|
2252
|
+
# Expected problems (a missing or private repository, no network, a
|
|
2253
|
+
# refused download) get a message saying what to try, not a traceback.
|
|
2254
|
+
print(f"\nerror: {exc}", file=sys.stderr)
|
|
2255
|
+
return 2
|
|
2207
2256
|
|
|
2208
2257
|
|
|
2209
2258
|
if __name__ == "__main__":
|
|
@@ -482,6 +482,9 @@ class Session:
|
|
|
482
482
|
env = dict(os.environ)
|
|
483
483
|
env["MOZ_DISABLE_AUTO_SAFE_MODE"] = "1"
|
|
484
484
|
env["MOZ_CRASHREPORTER_DISABLE"] = "1"
|
|
485
|
+
# Newer Firefox builds use the environment opt-in for system access.
|
|
486
|
+
# Keep the command-line flag as well for older Firefox builds.
|
|
487
|
+
env["MOZ_REMOTE_ALLOW_SYSTEM_ACCESS"] = "1"
|
|
485
488
|
# Chrome UI does not paint in headless mode.
|
|
486
489
|
env.pop("MOZ_HEADLESS", None)
|
|
487
490
|
cmd = [self.firefox, "--profile", str(self.profile), *LAUNCH_FLAGS,
|
|
@@ -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
|
|
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
|
-
|
|
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
|
|
82
|
-
"GitHub refused the request (rate limit). Set GITHUB_TOKEN
|
|
83
|
-
"raise it
|
|
84
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
378
|
+
|
|
379
|
+
def fetch():
|
|
297
380
|
with urllib.request.urlopen(_request(url, accept="*/*"), timeout=180) as response:
|
|
298
|
-
|
|
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
|
-
|
|
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
|
|
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:
|
|
@@ -89,8 +89,8 @@ jobs:
|
|
|
89
89
|
cat audit.txt
|
|
90
90
|
echo "status=$status" >> "$GITHUB_OUTPUT"
|
|
91
91
|
|
|
92
|
-
version
|
|
93
|
-
|
|
92
|
+
# Read the build version without needing a working Marionette session.
|
|
93
|
+
version=$(python -c 'import os; from fxcss import core; print(core.firefox_version(os.environ["FIREFOX_BIN"]) or "unknown")')
|
|
94
94
|
echo "version=${version:-unknown}" >> "$GITHUB_OUTPUT"
|
|
95
95
|
if [ -s fxcss-fix.patch ]; then echo "patch=yes" >> "$GITHUB_OUTPUT"; fi
|
|
96
96
|
|
|
@@ -163,7 +163,7 @@ jobs:
|
|
|
163
163
|
fi
|
|
164
164
|
|
|
165
165
|
- name: Open a pull request with the confident fixes
|
|
166
|
-
if: steps.audit.outcome == 'success' && steps.audit.outputs.status
|
|
166
|
+
if: steps.audit.outcome == 'success' && steps.audit.outputs.status == '1' && steps.audit.outputs.patch == 'yes'
|
|
167
167
|
env:
|
|
168
168
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
169
169
|
CHANNEL: ${{ matrix.channel }}
|
|
@@ -218,7 +218,7 @@ jobs:
|
|
|
218
218
|
--body-file body.md
|
|
219
219
|
|
|
220
220
|
- name: Open or update the heads-up issue
|
|
221
|
-
if: steps.audit.outcome == 'success' && steps.audit.outputs.status
|
|
221
|
+
if: steps.audit.outcome == 'success' && steps.audit.outputs.status == '1' && steps.audit.outputs.patch != 'yes'
|
|
222
222
|
env:
|
|
223
223
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
224
224
|
CHANNEL: ${{ matrix.channel }}
|
|
@@ -227,9 +227,9 @@ jobs:
|
|
|
227
227
|
set -euo pipefail
|
|
228
228
|
title="Firefox ${CHANNEL}: selectors need attention"
|
|
229
229
|
{
|
|
230
|
-
echo "Firefox **${CHANNEL}** is now **${VERSION}**. Some selectors
|
|
231
|
-
echo "
|
|
232
|
-
echo "
|
|
230
|
+
echo "Firefox **${CHANNEL}** is now **${VERSION}**. Some CSS selectors or"
|
|
231
|
+
echo "custom-property overrides need attention. No safe automatic"
|
|
232
|
+
echo "replacement was available for these findings."
|
|
233
233
|
echo
|
|
234
234
|
echo '```'
|
|
235
235
|
cat audit.txt
|
|
@@ -260,6 +260,12 @@ jobs:
|
|
|
260
260
|
--comment "Firefox ${CHANNEL} audits clean again — closing."
|
|
261
261
|
fi
|
|
262
262
|
|
|
263
|
+
- name: Fail when Firefox could not be checked
|
|
264
|
+
if: (steps.audit.outcome == 'success' && steps.audit.outputs.status != '0' && steps.audit.outputs.status != '1') || (steps.smoke.outcome == 'success' && steps.smoke.outputs.status != '0')
|
|
265
|
+
run: |
|
|
266
|
+
echo "::error::Firefox could not be audited or captured. See the audit and smoke artifacts."
|
|
267
|
+
exit 1
|
|
268
|
+
|
|
263
269
|
- uses: actions/upload-artifact@v7
|
|
264
270
|
if: always()
|
|
265
271
|
with:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fxcss
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.24.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
|
-
|
|
355
|
-
|
|
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`
|
|
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.
|
|
1149
|
+
- run: pip install "fxcss[images]==0.23.0"
|
|
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.
|
|
1304
|
+
pip install "fxcss[images]==0.23.0"
|
|
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
|
|
@@ -383,7 +483,81 @@ class SamplePagesTests(unittest.TestCase):
|
|
|
383
483
|
self.assertEqual(build_pages(), build_pages())
|
|
384
484
|
|
|
385
485
|
|
|
486
|
+
class AuditExitStatusTests(unittest.TestCase):
|
|
487
|
+
def run_audit(self, **changes):
|
|
488
|
+
import argparse
|
|
489
|
+
import contextlib
|
|
490
|
+
import io
|
|
491
|
+
from unittest.mock import Mock, patch
|
|
492
|
+
from fxcss import cli, core, audit, omni
|
|
493
|
+
args = argparse.Namespace(theme=Path("."), firefox="firefox", no_unused=True,
|
|
494
|
+
strict=True, strict_vars=False, no_colour=True,
|
|
495
|
+
all=False, patch=None)
|
|
496
|
+
for name, value in changes.items():
|
|
497
|
+
setattr(args, name, value)
|
|
498
|
+
self.static = {"used": {}, "defined": {"--old-token": []}}
|
|
499
|
+
self.unused = getattr(self, "unused", None) or {
|
|
500
|
+
"unused_properties": [{"name": "--old-token"}], "stale_overrides": []}
|
|
501
|
+
with patch.object(cli, "choose_firefox", return_value="firefox"), patch.object(
|
|
502
|
+
omni, "scan", return_value={"paths": []}), patch.object(core, "Session") as session, patch.object(
|
|
503
|
+
audit, "audit", return_value={"findings": []}), patch.object(audit, "report"), patch.object(
|
|
504
|
+
audit, "collect_unused", return_value=self.static) as collect, patch.object(
|
|
505
|
+
audit, "classify_unused", return_value=self.unused), patch.object(audit, "report_unused") as report, contextlib.redirect_stderr(
|
|
506
|
+
io.StringIO()) as err, contextlib.redirect_stdout(io.StringIO()) as out:
|
|
507
|
+
if getattr(self, "failure", None):
|
|
508
|
+
session.side_effect = self.failure
|
|
509
|
+
result = cli.cmd_audit(args)
|
|
510
|
+
self.stdout = out.getvalue()
|
|
511
|
+
return result, collect.call_count, report.call_count, err.getvalue()
|
|
512
|
+
|
|
513
|
+
def test_browser_failure_is_not_a_selector_finding(self):
|
|
514
|
+
from fxcss import core
|
|
515
|
+
self.failure = core.MarionetteError("system access is required")
|
|
516
|
+
code, _, _, error = self.run_audit()
|
|
517
|
+
self.assertEqual(code, 2)
|
|
518
|
+
self.assertIn("audit could not complete", error)
|
|
519
|
+
self.assertNotIn("Traceback", error)
|
|
520
|
+
|
|
521
|
+
def test_hidden_unused_section_does_not_disable_explicit_strict_vars(self):
|
|
522
|
+
code, collected, reported, _ = self.run_audit(strict_vars=True)
|
|
523
|
+
self.assertEqual(code, 1)
|
|
524
|
+
self.assertEqual(collected, 1)
|
|
525
|
+
self.assertEqual(reported, 0)
|
|
526
|
+
# With the report hidden, the failure itself has to name the property.
|
|
527
|
+
self.assertIn("--old-token", self.stdout)
|
|
528
|
+
|
|
529
|
+
def test_strict_vars_failure_says_where_each_property_is_set(self):
|
|
530
|
+
self.unused = {"unused_properties": [],
|
|
531
|
+
"stale_overrides": [{"name": "--stale-token", "file": "chrome/theme.css", "line": 12}]}
|
|
532
|
+
code, _, _, _ = self.run_audit(strict_vars=True)
|
|
533
|
+
self.assertEqual(code, 1)
|
|
534
|
+
self.assertIn("--stale-token", self.stdout)
|
|
535
|
+
self.assertIn("chrome/theme.css:12", self.stdout)
|
|
536
|
+
|
|
537
|
+
def test_no_unused_still_skips_checks_without_strict_vars(self):
|
|
538
|
+
code, collected, _, _ = self.run_audit()
|
|
539
|
+
self.assertEqual((code, collected), (0, 0))
|
|
540
|
+
|
|
541
|
+
|
|
386
542
|
class SessionCleanupTests(unittest.TestCase):
|
|
543
|
+
def test_system_access_is_enabled_only_for_the_owned_browser(self):
|
|
544
|
+
import os
|
|
545
|
+
from unittest.mock import Mock, patch
|
|
546
|
+
from fxcss import core
|
|
547
|
+
session = core.Session.__new__(core.Session)
|
|
548
|
+
session.firefox = "firefox"
|
|
549
|
+
session.profile = Path("temporary-profile")
|
|
550
|
+
session.port = 4242
|
|
551
|
+
session.apply_harness_css = Mock()
|
|
552
|
+
with patch.dict(os.environ, {"MOZ_REMOTE_ALLOW_SYSTEM_ACCESS": "0", "MOZ_HEADLESS": "1"}), patch.object(
|
|
553
|
+
core.subprocess, "Popen") as launch, patch.object(core, "Marionette"):
|
|
554
|
+
session._start_browser()
|
|
555
|
+
child = launch.call_args.kwargs["env"]
|
|
556
|
+
self.assertEqual(child["MOZ_REMOTE_ALLOW_SYSTEM_ACCESS"], "1")
|
|
557
|
+
self.assertNotIn("MOZ_HEADLESS", child)
|
|
558
|
+
self.assertEqual(os.environ["MOZ_REMOTE_ALLOW_SYSTEM_ACCESS"], "0")
|
|
559
|
+
self.assertEqual(os.environ["MOZ_HEADLESS"], "1")
|
|
560
|
+
|
|
387
561
|
def test_windows_timeout_kills_only_the_owned_launcher_tree_and_waits(self):
|
|
388
562
|
from unittest.mock import Mock, call, patch
|
|
389
563
|
from fxcss import core
|
|
@@ -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
|
|
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
|
|
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("
|
|
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", "
|
|
112
|
+
git("commit", "-m", "readme")
|
|
116
113
|
site = git("rev-parse", "HEAD")
|
|
117
114
|
|
|
118
115
|
(repo / "fxcss/core.py").write_text("toolkit update")
|
|
@@ -164,6 +161,23 @@ class WorkflowBehaviorTests(unittest.TestCase):
|
|
|
164
161
|
self.assertEqual((work / "compact-diff.png").read_bytes(), b"option crop")
|
|
165
162
|
self.assertFalse((work / "crops").exists())
|
|
166
163
|
|
|
164
|
+
def test_startup_failure_does_not_open_a_selector_issue_or_patch(self):
|
|
165
|
+
text = self.workflow("firefox-watch.yml")
|
|
166
|
+
values = {"steps.audit.outcome": "success", "steps.audit.outputs.status": "2",
|
|
167
|
+
"steps.audit.outputs.patch": "yes", "steps.smoke.outcome": "success",
|
|
168
|
+
"steps.smoke.outputs.status": "2"}
|
|
169
|
+
for name in ("Open or update the heads-up issue", "Open a pull request with the confident fixes"):
|
|
170
|
+
guard = re.search(r"^ if: (.+)$", step(text, name), re.M)[1]
|
|
171
|
+
self.assertFalse(condition(guard, values), name)
|
|
172
|
+
for name in ("Open or update the capture-pipeline issue", "Fail when Firefox could not be checked"):
|
|
173
|
+
guard = re.search(r"^ if: (.+)$", step(text, name), re.M)[1]
|
|
174
|
+
self.assertTrue(condition(guard, values), name)
|
|
175
|
+
values["steps.smoke.outputs.status"] = "0"
|
|
176
|
+
guard = re.search(r"^ if: (.+)$", step(text, "Fail when Firefox could not be checked"), re.M)[1]
|
|
177
|
+
self.assertTrue(condition(guard, values))
|
|
178
|
+
values["steps.audit.outputs.status"] = "1"
|
|
179
|
+
self.assertFalse(condition(guard, values))
|
|
180
|
+
|
|
167
181
|
def test_single_channel_watch_never_handles_results_for_skipped_channels(self):
|
|
168
182
|
text = self.workflow("firefox-watch.yml")
|
|
169
183
|
actions = ["Open or update the capture-pipeline issue",
|
|
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
|
|
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
|