qdocs 0.2.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.
@@ -0,0 +1,4 @@
1
+ * text=auto eol=lf
2
+ *.woff binary
3
+ *.woff2 binary
4
+ *.png binary
qdocs-0.2.0/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ *.egg-info/
3
+ build/
4
+ dist/
5
+ _site/
6
+ .jekyll-cache/
7
+ .jekyll-metadata
8
+ .ruff_cache/
qdocs-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Patrick Matthias Müller
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.
qdocs-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,199 @@
1
+ Metadata-Version: 2.5
2
+ Name: qdocs
3
+ Version: 0.2.0
4
+ Summary: The website theme and generator of qspec and qunits.
5
+ Project-URL: source, https://github.com/patmlr/qdocs
6
+ Project-URL: tracker, https://github.com/patmlr/qdocs/issues
7
+ Author-email: Patrick Müller <pamueller.ikp@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Topic :: Documentation
13
+ Classifier: Topic :: Software Development :: Documentation
14
+ Requires-Python: >=3.12
15
+ Requires-Dist: jinja2
16
+ Requires-Dist: pygments>=2.17
17
+ Description-Content-Type: text/markdown
18
+
19
+ # qdocs
20
+
21
+ The website theme and generator of [qspec](https://github.com/patmlr/qspec) and
22
+ [qunits](https://github.com/patmlr/qunits). This repository is both:
23
+
24
+ - a Jekyll theme (`_layouts/`, `_includes/`, `_sass/`, `assets/`) that GitHub Pages loads with `remote_theme`, and
25
+ - a Python package (`qdocs/`) that generates the API pages and the tutorial code blocks of a site.
26
+
27
+ ## Use it in a site
28
+
29
+ `docs/_config.yml`:
30
+
31
+ ```yaml
32
+ title: qunits
33
+ logo: /assets/img/logo.svg # The dark logo is logo_dark.svg next to it.
34
+ description: A performant, verbose and generic physical unit system.
35
+ show_downloads: true # The PyPi, GitHub and .zip links.
36
+ accent_color: "#2a7fff" # The color of the logo.
37
+ copyright: 2026 Patrick M&#252;ller. All rights reserved.
38
+ remote_theme: patmlr/qdocs@v0.2.0 # Pin a tag, so theme changes do not reach the site unnoticed.
39
+ plugins:
40
+ - jekyll-remote-theme
41
+ - jekyll-seo-tag
42
+ ```
43
+
44
+ The site provides `_data/navigation.yml` (top navigation), `_data/tutorials.yml` (tutorial list),
45
+ `_includes/badges.html` (optional) and its logos `assets/img/logo.svg`, `logo_dark.svg` and `logo_small.svg`.
46
+ Any theme file can be overridden by a file at the same path in the site. Extra styles go in `_sass/custom.scss`,
47
+ extra `<head>` tags in `_includes/head-custom.html`.
48
+
49
+ `docs/requirements.txt`, with the same version as `remote_theme`:
50
+
51
+ ```text
52
+ qdocs==0.2.0
53
+ ```
54
+
55
+ `docs/_gen/build.py`:
56
+
57
+ ```python
58
+ import os
59
+
60
+ from qdocs import Project, main
61
+
62
+ ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
63
+
64
+ PROJECT = Project(
65
+ package="qspec",
66
+ modules=["algebra", "analyze", "models", "physics"],
67
+ root=ROOT,
68
+ namespaced={"analyze", "models"}, # qspec.models.Model instead of qspec.Model.
69
+ type_aliases="qtypes", # Optional: link these type aliases in annotations to their module page.
70
+ )
71
+
72
+ if __name__ == "__main__":
73
+ main(PROJECT)
74
+ ```
75
+
76
+ ```bash
77
+ python docs/_gen/build.py [api | tutorials | logo | all]
78
+ ```
79
+
80
+ | Target | Source | Output |
81
+ |-------------|-------------------------------------------|--------------------------------------------------|
82
+ | `api` | docstrings and signatures of the package | `doc/functions/**`, `_includes/api-nav.html` |
83
+ | `tutorials` | `# docs: <name>` regions in `examples/` | `_includes/code/<name>.html` |
84
+ | `logo` | `assets/img/logo.svg` | `assets/img/logo_dark.svg` |
85
+
86
+ The module pages `doc/modules/<module>.html` and the overview `doc/doc.html` are written by hand with the `api`
87
+ layout, which adds the navigation. See `Project` in [`qdocs/project.py`](qdocs/project.py) for all options.
88
+
89
+ ### Customizations
90
+
91
+ Every class page has an Attributes section with the public class attributes, the annotated instance attributes
92
+ (including `__slots__`) and the properties of the class. Classes listed in `Project.namespaces` are documented like a
93
+ module of constants: no signature and no methods, only the description and the attributes. Enums are documented this
94
+ way automatically. Subclass `ApiBuilder` to change which attributes are listed (`attributes` returns a list of
95
+ `Attribute`) or how values are shown:
96
+
97
+ ```python
98
+ from qdocs import ApiBuilder, Project, main
99
+
100
+
101
+ class Builder(ApiBuilder):
102
+ def format_value(self, value) -> str:
103
+ if isinstance(value, Unit):
104
+ return f'<span class="default_value"><span class="class">Unit</span>(...)</span>'
105
+ return super().format_value(value)
106
+
107
+
108
+ main(PROJECT, Builder)
109
+ ```
110
+
111
+ `format_value` is used for default values in signatures and for attribute values. Color the parts of a value with
112
+ the classes `string`, `bool`, `num`, `class` and `func` inside a `default_value` span.
113
+
114
+ ## Docstrings
115
+
116
+ reST fields, with a small markup for the description texts:
117
+
118
+ ```python
119
+ def york_fit(x, y, sigma_x=None, ...):
120
+ r"""
121
+ A linear regression algorithm ... points $\vec{\mu}_i\in\mathbb{R}^2$ ...
122
+
123
+ $$\vec{\mu} = \begin{pmatrix}x\\y\end{pmatrix}.$$
124
+
125
+ The algorithm is described in
126
+ [<a href="https://doi.org/10.1119/1.1632486">York et al., Am. J. Phys. 72, 367 (2004)</a>].
127
+ See also [`linear_fit`].
128
+
129
+ :param x: The $x$ data.
130
+ :param sigma_x: The standard deviation $\sigma_x$ of the `x` data (unit of `x`).
131
+ :returns: (popt, pcov) The best y-intercept and slope and their covariance matrix.
132
+ :raises ValueError: If ...
133
+ :raises (ValueError, TypeError): Several exceptions in one field.
134
+ """
135
+ ```
136
+
137
+ - `` `code` `` and raw HTML (e.g. links to papers) are passed through.
138
+ - `$inline$` and `$$block$$` math is rendered by MathJax. Block math always stands on its own line on the website.
139
+ - `` [`name`] `` links to a documented object: `fit`, `King.fit`, `qspec.models.fit`, `qspec.physics.doppler`
140
+ or a module such as `qspec.analyze`. Unknown or ambiguous names stop the build.
141
+ - Blank lines separate paragraphs, lines starting with `- ` form a list.
142
+ - A leading `(name)` in `:returns:` labels the return value(s), otherwise it is shown as `out`.
143
+ - Types are taken from the annotations as written in the source.
144
+ - Methods without a docstring inherit the docstring of the overridden method.
145
+ - The signature and the parameters of a class are those of `__init__`, or of `__new__` if only that is overridden.
146
+ A class that overrides neither has no signature.
147
+ - Attributes are described by a string below their assignment or annotation in the class body, properties by their
148
+ docstring:
149
+
150
+ ```python
151
+ class Unit:
152
+ scale: float
153
+ """The scale factor of the unit relative to the SI base units."""
154
+ ```
155
+
156
+ The generator warns about parameters that are missing in the docstring or the signature.
157
+
158
+ ## Tutorial code
159
+
160
+ Mark a block in an example script and include it in a tutorial page:
161
+
162
+ ```python
163
+ # examples/tutorial_2.py
164
+ # docs: hfs-0
165
+ import qspec as qs
166
+
167
+ ...
168
+ # docs: end
169
+ ```
170
+
171
+ ```html
172
+ <!-- docs/tutorials/hfs.html -->
173
+ {% include code/hfs-0.html %}
174
+ ```
175
+
176
+ A script may contain several regions. The generator fails on unclosed or duplicate regions and on includes without a
177
+ matching region.
178
+
179
+ ## Developing the theme
180
+
181
+ ```bash
182
+ pip install -e .
183
+ python -m qdocs css # _sass/qdocs/pycode.scss from the Pygments styles in qdocs/tutorials.py.
184
+ python -m qdocs preview ../qspec/docs # Serve a site with this checkout instead of its remote_theme.
185
+ python -m qdocs preview ../qunits/docs build
186
+ ```
187
+
188
+ `preview` copies the theme and the site into a temporary folder, rerun it after changes.
189
+
190
+ All colors are CSS custom properties in [`assets/css/style.scss`](assets/css/style.scss): the light values on `:root`,
191
+ the dark values in the `dark-colors` mixin. The code highlighting styles are `STYLE` and `STYLE_DARK` in
192
+ [`qdocs/tutorials.py`](qdocs/tutorials.py).
193
+
194
+ To release, run the workflow on main (Actions > Build and release > Run workflow) and choose the version bump. It
195
+ publishes the package to PyPI and creates the tag `vX.Y.Z` and a GitHub release. Then update `remote_theme` and
196
+ `requirements.txt` of the sites. The version of a checkout is derived from the latest tag with hatch-vcs.
197
+
198
+ The base styles and the Noto Sans fonts are from [jekyll-theme-minimal](https://github.com/pages-themes/minimal)
199
+ (CC0 1.0).
qdocs-0.2.0/README.md ADDED
@@ -0,0 +1,181 @@
1
+ # qdocs
2
+
3
+ The website theme and generator of [qspec](https://github.com/patmlr/qspec) and
4
+ [qunits](https://github.com/patmlr/qunits). This repository is both:
5
+
6
+ - a Jekyll theme (`_layouts/`, `_includes/`, `_sass/`, `assets/`) that GitHub Pages loads with `remote_theme`, and
7
+ - a Python package (`qdocs/`) that generates the API pages and the tutorial code blocks of a site.
8
+
9
+ ## Use it in a site
10
+
11
+ `docs/_config.yml`:
12
+
13
+ ```yaml
14
+ title: qunits
15
+ logo: /assets/img/logo.svg # The dark logo is logo_dark.svg next to it.
16
+ description: A performant, verbose and generic physical unit system.
17
+ show_downloads: true # The PyPi, GitHub and .zip links.
18
+ accent_color: "#2a7fff" # The color of the logo.
19
+ copyright: 2026 Patrick M&#252;ller. All rights reserved.
20
+ remote_theme: patmlr/qdocs@v0.2.0 # Pin a tag, so theme changes do not reach the site unnoticed.
21
+ plugins:
22
+ - jekyll-remote-theme
23
+ - jekyll-seo-tag
24
+ ```
25
+
26
+ The site provides `_data/navigation.yml` (top navigation), `_data/tutorials.yml` (tutorial list),
27
+ `_includes/badges.html` (optional) and its logos `assets/img/logo.svg`, `logo_dark.svg` and `logo_small.svg`.
28
+ Any theme file can be overridden by a file at the same path in the site. Extra styles go in `_sass/custom.scss`,
29
+ extra `<head>` tags in `_includes/head-custom.html`.
30
+
31
+ `docs/requirements.txt`, with the same version as `remote_theme`:
32
+
33
+ ```text
34
+ qdocs==0.2.0
35
+ ```
36
+
37
+ `docs/_gen/build.py`:
38
+
39
+ ```python
40
+ import os
41
+
42
+ from qdocs import Project, main
43
+
44
+ ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
45
+
46
+ PROJECT = Project(
47
+ package="qspec",
48
+ modules=["algebra", "analyze", "models", "physics"],
49
+ root=ROOT,
50
+ namespaced={"analyze", "models"}, # qspec.models.Model instead of qspec.Model.
51
+ type_aliases="qtypes", # Optional: link these type aliases in annotations to their module page.
52
+ )
53
+
54
+ if __name__ == "__main__":
55
+ main(PROJECT)
56
+ ```
57
+
58
+ ```bash
59
+ python docs/_gen/build.py [api | tutorials | logo | all]
60
+ ```
61
+
62
+ | Target | Source | Output |
63
+ |-------------|-------------------------------------------|--------------------------------------------------|
64
+ | `api` | docstrings and signatures of the package | `doc/functions/**`, `_includes/api-nav.html` |
65
+ | `tutorials` | `# docs: <name>` regions in `examples/` | `_includes/code/<name>.html` |
66
+ | `logo` | `assets/img/logo.svg` | `assets/img/logo_dark.svg` |
67
+
68
+ The module pages `doc/modules/<module>.html` and the overview `doc/doc.html` are written by hand with the `api`
69
+ layout, which adds the navigation. See `Project` in [`qdocs/project.py`](qdocs/project.py) for all options.
70
+
71
+ ### Customizations
72
+
73
+ Every class page has an Attributes section with the public class attributes, the annotated instance attributes
74
+ (including `__slots__`) and the properties of the class. Classes listed in `Project.namespaces` are documented like a
75
+ module of constants: no signature and no methods, only the description and the attributes. Enums are documented this
76
+ way automatically. Subclass `ApiBuilder` to change which attributes are listed (`attributes` returns a list of
77
+ `Attribute`) or how values are shown:
78
+
79
+ ```python
80
+ from qdocs import ApiBuilder, Project, main
81
+
82
+
83
+ class Builder(ApiBuilder):
84
+ def format_value(self, value) -> str:
85
+ if isinstance(value, Unit):
86
+ return f'<span class="default_value"><span class="class">Unit</span>(...)</span>'
87
+ return super().format_value(value)
88
+
89
+
90
+ main(PROJECT, Builder)
91
+ ```
92
+
93
+ `format_value` is used for default values in signatures and for attribute values. Color the parts of a value with
94
+ the classes `string`, `bool`, `num`, `class` and `func` inside a `default_value` span.
95
+
96
+ ## Docstrings
97
+
98
+ reST fields, with a small markup for the description texts:
99
+
100
+ ```python
101
+ def york_fit(x, y, sigma_x=None, ...):
102
+ r"""
103
+ A linear regression algorithm ... points $\vec{\mu}_i\in\mathbb{R}^2$ ...
104
+
105
+ $$\vec{\mu} = \begin{pmatrix}x\\y\end{pmatrix}.$$
106
+
107
+ The algorithm is described in
108
+ [<a href="https://doi.org/10.1119/1.1632486">York et al., Am. J. Phys. 72, 367 (2004)</a>].
109
+ See also [`linear_fit`].
110
+
111
+ :param x: The $x$ data.
112
+ :param sigma_x: The standard deviation $\sigma_x$ of the `x` data (unit of `x`).
113
+ :returns: (popt, pcov) The best y-intercept and slope and their covariance matrix.
114
+ :raises ValueError: If ...
115
+ :raises (ValueError, TypeError): Several exceptions in one field.
116
+ """
117
+ ```
118
+
119
+ - `` `code` `` and raw HTML (e.g. links to papers) are passed through.
120
+ - `$inline$` and `$$block$$` math is rendered by MathJax. Block math always stands on its own line on the website.
121
+ - `` [`name`] `` links to a documented object: `fit`, `King.fit`, `qspec.models.fit`, `qspec.physics.doppler`
122
+ or a module such as `qspec.analyze`. Unknown or ambiguous names stop the build.
123
+ - Blank lines separate paragraphs, lines starting with `- ` form a list.
124
+ - A leading `(name)` in `:returns:` labels the return value(s), otherwise it is shown as `out`.
125
+ - Types are taken from the annotations as written in the source.
126
+ - Methods without a docstring inherit the docstring of the overridden method.
127
+ - The signature and the parameters of a class are those of `__init__`, or of `__new__` if only that is overridden.
128
+ A class that overrides neither has no signature.
129
+ - Attributes are described by a string below their assignment or annotation in the class body, properties by their
130
+ docstring:
131
+
132
+ ```python
133
+ class Unit:
134
+ scale: float
135
+ """The scale factor of the unit relative to the SI base units."""
136
+ ```
137
+
138
+ The generator warns about parameters that are missing in the docstring or the signature.
139
+
140
+ ## Tutorial code
141
+
142
+ Mark a block in an example script and include it in a tutorial page:
143
+
144
+ ```python
145
+ # examples/tutorial_2.py
146
+ # docs: hfs-0
147
+ import qspec as qs
148
+
149
+ ...
150
+ # docs: end
151
+ ```
152
+
153
+ ```html
154
+ <!-- docs/tutorials/hfs.html -->
155
+ {% include code/hfs-0.html %}
156
+ ```
157
+
158
+ A script may contain several regions. The generator fails on unclosed or duplicate regions and on includes without a
159
+ matching region.
160
+
161
+ ## Developing the theme
162
+
163
+ ```bash
164
+ pip install -e .
165
+ python -m qdocs css # _sass/qdocs/pycode.scss from the Pygments styles in qdocs/tutorials.py.
166
+ python -m qdocs preview ../qspec/docs # Serve a site with this checkout instead of its remote_theme.
167
+ python -m qdocs preview ../qunits/docs build
168
+ ```
169
+
170
+ `preview` copies the theme and the site into a temporary folder, rerun it after changes.
171
+
172
+ All colors are CSS custom properties in [`assets/css/style.scss`](assets/css/style.scss): the light values on `:root`,
173
+ the dark values in the `dark-colors` mixin. The code highlighting styles are `STYLE` and `STYLE_DARK` in
174
+ [`qdocs/tutorials.py`](qdocs/tutorials.py).
175
+
176
+ To release, run the workflow on main (Actions > Build and release > Run workflow) and choose the version bump. It
177
+ publishes the package to PyPI and creates the tag `vX.Y.Z` and a GitHub release. Then update `remote_theme` and
178
+ `requirements.txt` of the sites. The version of a checkout is derived from the latest tag with hatch-vcs.
179
+
180
+ The base styles and the Noto Sans fonts are from [jekyll-theme-minimal](https://github.com/pages-themes/minimal)
181
+ (CC0 1.0).
@@ -0,0 +1,84 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27", "hatch-vcs>=0.5"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "qdocs"
7
+ dynamic = ["version"]
8
+ description = "The website theme and generator of qspec and qunits."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.12"
13
+ authors = [
14
+ {name = "Patrick Müller", email = "pamueller.ikp@gmail.com"},
15
+ ]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3 :: Only",
19
+ "Topic :: Documentation",
20
+ "Topic :: Software Development :: Documentation",
21
+ ]
22
+ dependencies = [
23
+ "jinja2",
24
+ "pygments>=2.17",
25
+ ]
26
+
27
+ [project.urls]
28
+ source = "https://github.com/patmlr/qdocs"
29
+ tracker = "https://github.com/patmlr/qdocs/issues"
30
+
31
+ [tool.hatch.version]
32
+ source = "vcs"
33
+ fallback-version = "0.0.0"
34
+
35
+ [tool.hatch.build.targets.wheel]
36
+ packages = ["qdocs"]
37
+
38
+ [tool.hatch.build.targets.sdist]
39
+ exclude = [
40
+ ".github/",
41
+ "_includes/",
42
+ "_layouts/",
43
+ "_sass/",
44
+ "assets/",
45
+ ]
46
+
47
+ [tool.ruff]
48
+ extend-exclude = [
49
+ "__pycache__",
50
+ "_includes",
51
+ "_layouts",
52
+ "_sass",
53
+ "assets",
54
+ ]
55
+ line-length = 120
56
+ target-version = "py312"
57
+
58
+ [tool.ruff.lint]
59
+ select = [
60
+ "ANN",
61
+ "E",
62
+ "F",
63
+ "I",
64
+ "ICN",
65
+ "ISC",
66
+ "NPY",
67
+ "Q",
68
+ "RET",
69
+ "RUF",
70
+ "SIM",
71
+ "TC",
72
+ "TID",
73
+ "UP",
74
+ ]
75
+
76
+ ignore = [
77
+ "ANN003",
78
+ "ANN401",
79
+ "E741",
80
+ "RUF012",
81
+ ]
82
+
83
+ [tool.ruff.lint.isort]
84
+ known-first-party = ["qdocs"]
@@ -0,0 +1,8 @@
1
+ """
2
+ The website theme and generator of qspec and qunits.
3
+ """
4
+
5
+ from qdocs.build import ApiBuilder, Attribute, main
6
+ from qdocs.project import Project
7
+
8
+ __all__ = ["ApiBuilder", "Attribute", "Project", "main"]
@@ -0,0 +1,75 @@
1
+ """
2
+ Commands for the theme itself. Run from a checkout of the qdocs repository:
3
+
4
+ python -m qdocs css
5
+ python -m qdocs preview <docs> [build | serve] [jekyll options]
6
+
7
+ - css: the Pygments styles _sass/qdocs/pycode.scss.
8
+ - preview: builds or serves a site with the theme of this checkout instead of its remote_theme, e.g. to try theme
9
+ changes before they are pushed. The site and the theme are copied into a temporary folder, rerun after changes.
10
+ """
11
+
12
+ import argparse
13
+ import os
14
+ import re
15
+ import shutil
16
+ import subprocess
17
+ import sys
18
+ import tempfile
19
+
20
+ from qdocs import tutorials
21
+ from qdocs.build import write
22
+
23
+ THEME = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
24
+ THEME_DIRS = ["_layouts", "_includes", "_sass", "assets"]
25
+ PYCODE_FILE = os.path.join(THEME, "_sass", "qdocs", "pycode.scss")
26
+
27
+
28
+ def preview(docs: str, command: str, options: list[str]) -> int:
29
+ docs = os.path.abspath(docs)
30
+ site = os.path.join(tempfile.gettempdir(), "qdocs-preview", os.path.basename(os.path.dirname(docs)))
31
+ if os.path.exists(site):
32
+ shutil.rmtree(site)
33
+ for d in THEME_DIRS:
34
+ shutil.copytree(os.path.join(THEME, d), os.path.join(site, d))
35
+ ignore = shutil.ignore_patterns("_site", ".jekyll-cache", ".jekyll-metadata")
36
+ shutil.copytree(docs, site, ignore=ignore, dirs_exist_ok=True) # Files of the site override the theme.
37
+
38
+ config = os.path.join(site, "_config.yml")
39
+ with open(config, encoding="utf-8") as f:
40
+ text = re.sub(r"^remote_theme:.*$", "", f.read(), flags=re.MULTILINE)
41
+ write(config, text)
42
+
43
+ env = dict(os.environ, BUNDLE_GEMFILE=os.path.join(docs, "Gemfile"))
44
+ # The copy is not a git repository, site.github needs the repository of the site.
45
+ origin = subprocess.run(
46
+ ["git", "-C", docs, "remote", "get-url", "origin"], capture_output=True, text=True, check=False
47
+ ).stdout
48
+ m = re.search(r"github\.com[:/](.+?)(?:\.git)?\s*$", origin)
49
+ if m and "PAGES_REPO_NWO" not in env:
50
+ env["PAGES_REPO_NWO"] = m.group(1)
51
+ args = ["bundle", "exec", "jekyll", command, "-d", os.path.join(site, "_site"), *options]
52
+ print(f"Running {' '.join(args)} in {site}")
53
+ return subprocess.call(args, cwd=site, env=env, shell=sys.platform == "win32")
54
+
55
+
56
+ def main() -> None:
57
+ parser = argparse.ArgumentParser(description="Commands for the qdocs theme.")
58
+ sub = parser.add_subparsers(dest="target", required=True)
59
+ sub.add_parser("css", help="Generate _sass/qdocs/pycode.scss.")
60
+ p = sub.add_parser("preview", help="Build or serve a site with the theme of this checkout.")
61
+ p.add_argument("docs", help="The Jekyll site, e.g. ../qspec/docs.")
62
+ p.add_argument("command", nargs="?", default="serve", choices=["build", "serve"])
63
+ args, options = parser.parse_known_args()
64
+
65
+ if not os.path.isdir(os.path.join(THEME, "_sass", "qdocs")):
66
+ sys.exit("The theme files are not next to the qdocs package. Run this from a checkout of the repository.")
67
+ if args.target == "css":
68
+ write(PYCODE_FILE, tutorials.pycode_css())
69
+ print(f"Wrote {os.path.relpath(PYCODE_FILE, THEME)}.")
70
+ else:
71
+ sys.exit(preview(args.docs, args.command, options))
72
+
73
+
74
+ if __name__ == "__main__":
75
+ main()