versite 0.0.1__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.
- versite-0.0.1/PKG-INFO +222 -0
- versite-0.0.1/README.md +213 -0
- versite-0.0.1/pyproject.toml +29 -0
- versite-0.0.1/setup.cfg +4 -0
- versite-0.0.1/tests/test_cli.py +17 -0
- versite-0.0.1/tests/test_command_builder.py +44 -0
- versite-0.0.1/tests/test_config.py +36 -0
- versite-0.0.1/tests/test_deploy.py +92 -0
- versite-0.0.1/tests/test_non_build_commands_do_not_import_builders.py +33 -0
- versite-0.0.1/tests/test_non_build_commands_do_not_run_builders.py +24 -0
- versite-0.0.1/tests/test_redirects.py +16 -0
- versite-0.0.1/tests/test_versions.py +33 -0
- versite-0.0.1/versite/__init__.py +3 -0
- versite-0.0.1/versite/builders/__init__.py +1 -0
- versite-0.0.1/versite/builders/command.py +66 -0
- versite-0.0.1/versite/cli.py +182 -0
- versite-0.0.1/versite/commands.py +406 -0
- versite-0.0.1/versite/config.py +139 -0
- versite-0.0.1/versite/git_utils.py +145 -0
- versite-0.0.1/versite/jsonpath.py +81 -0
- versite-0.0.1/versite/redirects.py +24 -0
- versite-0.0.1/versite/serve.py +16 -0
- versite-0.0.1/versite/templates/__init__.py +1 -0
- versite-0.0.1/versite/templates/redirect.html +11 -0
- versite-0.0.1/versite/versions.py +111 -0
- versite-0.0.1/versite.egg-info/PKG-INFO +222 -0
- versite-0.0.1/versite.egg-info/SOURCES.txt +29 -0
- versite-0.0.1/versite.egg-info/dependency_links.txt +1 -0
- versite-0.0.1/versite.egg-info/entry_points.txt +2 -0
- versite-0.0.1/versite.egg-info/requires.txt +2 -0
- versite-0.0.1/versite.egg-info/top_level.txt +1 -0
versite-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: versite
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Versioned static-site deployments with builder isolation
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: PyYAML>=6.0
|
|
8
|
+
Requires-Dist: Jinja2>=3.1
|
|
9
|
+
|
|
10
|
+
# versite
|
|
11
|
+
|
|
12
|
+
`versite` is a generic versioned static-site deployment tool inspired by `mike`, but it is not coupled to MkDocs. It manages a deployment branch containing multiple published site versions, aliases, redirects, and per-version metadata. Only `versite deploy` is allowed to invoke a site builder.
|
|
13
|
+
|
|
14
|
+
## Why it exists
|
|
15
|
+
|
|
16
|
+
`mike` is tightly centered on MkDocs. `versite` separates the problem into two layers:
|
|
17
|
+
|
|
18
|
+
1. A versioned static-site manager that edits `versions.json`, alias paths, redirects, and the target git branch.
|
|
19
|
+
2. A command-based builder runner that invokes builders as external subprocesses only during `deploy`.
|
|
20
|
+
|
|
21
|
+
That separation means non-build commands stay fast and reliable:
|
|
22
|
+
|
|
23
|
+
- `versite list`
|
|
24
|
+
- `versite delete`
|
|
25
|
+
- `versite alias`
|
|
26
|
+
- `versite retitle`
|
|
27
|
+
- `versite props`
|
|
28
|
+
- `versite set-default`
|
|
29
|
+
- `versite serve`
|
|
30
|
+
|
|
31
|
+
Those commands do not import MkDocs, load MkDocs config, run MkDocs plugin hooks, invoke Jekyll, or shell out to any builder.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install -e .
|
|
37
|
+
versite --help
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Configuration
|
|
41
|
+
|
|
42
|
+
`versite` reads `versite.yml` if present. The config loader only uses lightweight YAML parsing.
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
builder: mkdocs
|
|
46
|
+
remote: origin
|
|
47
|
+
branch: gh-pages
|
|
48
|
+
deploy_prefix: ""
|
|
49
|
+
alias_type: redirect
|
|
50
|
+
redirect_template: null
|
|
51
|
+
push: false
|
|
52
|
+
|
|
53
|
+
builders:
|
|
54
|
+
mkdocs:
|
|
55
|
+
command:
|
|
56
|
+
- mkdocs
|
|
57
|
+
- build
|
|
58
|
+
- --clean
|
|
59
|
+
- --config-file
|
|
60
|
+
- "{config_file}"
|
|
61
|
+
- --site-dir
|
|
62
|
+
- "{output_dir}"
|
|
63
|
+
config_file: mkdocs.yml
|
|
64
|
+
|
|
65
|
+
jekyll:
|
|
66
|
+
command:
|
|
67
|
+
- bundle
|
|
68
|
+
- exec
|
|
69
|
+
- jekyll
|
|
70
|
+
- build
|
|
71
|
+
- --source
|
|
72
|
+
- "{source}"
|
|
73
|
+
- --destination
|
|
74
|
+
- "{output_dir}"
|
|
75
|
+
source: .
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
CLI flags override config values.
|
|
79
|
+
|
|
80
|
+
## MkDocs usage
|
|
81
|
+
|
|
82
|
+
MkDocs support is implemented only as a command template. `versite` never imports `mkdocs`.
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
versite deploy 1.0 latest --builder mkdocs
|
|
86
|
+
versite list
|
|
87
|
+
versite set-default latest
|
|
88
|
+
versite delete 0.9
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
During `deploy`, the MkDocs builder receives:
|
|
92
|
+
|
|
93
|
+
- `VERSITE_VERSION=<version>`
|
|
94
|
+
- `MIKE_DOCS_VERSION=<version>`
|
|
95
|
+
|
|
96
|
+
## Jekyll usage
|
|
97
|
+
|
|
98
|
+
Jekyll support is also command-template based.
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
versite deploy 1.0 latest --builder jekyll
|
|
102
|
+
versite list
|
|
103
|
+
versite alias 1.0 stable
|
|
104
|
+
versite set-default latest
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`versite` does not import Jekyll-related Python libraries. It only runs the configured command during `deploy`.
|
|
108
|
+
|
|
109
|
+
## Custom builders
|
|
110
|
+
|
|
111
|
+
Custom builders can be added through `versite.yml` without changing Python code:
|
|
112
|
+
|
|
113
|
+
```yaml
|
|
114
|
+
builder: custom
|
|
115
|
+
|
|
116
|
+
builders:
|
|
117
|
+
custom:
|
|
118
|
+
command:
|
|
119
|
+
- npm
|
|
120
|
+
- run
|
|
121
|
+
- build
|
|
122
|
+
- --
|
|
123
|
+
- --outDir
|
|
124
|
+
- "{output_dir}"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Example:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
versite deploy 1.0 latest --builder custom
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Command reference
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
versite deploy VERSION [ALIAS...]
|
|
137
|
+
versite list [IDENTIFIER]
|
|
138
|
+
versite delete [IDENTIFIER...] [--all]
|
|
139
|
+
versite alias IDENTIFIER [ALIAS...]
|
|
140
|
+
versite retitle IDENTIFIER TITLE
|
|
141
|
+
versite props IDENTIFIER [PROP]
|
|
142
|
+
versite set-default IDENTIFIER
|
|
143
|
+
versite serve
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Important options:
|
|
147
|
+
|
|
148
|
+
- `--config-file FILE`
|
|
149
|
+
- `--builder NAME`
|
|
150
|
+
- `-r, --remote REMOTE`
|
|
151
|
+
- `-b, --branch BRANCH`
|
|
152
|
+
- `-m, --message MESSAGE`
|
|
153
|
+
- `-p, --push`
|
|
154
|
+
- `--allow-empty`
|
|
155
|
+
- `--deploy-prefix PATH`
|
|
156
|
+
- `--alias-type {redirect,copy,symlink}`
|
|
157
|
+
- `-T, --template FILE`
|
|
158
|
+
- `--ignore-remote-status`
|
|
159
|
+
- `--source DIR`
|
|
160
|
+
- `--output-dir DIR`
|
|
161
|
+
- `--build-command ...`
|
|
162
|
+
- `-q, --quiet`
|
|
163
|
+
- `--json`
|
|
164
|
+
|
|
165
|
+
## Alias modes
|
|
166
|
+
|
|
167
|
+
- `redirect`: writes static HTML redirects. This is the default and works well on GitHub Pages.
|
|
168
|
+
- `copy`: copies the deployed version directory into each alias directory.
|
|
169
|
+
- `symlink`: creates symlink aliases in the target branch for compatibility-focused setups.
|
|
170
|
+
|
|
171
|
+
## GitHub Pages
|
|
172
|
+
|
|
173
|
+
`versite` is designed for branch-based static hosting. A common setup is `gh-pages` with redirect aliases and a root `index.html` redirect created by `set-default`.
|
|
174
|
+
|
|
175
|
+
Example MkDocs config:
|
|
176
|
+
|
|
177
|
+
```yaml
|
|
178
|
+
builder: mkdocs
|
|
179
|
+
branch: gh-pages
|
|
180
|
+
alias_type: redirect
|
|
181
|
+
|
|
182
|
+
builders:
|
|
183
|
+
mkdocs:
|
|
184
|
+
command:
|
|
185
|
+
- mkdocs
|
|
186
|
+
- build
|
|
187
|
+
- --clean
|
|
188
|
+
- --config-file
|
|
189
|
+
- "{config_file}"
|
|
190
|
+
- --site-dir
|
|
191
|
+
- "{output_dir}"
|
|
192
|
+
config_file: mkdocs.yml
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Example Jekyll config:
|
|
196
|
+
|
|
197
|
+
```yaml
|
|
198
|
+
builder: jekyll
|
|
199
|
+
branch: gh-pages
|
|
200
|
+
alias_type: redirect
|
|
201
|
+
|
|
202
|
+
builders:
|
|
203
|
+
jekyll:
|
|
204
|
+
command:
|
|
205
|
+
- bundle
|
|
206
|
+
- exec
|
|
207
|
+
- jekyll
|
|
208
|
+
- build
|
|
209
|
+
- --source
|
|
210
|
+
- "{source}"
|
|
211
|
+
- --destination
|
|
212
|
+
- "{output_dir}"
|
|
213
|
+
source: .
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Migration from mike
|
|
217
|
+
|
|
218
|
+
- `mike deploy` roughly maps to `versite deploy --builder mkdocs`.
|
|
219
|
+
- `mike list`, `delete`, `alias`, `retitle`, `props`, and `set-default` roughly map to the same `versite` subcommands.
|
|
220
|
+
- Unlike `mike`, non-build commands do not load MkDocs config.
|
|
221
|
+
- Shared deployment settings should move into `versite.yml`.
|
|
222
|
+
- `VERSITE_VERSION` is the generic build env var. MkDocs builders also receive `MIKE_DOCS_VERSION` for compatibility.
|
versite-0.0.1/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# versite
|
|
2
|
+
|
|
3
|
+
`versite` is a generic versioned static-site deployment tool inspired by `mike`, but it is not coupled to MkDocs. It manages a deployment branch containing multiple published site versions, aliases, redirects, and per-version metadata. Only `versite deploy` is allowed to invoke a site builder.
|
|
4
|
+
|
|
5
|
+
## Why it exists
|
|
6
|
+
|
|
7
|
+
`mike` is tightly centered on MkDocs. `versite` separates the problem into two layers:
|
|
8
|
+
|
|
9
|
+
1. A versioned static-site manager that edits `versions.json`, alias paths, redirects, and the target git branch.
|
|
10
|
+
2. A command-based builder runner that invokes builders as external subprocesses only during `deploy`.
|
|
11
|
+
|
|
12
|
+
That separation means non-build commands stay fast and reliable:
|
|
13
|
+
|
|
14
|
+
- `versite list`
|
|
15
|
+
- `versite delete`
|
|
16
|
+
- `versite alias`
|
|
17
|
+
- `versite retitle`
|
|
18
|
+
- `versite props`
|
|
19
|
+
- `versite set-default`
|
|
20
|
+
- `versite serve`
|
|
21
|
+
|
|
22
|
+
Those commands do not import MkDocs, load MkDocs config, run MkDocs plugin hooks, invoke Jekyll, or shell out to any builder.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install -e .
|
|
28
|
+
versite --help
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Configuration
|
|
32
|
+
|
|
33
|
+
`versite` reads `versite.yml` if present. The config loader only uses lightweight YAML parsing.
|
|
34
|
+
|
|
35
|
+
```yaml
|
|
36
|
+
builder: mkdocs
|
|
37
|
+
remote: origin
|
|
38
|
+
branch: gh-pages
|
|
39
|
+
deploy_prefix: ""
|
|
40
|
+
alias_type: redirect
|
|
41
|
+
redirect_template: null
|
|
42
|
+
push: false
|
|
43
|
+
|
|
44
|
+
builders:
|
|
45
|
+
mkdocs:
|
|
46
|
+
command:
|
|
47
|
+
- mkdocs
|
|
48
|
+
- build
|
|
49
|
+
- --clean
|
|
50
|
+
- --config-file
|
|
51
|
+
- "{config_file}"
|
|
52
|
+
- --site-dir
|
|
53
|
+
- "{output_dir}"
|
|
54
|
+
config_file: mkdocs.yml
|
|
55
|
+
|
|
56
|
+
jekyll:
|
|
57
|
+
command:
|
|
58
|
+
- bundle
|
|
59
|
+
- exec
|
|
60
|
+
- jekyll
|
|
61
|
+
- build
|
|
62
|
+
- --source
|
|
63
|
+
- "{source}"
|
|
64
|
+
- --destination
|
|
65
|
+
- "{output_dir}"
|
|
66
|
+
source: .
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
CLI flags override config values.
|
|
70
|
+
|
|
71
|
+
## MkDocs usage
|
|
72
|
+
|
|
73
|
+
MkDocs support is implemented only as a command template. `versite` never imports `mkdocs`.
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
versite deploy 1.0 latest --builder mkdocs
|
|
77
|
+
versite list
|
|
78
|
+
versite set-default latest
|
|
79
|
+
versite delete 0.9
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
During `deploy`, the MkDocs builder receives:
|
|
83
|
+
|
|
84
|
+
- `VERSITE_VERSION=<version>`
|
|
85
|
+
- `MIKE_DOCS_VERSION=<version>`
|
|
86
|
+
|
|
87
|
+
## Jekyll usage
|
|
88
|
+
|
|
89
|
+
Jekyll support is also command-template based.
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
versite deploy 1.0 latest --builder jekyll
|
|
93
|
+
versite list
|
|
94
|
+
versite alias 1.0 stable
|
|
95
|
+
versite set-default latest
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`versite` does not import Jekyll-related Python libraries. It only runs the configured command during `deploy`.
|
|
99
|
+
|
|
100
|
+
## Custom builders
|
|
101
|
+
|
|
102
|
+
Custom builders can be added through `versite.yml` without changing Python code:
|
|
103
|
+
|
|
104
|
+
```yaml
|
|
105
|
+
builder: custom
|
|
106
|
+
|
|
107
|
+
builders:
|
|
108
|
+
custom:
|
|
109
|
+
command:
|
|
110
|
+
- npm
|
|
111
|
+
- run
|
|
112
|
+
- build
|
|
113
|
+
- --
|
|
114
|
+
- --outDir
|
|
115
|
+
- "{output_dir}"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Example:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
versite deploy 1.0 latest --builder custom
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Command reference
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
versite deploy VERSION [ALIAS...]
|
|
128
|
+
versite list [IDENTIFIER]
|
|
129
|
+
versite delete [IDENTIFIER...] [--all]
|
|
130
|
+
versite alias IDENTIFIER [ALIAS...]
|
|
131
|
+
versite retitle IDENTIFIER TITLE
|
|
132
|
+
versite props IDENTIFIER [PROP]
|
|
133
|
+
versite set-default IDENTIFIER
|
|
134
|
+
versite serve
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Important options:
|
|
138
|
+
|
|
139
|
+
- `--config-file FILE`
|
|
140
|
+
- `--builder NAME`
|
|
141
|
+
- `-r, --remote REMOTE`
|
|
142
|
+
- `-b, --branch BRANCH`
|
|
143
|
+
- `-m, --message MESSAGE`
|
|
144
|
+
- `-p, --push`
|
|
145
|
+
- `--allow-empty`
|
|
146
|
+
- `--deploy-prefix PATH`
|
|
147
|
+
- `--alias-type {redirect,copy,symlink}`
|
|
148
|
+
- `-T, --template FILE`
|
|
149
|
+
- `--ignore-remote-status`
|
|
150
|
+
- `--source DIR`
|
|
151
|
+
- `--output-dir DIR`
|
|
152
|
+
- `--build-command ...`
|
|
153
|
+
- `-q, --quiet`
|
|
154
|
+
- `--json`
|
|
155
|
+
|
|
156
|
+
## Alias modes
|
|
157
|
+
|
|
158
|
+
- `redirect`: writes static HTML redirects. This is the default and works well on GitHub Pages.
|
|
159
|
+
- `copy`: copies the deployed version directory into each alias directory.
|
|
160
|
+
- `symlink`: creates symlink aliases in the target branch for compatibility-focused setups.
|
|
161
|
+
|
|
162
|
+
## GitHub Pages
|
|
163
|
+
|
|
164
|
+
`versite` is designed for branch-based static hosting. A common setup is `gh-pages` with redirect aliases and a root `index.html` redirect created by `set-default`.
|
|
165
|
+
|
|
166
|
+
Example MkDocs config:
|
|
167
|
+
|
|
168
|
+
```yaml
|
|
169
|
+
builder: mkdocs
|
|
170
|
+
branch: gh-pages
|
|
171
|
+
alias_type: redirect
|
|
172
|
+
|
|
173
|
+
builders:
|
|
174
|
+
mkdocs:
|
|
175
|
+
command:
|
|
176
|
+
- mkdocs
|
|
177
|
+
- build
|
|
178
|
+
- --clean
|
|
179
|
+
- --config-file
|
|
180
|
+
- "{config_file}"
|
|
181
|
+
- --site-dir
|
|
182
|
+
- "{output_dir}"
|
|
183
|
+
config_file: mkdocs.yml
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Example Jekyll config:
|
|
187
|
+
|
|
188
|
+
```yaml
|
|
189
|
+
builder: jekyll
|
|
190
|
+
branch: gh-pages
|
|
191
|
+
alias_type: redirect
|
|
192
|
+
|
|
193
|
+
builders:
|
|
194
|
+
jekyll:
|
|
195
|
+
command:
|
|
196
|
+
- bundle
|
|
197
|
+
- exec
|
|
198
|
+
- jekyll
|
|
199
|
+
- build
|
|
200
|
+
- --source
|
|
201
|
+
- "{source}"
|
|
202
|
+
- --destination
|
|
203
|
+
- "{output_dir}"
|
|
204
|
+
source: .
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Migration from mike
|
|
208
|
+
|
|
209
|
+
- `mike deploy` roughly maps to `versite deploy --builder mkdocs`.
|
|
210
|
+
- `mike list`, `delete`, `alias`, `retitle`, `props`, and `set-default` roughly map to the same `versite` subcommands.
|
|
211
|
+
- Unlike `mike`, non-build commands do not load MkDocs config.
|
|
212
|
+
- Shared deployment settings should move into `versite.yml`.
|
|
213
|
+
- `VERSITE_VERSION` is the generic build env var. MkDocs builders also receive `MIKE_DOCS_VERSION` for compatibility.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "versite"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "Versioned static-site deployments with builder isolation"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"PyYAML>=6.0",
|
|
13
|
+
"Jinja2>=3.1",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.scripts]
|
|
17
|
+
versite = "versite.cli:main"
|
|
18
|
+
|
|
19
|
+
[tool.setuptools]
|
|
20
|
+
include-package-data = true
|
|
21
|
+
|
|
22
|
+
[tool.setuptools.packages.find]
|
|
23
|
+
include = ["versite*"]
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.package-data]
|
|
26
|
+
"versite.templates" = ["*.html"]
|
|
27
|
+
|
|
28
|
+
[tool.pytest.ini_options]
|
|
29
|
+
testpaths = ["tests"]
|
versite-0.0.1/setup.cfg
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from versite.cli import build_parser, main
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_help_parser_exists() -> None:
|
|
7
|
+
parser = build_parser()
|
|
8
|
+
assert parser.prog == "versite"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_help_command(capsys) -> None:
|
|
12
|
+
try:
|
|
13
|
+
main(["--help"])
|
|
14
|
+
except SystemExit as exc:
|
|
15
|
+
assert exc.code == 0
|
|
16
|
+
captured = capsys.readouterr()
|
|
17
|
+
assert "deploy" in captured.out
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from versite.builders.command import load_builder
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_builder_runs_command_and_sets_env(tmp_path: Path) -> None:
|
|
11
|
+
script = tmp_path / "builder.py"
|
|
12
|
+
script.write_text(
|
|
13
|
+
"import os, pathlib, sys\n"
|
|
14
|
+
"out = pathlib.Path(sys.argv[1])\n"
|
|
15
|
+
"out.mkdir(parents=True, exist_ok=True)\n"
|
|
16
|
+
"(out / 'index.html').write_text(os.environ['VERSITE_VERSION'])\n",
|
|
17
|
+
encoding="utf-8",
|
|
18
|
+
)
|
|
19
|
+
config = {
|
|
20
|
+
"builders": {
|
|
21
|
+
"custom": {
|
|
22
|
+
"command": [sys.executable, str(script), "{output_dir}"],
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
builder = load_builder("custom", config)
|
|
27
|
+
result = builder.build(version="2.0", output_dir=str(tmp_path / "out"), config={}, quiet=False)
|
|
28
|
+
assert Path(result.site_dir).joinpath("index.html").read_text(encoding="utf-8") == "2.0"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_mkdocs_builder_sets_compat_env(tmp_path: Path, monkeypatch) -> None:
|
|
32
|
+
observed = {}
|
|
33
|
+
|
|
34
|
+
def fake_run(command, **kwargs):
|
|
35
|
+
observed["command"] = command
|
|
36
|
+
observed["env"] = kwargs["env"]
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
monkeypatch.setattr("subprocess.run", fake_run)
|
|
40
|
+
config = {"builders": {"mkdocs": {"command": ["mkdocs", "build", "--site-dir", "{output_dir}"]}}}
|
|
41
|
+
builder = load_builder("mkdocs", config)
|
|
42
|
+
builder.build(version="3.0", output_dir=str(tmp_path / "out"), config={}, quiet=True)
|
|
43
|
+
assert observed["env"]["VERSITE_VERSION"] == "3.0"
|
|
44
|
+
assert observed["env"]["MIKE_DOCS_VERSION"] == "3.0"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from versite.config import DEFAULT_CONFIG, apply_cli_overrides, load_config
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_load_defaults_without_file(tmp_path: Path, monkeypatch) -> None:
|
|
9
|
+
monkeypatch.chdir(tmp_path)
|
|
10
|
+
config, path = load_config()
|
|
11
|
+
assert path is None
|
|
12
|
+
assert config["builder"] == DEFAULT_CONFIG["builder"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_load_config_file(tmp_path: Path) -> None:
|
|
16
|
+
config_file = tmp_path / "versite.yml"
|
|
17
|
+
config_file.write_text("branch: docs\nbuilders:\n mkdocs:\n config_file: docs.yml\n", encoding="utf-8")
|
|
18
|
+
config, path = load_config(config_file)
|
|
19
|
+
assert path == config_file
|
|
20
|
+
assert config["branch"] == "docs"
|
|
21
|
+
assert config["builders"]["mkdocs"]["config_file"] == "docs.yml"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_cli_overrides_builder_values() -> None:
|
|
25
|
+
config = apply_cli_overrides(
|
|
26
|
+
DEFAULT_CONFIG,
|
|
27
|
+
builder="jekyll",
|
|
28
|
+
branch="pages",
|
|
29
|
+
deploy_prefix="docs",
|
|
30
|
+
source="site",
|
|
31
|
+
build_command=["bundle", "exec", "jekyll", "build"],
|
|
32
|
+
)
|
|
33
|
+
assert config["builder"] == "jekyll"
|
|
34
|
+
assert config["branch"] == "pages"
|
|
35
|
+
assert config["deploy_prefix"] == "docs"
|
|
36
|
+
assert config["builders"]["jekyll"]["source"] == "site"
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from versite.cli import main
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _show_file(repo: Path, branch: str, path: str) -> str:
|
|
12
|
+
result = subprocess.run(
|
|
13
|
+
["git", "show", f"{branch}:{path}"],
|
|
14
|
+
cwd=repo,
|
|
15
|
+
check=True,
|
|
16
|
+
capture_output=True,
|
|
17
|
+
text=True,
|
|
18
|
+
)
|
|
19
|
+
return result.stdout
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_deploy_custom_builder(git_repo: Path, tmp_path: Path) -> None:
|
|
23
|
+
script = tmp_path / "custom_builder.py"
|
|
24
|
+
script.write_text(
|
|
25
|
+
"import os, pathlib, sys\n"
|
|
26
|
+
"out = pathlib.Path(sys.argv[1])\n"
|
|
27
|
+
"out.mkdir(parents=True, exist_ok=True)\n"
|
|
28
|
+
"(out / 'index.html').write_text(os.environ['VERSITE_VERSION'])\n",
|
|
29
|
+
encoding="utf-8",
|
|
30
|
+
)
|
|
31
|
+
config = git_repo / "versite.yml"
|
|
32
|
+
config.write_text(
|
|
33
|
+
"builder: custom\n"
|
|
34
|
+
"branch: gh-pages\n"
|
|
35
|
+
"builders:\n"
|
|
36
|
+
" custom:\n"
|
|
37
|
+
f" command: ['{sys.executable}', '{script}', '{{output_dir}}']\n",
|
|
38
|
+
encoding="utf-8",
|
|
39
|
+
)
|
|
40
|
+
assert main(["deploy", "2.0", "latest", "--builder", "custom", "--config-file", str(config)]) == 0
|
|
41
|
+
versions = json.loads(_show_file(git_repo, "gh-pages", "versions.json"))
|
|
42
|
+
assert any(item["version"] == "2.0" for item in versions)
|
|
43
|
+
assert _show_file(git_repo, "gh-pages", "2.0/index.html") == "2.0"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_deploy_mkdocs_command_template(git_repo: Path, tmp_path: Path) -> None:
|
|
47
|
+
script = tmp_path / "fake_mkdocs.py"
|
|
48
|
+
marker = tmp_path / "env.txt"
|
|
49
|
+
script.write_text(
|
|
50
|
+
"import os, pathlib, sys\n"
|
|
51
|
+
"out = pathlib.Path(sys.argv[-1])\n"
|
|
52
|
+
"out.mkdir(parents=True, exist_ok=True)\n"
|
|
53
|
+
"(out / 'index.html').write_text('mkdocs')\n"
|
|
54
|
+
f"pathlib.Path(r'{marker}').write_text(os.environ['MIKE_DOCS_VERSION'])\n",
|
|
55
|
+
encoding="utf-8",
|
|
56
|
+
)
|
|
57
|
+
config = git_repo / "versite.yml"
|
|
58
|
+
config.write_text(
|
|
59
|
+
"branch: gh-pages\n"
|
|
60
|
+
"builders:\n"
|
|
61
|
+
" mkdocs:\n"
|
|
62
|
+
f" command: ['{sys.executable}', '{script}', '--site-dir', '{{output_dir}}']\n",
|
|
63
|
+
encoding="utf-8",
|
|
64
|
+
)
|
|
65
|
+
assert main(["deploy", "3.0", "--builder", "mkdocs", "--config-file", str(config)]) == 0
|
|
66
|
+
assert marker.read_text(encoding="utf-8") == "3.0"
|
|
67
|
+
assert _show_file(git_repo, "gh-pages", "3.0/index.html") == "mkdocs"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_deploy_jekyll_command_template(git_repo: Path, tmp_path: Path) -> None:
|
|
71
|
+
script = tmp_path / "fake_jekyll.py"
|
|
72
|
+
marker = tmp_path / "jekyll_env.txt"
|
|
73
|
+
script.write_text(
|
|
74
|
+
"import os, pathlib, sys\n"
|
|
75
|
+
"out = pathlib.Path(sys.argv[-1])\n"
|
|
76
|
+
"out.mkdir(parents=True, exist_ok=True)\n"
|
|
77
|
+
"(out / 'index.html').write_text('jekyll')\n"
|
|
78
|
+
f"pathlib.Path(r'{marker}').write_text(os.environ['VERSITE_VERSION'])\n",
|
|
79
|
+
encoding="utf-8",
|
|
80
|
+
)
|
|
81
|
+
config = git_repo / "versite.yml"
|
|
82
|
+
config.write_text(
|
|
83
|
+
"builder: jekyll\n"
|
|
84
|
+
"branch: gh-pages\n"
|
|
85
|
+
"builders:\n"
|
|
86
|
+
" jekyll:\n"
|
|
87
|
+
f" command: ['{sys.executable}', '{script}', '--destination', '{{output_dir}}']\n",
|
|
88
|
+
encoding="utf-8",
|
|
89
|
+
)
|
|
90
|
+
assert main(["deploy", "4.0", "--builder", "jekyll", "--config-file", str(config)]) == 0
|
|
91
|
+
assert marker.read_text(encoding="utf-8") == "4.0"
|
|
92
|
+
assert _show_file(git_repo, "gh-pages", "4.0/index.html") == "jekyll"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import builtins
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from versite.cli import main
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_non_build_commands_do_not_import_mkdocs(git_repo: Path, monkeypatch) -> None:
|
|
11
|
+
original_import = builtins.__import__
|
|
12
|
+
sys.modules.pop("versite.builders.command", None)
|
|
13
|
+
|
|
14
|
+
def guarded_import(name, globals=None, locals=None, fromlist=(), level=0):
|
|
15
|
+
if name.startswith("mkdocs"):
|
|
16
|
+
raise AssertionError("mkdocs should not be imported")
|
|
17
|
+
return original_import(name, globals, locals, fromlist, level)
|
|
18
|
+
|
|
19
|
+
monkeypatch.setattr(builtins, "__import__", guarded_import)
|
|
20
|
+
commands = [
|
|
21
|
+
["list"],
|
|
22
|
+
["delete", "latest"],
|
|
23
|
+
["alias", "1.0", "stable"],
|
|
24
|
+
["retitle", "1.0", "One"],
|
|
25
|
+
["props", "1.0"],
|
|
26
|
+
["props", "1.0", "meta.channel=\"beta\""],
|
|
27
|
+
["set-default", "1.0"],
|
|
28
|
+
]
|
|
29
|
+
monkeypatch.setattr("versite.commands.serve_directory", lambda *args, **kwargs: None)
|
|
30
|
+
for argv in commands:
|
|
31
|
+
assert main([*argv, "-b", "gh-pages", "--ignore-remote-status"]) == 0
|
|
32
|
+
assert main(["serve", "-b", "gh-pages", "--ignore-remote-status"]) == 0
|
|
33
|
+
assert "versite.builders.command" not in sys.modules
|