labinacan 0.1.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.
- labinacan-0.1.0/.gitignore +8 -0
- labinacan-0.1.0/CHANGELOG.md +16 -0
- labinacan-0.1.0/LICENSE +21 -0
- labinacan-0.1.0/PKG-INFO +90 -0
- labinacan-0.1.0/README.md +61 -0
- labinacan-0.1.0/labinacan/__init__.py +9 -0
- labinacan-0.1.0/labinacan/brand/logo.svg +25 -0
- labinacan-0.1.0/labinacan/brand/mark-32.png +0 -0
- labinacan-0.1.0/labinacan/brand/mark.svg +21 -0
- labinacan-0.1.0/labinacan/brand/og.png +0 -0
- labinacan-0.1.0/labinacan/cache.py +27 -0
- labinacan-0.1.0/labinacan/cli.py +213 -0
- labinacan-0.1.0/labinacan/config.py +294 -0
- labinacan-0.1.0/labinacan/data/__init__.py +1 -0
- labinacan-0.1.0/labinacan/data/offensive_words.txt +58 -0
- labinacan-0.1.0/labinacan/data/public_suffix_list.dat +15771 -0
- labinacan-0.1.0/labinacan/errors.py +9 -0
- labinacan-0.1.0/labinacan/figures/__init__.py +4 -0
- labinacan-0.1.0/labinacan/figures/motion.py +84 -0
- labinacan-0.1.0/labinacan/figures/svg.py +279 -0
- labinacan-0.1.0/labinacan/progress.py +146 -0
- labinacan-0.1.0/labinacan/sensitive.py +254 -0
- labinacan-0.1.0/labinacan/site/__init__.py +1 -0
- labinacan-0.1.0/labinacan/site/alphaxiv.py +78 -0
- labinacan-0.1.0/labinacan/site/brand.py +143 -0
- labinacan-0.1.0/labinacan/site/build.py +171 -0
- labinacan-0.1.0/labinacan/site/changelog_page.py +65 -0
- labinacan-0.1.0/labinacan/site/cluster_map.py +188 -0
- labinacan-0.1.0/labinacan/site/contents.py +111 -0
- labinacan-0.1.0/labinacan/site/css.py +187 -0
- labinacan-0.1.0/labinacan/site/disk_memo.py +63 -0
- labinacan-0.1.0/labinacan/site/feeds.py +76 -0
- labinacan-0.1.0/labinacan/site/fonts/GUST-FONT-LICENSE.txt +30 -0
- labinacan-0.1.0/labinacan/site/fonts/OFL.txt +103 -0
- labinacan-0.1.0/labinacan/site/fonts/README.md +17 -0
- labinacan-0.1.0/labinacan/site/fonts/cmu-serif-500-italic.woff2 +0 -0
- labinacan-0.1.0/labinacan/site/fonts/cmu-serif-500-roman.woff2 +0 -0
- labinacan-0.1.0/labinacan/site/fonts/cmu-serif-700-italic.woff2 +0 -0
- labinacan-0.1.0/labinacan/site/fonts/cmu-serif-700-roman.woff2 +0 -0
- labinacan-0.1.0/labinacan/site/fonts/cmu-typewriter-text-500-roman.woff2 +0 -0
- labinacan-0.1.0/labinacan/site/fonts/latinmodern-math.otf +0 -0
- labinacan-0.1.0/labinacan/site/github.py +158 -0
- labinacan-0.1.0/labinacan/site/literature_map_view.py +329 -0
- labinacan-0.1.0/labinacan/site/literature_pages.py +151 -0
- labinacan-0.1.0/labinacan/site/maths.py +83 -0
- labinacan-0.1.0/labinacan/site/palette.py +63 -0
- labinacan-0.1.0/labinacan/site/paper_pdf.py +170 -0
- labinacan-0.1.0/labinacan/site/parallel.py +144 -0
- labinacan-0.1.0/labinacan/site/pii.py +224 -0
- labinacan-0.1.0/labinacan/site/render.py +159 -0
- labinacan-0.1.0/labinacan/site/research.py +450 -0
- labinacan-0.1.0/labinacan/site/research_feeds.py +251 -0
- labinacan-0.1.0/labinacan/site/sections.py +110 -0
- labinacan-0.1.0/labinacan/site/social_media.py +275 -0
- labinacan-0.1.0/labinacan/site/takedowns.py +134 -0
- labinacan-0.1.0/labinacan/site/templates/_map_theme.html +92 -0
- labinacan-0.1.0/labinacan/site/templates/_prose.html +32 -0
- labinacan-0.1.0/labinacan/site/templates/_site_macros.html +27 -0
- labinacan-0.1.0/labinacan/site/templates/base.html +11 -0
- labinacan-0.1.0/labinacan/site/templates/changelog.html +26 -0
- labinacan-0.1.0/labinacan/site/templates/index.html +13 -0
- labinacan-0.1.0/labinacan/site/templates/literature.html +66 -0
- labinacan-0.1.0/labinacan/site/templates/paper.html +29 -0
- labinacan-0.1.0/labinacan/site/templates/paper_print.html +49 -0
- labinacan-0.1.0/labinacan/site/templates/post.html +25 -0
- labinacan-0.1.0/labinacan/site/templates/posts.html +39 -0
- labinacan-0.1.0/labinacan/site/templates/redirect.html +1 -0
- labinacan-0.1.0/labinacan/site/templates/research.html +43 -0
- labinacan-0.1.0/labinacan/site/templates/site_base.html +134 -0
- labinacan-0.1.0/labinacan/social/__init__.py +12 -0
- labinacan-0.1.0/labinacan/social/feed.py +111 -0
- labinacan-0.1.0/labinacan/social/links.py +113 -0
- labinacan-0.1.0/labinacan/social/message.py +163 -0
- labinacan-0.1.0/labinacan/social/poster.py +247 -0
- labinacan-0.1.0/labinacan/social/run.py +264 -0
- labinacan-0.1.0/labinacan/social/thread.py +226 -0
- labinacan-0.1.0/labinacan/strict.py +15 -0
- labinacan-0.1.0/labinacan/sync/__init__.py +11 -0
- labinacan-0.1.0/labinacan/sync/r2.py +315 -0
- labinacan-0.1.0/pyproject.toml +56 -0
- labinacan-0.1.0/tests/example/pyproject.toml +39 -0
- labinacan-0.1.0/tests/test_changelog_page.py +47 -0
- labinacan-0.1.0/tests/test_labinacan_boundary.py +52 -0
- labinacan-0.1.0/tests/test_labinacan_build.py +185 -0
- labinacan-0.1.0/tests/test_labinacan_cli.py +70 -0
- labinacan-0.1.0/tests/test_labinacan_config.py +127 -0
- labinacan-0.1.0/tests/test_labinacan_feeds.py +49 -0
- labinacan-0.1.0/tests/test_labinacan_github.py +129 -0
- labinacan-0.1.0/tests/test_labinacan_palette.py +30 -0
- labinacan-0.1.0/tests/test_labinacan_render.py +62 -0
- labinacan-0.1.0/tests/test_labinacan_sections.py +205 -0
- labinacan-0.1.0/tests/test_labinacan_sync.py +94 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to labinacan are listed here, newest first. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.1.0] - 2026-11-26
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- The first release of labinacan as a package of its own, from the `labinacan/` folder of [Open Interpretability](https://github.com/8W9aG/openinterpretability): the site build, the brand, the figure and motion pipeline, the social threads and the upload to R2.
|
|
12
|
+
- Extras `r2` (boto3) and `pii` (presidio-analyzer), so that the base install stays small.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- A changelog with no version heading no longer stops the site build.
|
labinacan-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Will Sackfield
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
labinacan-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: labinacan
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The generic parts of an autoresearch project: its site, papers, posts, literature reviews, figures and social posts.
|
|
5
|
+
Project-URL: Homepage, https://github.com/8W9aG/labinacan/
|
|
6
|
+
Project-URL: Repository, https://github.com/8W9aG/labinacan
|
|
7
|
+
Project-URL: Template, https://github.com/8W9aG/labinacan-template
|
|
8
|
+
Author: Will Sackfield
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering
|
|
13
|
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
|
14
|
+
Requires-Python: >=3.11
|
|
15
|
+
Requires-Dist: click>=8.1.0
|
|
16
|
+
Requires-Dist: jinja2>=3.1.3
|
|
17
|
+
Requires-Dist: latex2mathml>=3.81.1
|
|
18
|
+
Requires-Dist: markdown-it-py>=4.0
|
|
19
|
+
Requires-Dist: markupsafe>=2.1
|
|
20
|
+
Requires-Dist: mdit-py-plugins>=0.6.1
|
|
21
|
+
Requires-Dist: pydantic>=2.7.0
|
|
22
|
+
Requires-Dist: pyyaml>=6.0
|
|
23
|
+
Requires-Dist: tldextract>=5.1
|
|
24
|
+
Provides-Extra: pii
|
|
25
|
+
Requires-Dist: presidio-analyzer>=2.2; extra == 'pii'
|
|
26
|
+
Provides-Extra: r2
|
|
27
|
+
Requires-Dist: boto3>=1.34.0; extra == 'r2'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# labinacan
|
|
31
|
+
|
|
32
|
+
<img src="labinacan/brand/mark.svg" alt="labinacan's mark: a can drawn on a 3 by 3 grid" width="64">
|
|
33
|
+
|
|
34
|
+
labinacan holds the parts of an agent-run research project that do not depend on its research focus:
|
|
35
|
+
|
|
36
|
+
- the static site, with its papers, posts, literature reviews, changelog and feeds;
|
|
37
|
+
- the brand, drawn from the project's config: a mark, a wordmark and a social image;
|
|
38
|
+
- the figure and animation pipeline for papers, as SVG with CSS motion;
|
|
39
|
+
- the X threads that announce papers and posts;
|
|
40
|
+
- the upload of the built site to Cloudflare R2.
|
|
41
|
+
|
|
42
|
+
A project keeps its own research code beside the package, and sets its values in `[tool.labinacan]` of its `pyproject.toml`.
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install labinacan
|
|
48
|
+
# With the upload to R2, and the scan of published text for personal data:
|
|
49
|
+
pip install "labinacan[r2,pii]"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Start a project
|
|
53
|
+
|
|
54
|
+
Start a new project from the template, [8W9aG/labinacan-template](https://github.com/8W9aG/labinacan-template). The template holds what a project copies once and then owns: its workflows, Makefile, skills, writing rules and an example project. It installs this package from PyPI.
|
|
55
|
+
|
|
56
|
+
## Configure
|
|
57
|
+
|
|
58
|
+
A project's `pyproject.toml` gives its name, links and brand:
|
|
59
|
+
|
|
60
|
+
```toml
|
|
61
|
+
[project.urls]
|
|
62
|
+
Homepage = "https://example.org/"
|
|
63
|
+
Repository = "https://github.com/someone/a-project"
|
|
64
|
+
|
|
65
|
+
[tool.labinacan]
|
|
66
|
+
name = "A Project"
|
|
67
|
+
package = "aproject"
|
|
68
|
+
env_prefix = "APROJECT"
|
|
69
|
+
linear_team = "APR"
|
|
70
|
+
maintainer = "someone"
|
|
71
|
+
hf_dataset = "someone/a-project-inputs"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`labinacan.config` reads these values. `tests/example/pyproject.toml` is a full example, with a brand.
|
|
75
|
+
|
|
76
|
+
## Develop
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
uv sync
|
|
80
|
+
uv run ruff check .
|
|
81
|
+
uv run pytest
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Release
|
|
85
|
+
|
|
86
|
+
The version is in `labinacan/__init__.py`. Write the changes under *Unreleased* in `CHANGELOG.md`, give that section the version and the date, and push a tag `v<version>`. The *Release* workflow builds the package and publishes it to PyPI through trusted publishing, with no stored token.
|
|
87
|
+
|
|
88
|
+
## Licence
|
|
89
|
+
|
|
90
|
+
MIT. The fonts in `labinacan/site/fonts/` have their own licences, which sit beside them.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# labinacan
|
|
2
|
+
|
|
3
|
+
<img src="labinacan/brand/mark.svg" alt="labinacan's mark: a can drawn on a 3 by 3 grid" width="64">
|
|
4
|
+
|
|
5
|
+
labinacan holds the parts of an agent-run research project that do not depend on its research focus:
|
|
6
|
+
|
|
7
|
+
- the static site, with its papers, posts, literature reviews, changelog and feeds;
|
|
8
|
+
- the brand, drawn from the project's config: a mark, a wordmark and a social image;
|
|
9
|
+
- the figure and animation pipeline for papers, as SVG with CSS motion;
|
|
10
|
+
- the X threads that announce papers and posts;
|
|
11
|
+
- the upload of the built site to Cloudflare R2.
|
|
12
|
+
|
|
13
|
+
A project keeps its own research code beside the package, and sets its values in `[tool.labinacan]` of its `pyproject.toml`.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install labinacan
|
|
19
|
+
# With the upload to R2, and the scan of published text for personal data:
|
|
20
|
+
pip install "labinacan[r2,pii]"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Start a project
|
|
24
|
+
|
|
25
|
+
Start a new project from the template, [8W9aG/labinacan-template](https://github.com/8W9aG/labinacan-template). The template holds what a project copies once and then owns: its workflows, Makefile, skills, writing rules and an example project. It installs this package from PyPI.
|
|
26
|
+
|
|
27
|
+
## Configure
|
|
28
|
+
|
|
29
|
+
A project's `pyproject.toml` gives its name, links and brand:
|
|
30
|
+
|
|
31
|
+
```toml
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://example.org/"
|
|
34
|
+
Repository = "https://github.com/someone/a-project"
|
|
35
|
+
|
|
36
|
+
[tool.labinacan]
|
|
37
|
+
name = "A Project"
|
|
38
|
+
package = "aproject"
|
|
39
|
+
env_prefix = "APROJECT"
|
|
40
|
+
linear_team = "APR"
|
|
41
|
+
maintainer = "someone"
|
|
42
|
+
hf_dataset = "someone/a-project-inputs"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`labinacan.config` reads these values. `tests/example/pyproject.toml` is a full example, with a brand.
|
|
46
|
+
|
|
47
|
+
## Develop
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
uv sync
|
|
51
|
+
uv run ruff check .
|
|
52
|
+
uv run pytest
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Release
|
|
56
|
+
|
|
57
|
+
The version is in `labinacan/__init__.py`. Write the changes under *Unreleased* in `CHANGELOG.md`, give that section the version and the date, and push a tag `v<version>`. The *Release* workflow builds the package and publishes it to PyPI through trusted publishing, with no stored token.
|
|
58
|
+
|
|
59
|
+
## Licence
|
|
60
|
+
|
|
61
|
+
MIT. The fonts in `labinacan/site/fonts/` have their own licences, which sit beside them.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""labinacan: the parts of an autoresearch project that don't depend on its research focus.
|
|
2
|
+
|
|
3
|
+
A project builds its site, papers, posts and literature reviews with this package, and
|
|
4
|
+
keeps its own research code beside it. The project's values, such as its name and brand,
|
|
5
|
+
come from ``[tool.labinacan]`` in the project's ``pyproject.toml`` (``labinacan.config``).
|
|
6
|
+
The package imports nothing from the project that uses it.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 330 40" role="img" aria-label="labinacan">
|
|
2
|
+
<style>.name { fill: #0F172A; } @media (prefers-color-scheme: dark) { .name { fill: #F8FAFC; } }</style>
|
|
3
|
+
<g transform="translate(4 4)">
|
|
4
|
+
<rect width="32" height="32" rx="7" fill="#0F172A"/>
|
|
5
|
+
<rect x="5" y="5" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
6
|
+
<rect x="5" y="5" width="6" height="6" rx="1" fill="#94A3B8"/>
|
|
7
|
+
<rect x="13" y="5" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
8
|
+
<rect x="13" y="5" width="6" height="6" rx="1" fill="#94A3B8"/>
|
|
9
|
+
<rect x="21" y="5" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
10
|
+
<rect x="21" y="5" width="6" height="6" rx="1" fill="#94A3B8"/>
|
|
11
|
+
<rect x="5" y="13" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
12
|
+
<rect x="5" y="15" width="6" height="4" rx="1" fill="#2DD4BF"/>
|
|
13
|
+
<rect x="13" y="13" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
14
|
+
<rect x="13" y="13" width="6" height="6" rx="1" fill="#F59E0B"/>
|
|
15
|
+
<rect x="21" y="13" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
16
|
+
<rect x="21" y="15" width="6" height="4" rx="1" fill="#2DD4BF"/>
|
|
17
|
+
<rect x="5" y="21" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
18
|
+
<rect x="5" y="23" width="6" height="4" rx="1" fill="#2DD4BF"/>
|
|
19
|
+
<rect x="13" y="21" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
20
|
+
<rect x="13" y="21" width="6" height="6" rx="1" fill="#F59E0B"/>
|
|
21
|
+
<rect x="21" y="21" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
22
|
+
<rect x="21" y="23" width="6" height="4" rx="1" fill="#2DD4BF"/>
|
|
23
|
+
</g>
|
|
24
|
+
<text x="48" y="28" font-family="ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif" font-size="21" font-weight="600" class="name">labinacan</text>
|
|
25
|
+
</svg>
|
|
Binary file
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" role="img" aria-label="labinacan">
|
|
2
|
+
<rect width="32" height="32" rx="7" fill="#0F172A"/>
|
|
3
|
+
<rect x="5" y="5" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
4
|
+
<rect x="5" y="5" width="6" height="6" rx="1" fill="#94A3B8"/>
|
|
5
|
+
<rect x="13" y="5" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
6
|
+
<rect x="13" y="5" width="6" height="6" rx="1" fill="#94A3B8"/>
|
|
7
|
+
<rect x="21" y="5" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
8
|
+
<rect x="21" y="5" width="6" height="6" rx="1" fill="#94A3B8"/>
|
|
9
|
+
<rect x="5" y="13" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
10
|
+
<rect x="5" y="15" width="6" height="4" rx="1" fill="#2DD4BF"/>
|
|
11
|
+
<rect x="13" y="13" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
12
|
+
<rect x="13" y="13" width="6" height="6" rx="1" fill="#F59E0B"/>
|
|
13
|
+
<rect x="21" y="13" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
14
|
+
<rect x="21" y="15" width="6" height="4" rx="1" fill="#2DD4BF"/>
|
|
15
|
+
<rect x="5" y="21" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
16
|
+
<rect x="5" y="23" width="6" height="4" rx="1" fill="#2DD4BF"/>
|
|
17
|
+
<rect x="13" y="21" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
18
|
+
<rect x="13" y="21" width="6" height="6" rx="1" fill="#F59E0B"/>
|
|
19
|
+
<rect x="21" y="21" width="6" height="6" rx="1" fill="#ffffff" fill-opacity="0.16"/>
|
|
20
|
+
<rect x="21" y="23" width="6" height="4" rx="1" fill="#2DD4BF"/>
|
|
21
|
+
</svg>
|
|
Binary file
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Where a project's on-disk caches live (#6628)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def cache_root(env: str, name: str, base: Path) -> Path | None:
|
|
10
|
+
"""``$<env>``, else ``<base>/<name>``. ``None`` when ``$<env>`` turns the cache off.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
env: The environment variable that moves the cache, or turns it off.
|
|
14
|
+
name: The cache's folder in ``base``.
|
|
15
|
+
base: The project's cache folder.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
The cache's folder, or ``None`` when it is off.
|
|
19
|
+
|
|
20
|
+
Examples:
|
|
21
|
+
>>> cache_root("LAB_NO_SUCH_CACHE", "pii", Path("/c")).as_posix()
|
|
22
|
+
'/c/pii'
|
|
23
|
+
"""
|
|
24
|
+
value = os.environ.get(env)
|
|
25
|
+
if value is not None:
|
|
26
|
+
return None if value.lower() in ("", "0", "off", "false") else Path(value)
|
|
27
|
+
return base / name
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"""The commands that any project's site needs: ``deploy`` and ``social`` (#6628).
|
|
2
|
+
|
|
3
|
+
A project mounts them on its own CLI (:func:`site_commands`). ``deploy`` syncs the built site
|
|
4
|
+
to Cloudflare R2. ``social post`` reads the site's feeds of published papers and site
|
|
5
|
+
posts, and posts each new entry once (``labinacan/social``). The deploy workflow runs it
|
|
6
|
+
after each sync, with the X secrets. Without them it posts nothing and exits cleanly.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import time
|
|
12
|
+
from collections.abc import Callable
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
import click
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@click.group(name="social")
|
|
19
|
+
def social_group() -> None:
|
|
20
|
+
"""Post new published papers and site posts (#4463, #5533)."""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _entries(path: Path | None) -> list:
|
|
24
|
+
from labinacan.social.feed import read_feed
|
|
25
|
+
|
|
26
|
+
return read_feed(path) if path is not None and path.exists() else []
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@social_group.command(name="post")
|
|
30
|
+
@click.option("--papers", type=click.Path(path_type=Path), default=None,
|
|
31
|
+
help="The feed of published papers. Default: the build's.") # fmt: skip
|
|
32
|
+
@click.option("--posts", type=click.Path(path_type=Path), default=None,
|
|
33
|
+
help="The feed of site posts, never drafts. Default: the build's.") # fmt: skip
|
|
34
|
+
@click.option("--state", type=click.Path(path_type=Path), default=Path(".social/x.json"),
|
|
35
|
+
show_default=True, help="The ids posted so far.") # fmt: skip
|
|
36
|
+
@click.option("--dry-run", is_flag=True, help="Print the posts; post nothing, change no state.")
|
|
37
|
+
@click.option(
|
|
38
|
+
"--preview",
|
|
39
|
+
"newest",
|
|
40
|
+
type=int,
|
|
41
|
+
default=0,
|
|
42
|
+
help="Print the posts of the newest N entries of each feed, whatever the state.",
|
|
43
|
+
)
|
|
44
|
+
@click.option("--repost", multiple=True,
|
|
45
|
+
help="Post this entry id although the state has it, as the first run seeds "
|
|
46
|
+
"every entry (#5527). Repeat for more.") # fmt: skip
|
|
47
|
+
@click.option("--record", type=click.Path(path_type=Path), default=None,
|
|
48
|
+
help="Write the entries that this run posts, and their post URLs, here, for "
|
|
49
|
+
"`social link` (#5840).") # fmt: skip
|
|
50
|
+
def post_command(papers, posts, state, dry_run, newest, repost, record) -> None:
|
|
51
|
+
"""Post each new published paper and site post once (#5533, #6081).
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
papers: The feed of published papers, or None for the build's.
|
|
55
|
+
posts: The feed of site posts, or None for the build's.
|
|
56
|
+
state: The JSON file of the ids posted or seen so far.
|
|
57
|
+
dry_run: Print the posts, and post nothing.
|
|
58
|
+
newest: Print the posts of this many newest entries of each feed, or 0.
|
|
59
|
+
repost: Entry ids to post although the state has them.
|
|
60
|
+
record: Where to write this run's posts, or None.
|
|
61
|
+
|
|
62
|
+
Raises:
|
|
63
|
+
click.ClickException: When a post fails, for example on an HTTP or network error.
|
|
64
|
+
"""
|
|
65
|
+
from labinacan.site.research_feeds import POSTS_FEED, PUBLISHED_FEED
|
|
66
|
+
from labinacan.social.poster import XPoster, keys_from_env
|
|
67
|
+
from labinacan.social.run import State, planned, preview, run
|
|
68
|
+
|
|
69
|
+
papers = papers or Path("dist") / PUBLISHED_FEED # the paths the build writes
|
|
70
|
+
posts = posts or Path("dist") / POSTS_FEED
|
|
71
|
+
feeds = {"papers": _entries(papers), "posts": _entries(posts)}
|
|
72
|
+
if newest: # each tweet with its length and media, threads too (#5833)
|
|
73
|
+
for _, tweets in planned(State(), {k: v[:newest] for k, v in feeds.items()}):
|
|
74
|
+
click.echo(preview(tweets))
|
|
75
|
+
return
|
|
76
|
+
keys = keys_from_env()
|
|
77
|
+
if keys is None and not dry_run:
|
|
78
|
+
click.echo("The X secrets are not set, so nothing is posted.")
|
|
79
|
+
return
|
|
80
|
+
poster, posted = None if dry_run else XPoster(keys).post, []
|
|
81
|
+
try:
|
|
82
|
+
lines = run(state, feeds, poster, time.time(), frozenset(repost), posted)
|
|
83
|
+
except OSError as error: # an HTTP or network error: posts so far stay recorded
|
|
84
|
+
raise click.ClickException(f"posting failed: {error}") from error
|
|
85
|
+
finally:
|
|
86
|
+
if record is not None and posted: # what posted, even if a later post failed
|
|
87
|
+
from labinacan.social.links import write_records
|
|
88
|
+
|
|
89
|
+
write_records(record, posted)
|
|
90
|
+
click.echo("\n".join(lines))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@social_group.command(name="link")
|
|
94
|
+
@click.argument("posted", type=click.Path(exists=True, dir_okay=False, path_type=Path))
|
|
95
|
+
def link_command(posted) -> None:
|
|
96
|
+
"""Write each posted entry's X URL into its folder's media/social.json (#5840).
|
|
97
|
+
|
|
98
|
+
POSTED is the file that `social post --record` wrote. The deploy runs this, and opens
|
|
99
|
+
a PR with the files it changes.
|
|
100
|
+
|
|
101
|
+
\f
|
|
102
|
+
Args:
|
|
103
|
+
posted: The file of this run's posts.
|
|
104
|
+
"""
|
|
105
|
+
from labinacan.social.links import link
|
|
106
|
+
|
|
107
|
+
for path in link(posted):
|
|
108
|
+
click.echo(path.as_posix())
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def deploy_command(site_url_env: str, site_url: Callable[[], str | None]) -> click.Command:
|
|
112
|
+
"""The ``deploy`` command, with the project's site URL as the default.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
site_url_env: The environment variable that sets the site's URL.
|
|
116
|
+
site_url: Returns the project's site URL, or None.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
The command.
|
|
120
|
+
|
|
121
|
+
Examples:
|
|
122
|
+
>>> deploy_command("LAB_SITE_URL", lambda: None).name
|
|
123
|
+
'deploy'
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
@click.command(name="deploy")
|
|
127
|
+
@click.option("--dist-dir", default=Path("dist"), show_default=True,
|
|
128
|
+
type=click.Path(exists=True, file_okay=False, path_type=Path)) # fmt: skip
|
|
129
|
+
@click.option("--bucket", required=True, help="R2 bucket name.")
|
|
130
|
+
@click.option("--prefix", default="", help="Key prefix inside the bucket.")
|
|
131
|
+
@click.option("--delete", is_flag=True, help="Delete remote objects missing locally.")
|
|
132
|
+
@click.option("--dry-run", is_flag=True, help="Show what would change without uploading.")
|
|
133
|
+
@click.option(
|
|
134
|
+
"--site-url",
|
|
135
|
+
envvar=site_url_env,
|
|
136
|
+
default=site_url,
|
|
137
|
+
help="Public URL of the bucket root (default: the project's site URL). With CF_ZONE_ID "
|
|
138
|
+
"and CF_API_TOKEN set, the changed URLs are purged from Cloudflare's cache.",
|
|
139
|
+
)
|
|
140
|
+
def deploy(dist_dir, bucket, prefix, delete, dry_run, site_url):
|
|
141
|
+
"""Delta-sync the built site to Cloudflare R2 (a no-op when nothing changed).
|
|
142
|
+
|
|
143
|
+
\f
|
|
144
|
+
Args:
|
|
145
|
+
dist_dir: The built site.
|
|
146
|
+
bucket: The R2 bucket.
|
|
147
|
+
prefix: The key prefix inside the bucket.
|
|
148
|
+
delete: Delete remote objects that the site no longer has.
|
|
149
|
+
dry_run: Show the changes, and upload nothing.
|
|
150
|
+
site_url: The public URL of the bucket's root, for the cache purge.
|
|
151
|
+
"""
|
|
152
|
+
_deploy(dist_dir, bucket, prefix, delete, dry_run, site_url)
|
|
153
|
+
|
|
154
|
+
return deploy
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _deploy(dist_dir, bucket, prefix, delete, dry_run, site_url) -> None:
|
|
158
|
+
"""Sync ``dist_dir`` to the bucket, then purge the changed URLs from Cloudflare's cache.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
dist_dir: The built site.
|
|
162
|
+
bucket: The R2 bucket.
|
|
163
|
+
prefix: The key prefix inside the bucket.
|
|
164
|
+
delete: Delete remote objects that the site no longer has.
|
|
165
|
+
dry_run: Show the changes, and upload nothing.
|
|
166
|
+
site_url: The public URL of the bucket's root, for the cache purge.
|
|
167
|
+
"""
|
|
168
|
+
import os
|
|
169
|
+
|
|
170
|
+
from labinacan.sync.r2 import (
|
|
171
|
+
R2Config,
|
|
172
|
+
make_client,
|
|
173
|
+
purge_cloudflare_cache,
|
|
174
|
+
purge_targets,
|
|
175
|
+
sync_directory,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
client = make_client(R2Config.from_env())
|
|
179
|
+
plan = sync_directory(dist_dir, bucket, client, prefix=prefix, delete=delete,
|
|
180
|
+
dry_run=dry_run, log=click.echo) # fmt: skip
|
|
181
|
+
verb = "Would upload" if dry_run else "Uploaded"
|
|
182
|
+
click.echo(
|
|
183
|
+
f"{verb} {len(plan.uploads)}, unchanged {len(plan.unchanged)}, "
|
|
184
|
+
f"deleted {len(plan.deletes)}, derived skipped {len(plan.skipped_derived)}"
|
|
185
|
+
)
|
|
186
|
+
zone, token = os.environ.get("CF_ZONE_ID"), os.environ.get("CF_API_TOKEN")
|
|
187
|
+
if not (site_url and zone and token):
|
|
188
|
+
return
|
|
189
|
+
urls = purge_targets(plan, site_url, prefix)
|
|
190
|
+
if not urls:
|
|
191
|
+
click.echo("Nothing changed; no cache purge.")
|
|
192
|
+
elif dry_run:
|
|
193
|
+
click.echo(f"Would purge {len(urls)} URLs")
|
|
194
|
+
else:
|
|
195
|
+
purge_cloudflare_cache(zone, token, urls)
|
|
196
|
+
click.echo(f"Purged {len(urls)} URLs from the Cloudflare cache")
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def site_commands(site_url_env: str, site_url: Callable[[], str | None]) -> list[click.Command]:
|
|
200
|
+
"""The commands to mount on a project's CLI: ``deploy`` and the ``social`` group.
|
|
201
|
+
|
|
202
|
+
Args:
|
|
203
|
+
site_url_env: The environment variable that sets the site's URL.
|
|
204
|
+
site_url: Returns the project's site URL, or None.
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
The commands.
|
|
208
|
+
|
|
209
|
+
Examples:
|
|
210
|
+
>>> [c.name for c in site_commands("LAB_SITE_URL", lambda: None)]
|
|
211
|
+
['deploy', 'social']
|
|
212
|
+
"""
|
|
213
|
+
return [deploy_command(site_url_env, site_url), social_group]
|