Skip to content

Commit b1eaf9a

Browse files
authoredMar 29, 2024··
Initial commit
0 parents  commit b1eaf9a

31 files changed

+1705
-0
lines changed
 

‎.github/workflows/pages.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Simple workflow for deploying static content to GitHub Pages
2+
name: Deploy static content to Pages
3+
4+
on:
5+
# Runs on pushes targeting the default branch
6+
push:
7+
branches: ["main"]
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# Allow one concurrent deployment
19+
concurrency:
20+
group: "pages"
21+
cancel-in-progress: true
22+
23+
jobs:
24+
# Single deploy job since we're just deploying
25+
deploy:
26+
environment:
27+
name: github-pages
28+
url: ${{ steps.deployment.outputs.page_url }}
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Harden Runner
32+
uses: step-security/harden-runner@v2
33+
with:
34+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
35+
- name: Checkout
36+
uses: actions/checkout@v3
37+
- name: 🐍 Set up Python
38+
uses: actions/setup-python@v4
39+
with:
40+
python-version: "3.11"
41+
cache: "pip"
42+
cache-dependency-path: "pyproject.toml"
43+
- name: 🔧 Build HTML
44+
run: |
45+
sudo apt-get install graphviz
46+
pip install .[doc]
47+
pip install sphinxcontrib-websupport
48+
conda install -c conda-forge pandoc
49+
invoke doc
50+
- name: Setup Pages
51+
uses: actions/configure-pages@v1
52+
- name: Upload artifact
53+
uses: actions/upload-pages-artifact@v1
54+
with:
55+
# Upload entire repository
56+
path: 'doc/_build/html/'
57+
- name: Deploy to GitHub Pages
58+
id: deployment
59+
uses: actions/deploy-pages@main

‎.github/workflows/python-publish.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
10+
on:
11+
release:
12+
types: [published]
13+
14+
jobs:
15+
deploy:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Set up Python
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: "3.x"
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install build
27+
- name: Build package
28+
run: python -m build
29+
- name: Publish package
30+
uses: pypa/gh-action-pypi-publish@master
31+
with:
32+
user: __token__
33+
password: ${{ secrets.PYPI_API_TOKEN }}

‎.gitignore

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/

‎LICENSE

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
Apache License
2+
Version 2.0, January 2004
3+
http://www.apache.org/licenses/
4+
5+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6+
7+
1. Definitions.
8+
9+
"License" shall mean the terms and conditions for use, reproduction,
10+
and distribution as defined by Sections 1 through 9 of this document.
11+
12+
"Licensor" shall mean the copyright owner or entity authorized by
13+
the copyright owner that is granting the License.
14+
15+
"Legal Entity" shall mean the union of the acting entity and all
16+
other entities that control, are controlled by, or are under common
17+
control with that entity. For the purposes of this definition,
18+
"control" means (i) the power, direct or indirect, to cause the
19+
direction or management of such entity, whether by contract or
20+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
21+
outstanding shares, or (iii) beneficial ownership of such entity.
22+
23+
"You" (or "Your") shall mean an individual or Legal Entity
24+
exercising permissions granted by this License.
25+
26+
"Source" form shall mean the preferred form for making modifications,
27+
including but not limited to software source code, documentation
28+
source, and configuration files.
29+
30+
"Object" form shall mean any form resulting from mechanical
31+
transformation or translation of a Source form, including but
32+
not limited to compiled object code, generated documentation,
33+
and conversions to other media types.
34+
35+
"Work" shall mean the work of authorship, whether in Source or
36+
Object form, made available under the License, as indicated by a
37+
copyright notice that is included in or attached to the work
38+
(an example is provided in the Appendix below).
39+
40+
"Derivative Works" shall mean any work, whether in Source or Object
41+
form, that is based on (or derived from) the Work and for which the
42+
editorial revisions, annotations, elaborations, or other modifications
43+
represent, as a whole, an original work of authorship. For the purposes
44+
of this License, Derivative Works shall not include works that remain
45+
separable from, or merely link (or bind by name) to the interfaces of,
46+
the Work and Derivative Works thereof.
47+
48+
"Contribution" shall mean any work of authorship, including
49+
the original version of the Work and any modifications or additions
50+
to that Work or Derivative Works thereof, that is intentionally
51+
submitted to Licensor for inclusion in the Work by the copyright owner
52+
or by an individual or Legal Entity authorized to submit on behalf of
53+
the copyright owner. For the purposes of this definition, "submitted"
54+
means any form of electronic, verbal, or written communication sent
55+
to the Licensor or its representatives, including but not limited to
56+
communication on electronic mailing lists, source code control systems,
57+
and issue tracking systems that are managed by, or on behalf of, the
58+
Licensor for the purpose of discussing and improving the Work, but
59+
excluding communication that is conspicuously marked or otherwise
60+
designated in writing by the copyright owner as "Not a Contribution."
61+
62+
"Contributor" shall mean Licensor and any individual or Legal Entity
63+
on behalf of whom a Contribution has been received by Licensor and
64+
subsequently incorporated within the Work.
65+
66+
2. Grant of Copyright License. Subject to the terms and conditions of
67+
this License, each Contributor hereby grants to You a perpetual,
68+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69+
copyright license to reproduce, prepare Derivative Works of,
70+
publicly display, publicly perform, sublicense, and distribute the
71+
Work and such Derivative Works in Source or Object form.
72+
73+
3. Grant of Patent License. Subject to the terms and conditions of
74+
this License, each Contributor hereby grants to You a perpetual,
75+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76+
(except as stated in this section) patent license to make, have made,
77+
use, offer to sell, sell, import, and otherwise transfer the Work,
78+
where such license applies only to those patent claims licensable
79+
by such Contributor that are necessarily infringed by their
80+
Contribution(s) alone or by combination of their Contribution(s)
81+
with the Work to which such Contribution(s) was submitted. If You
82+
institute patent litigation against any entity (including a
83+
cross-claim or counterclaim in a lawsuit) alleging that the Work
84+
or a Contribution incorporated within the Work constitutes direct
85+
or contributory patent infringement, then any patent licenses
86+
granted to You under this License for that Work shall terminate
87+
as of the date such litigation is filed.
88+
89+
4. Redistribution. You may reproduce and distribute copies of the
90+
Work or Derivative Works thereof in any medium, with or without
91+
modifications, and in Source or Object form, provided that You
92+
meet the following conditions:
93+
94+
(a) You must give any other recipients of the Work or
95+
Derivative Works a copy of this License; and
96+
97+
(b) You must cause any modified files to carry prominent notices
98+
stating that You changed the files; and
99+
100+
(c) You must retain, in the Source form of any Derivative Works
101+
that You distribute, all copyright, patent, trademark, and
102+
attribution notices from the Source form of the Work,
103+
excluding those notices that do not pertain to any part of
104+
the Derivative Works; and
105+
106+
(d) If the Work includes a "NOTICE" text file as part of its
107+
distribution, then any Derivative Works that You distribute must
108+
include a readable copy of the attribution notices contained
109+
within such NOTICE file, excluding those notices that do not
110+
pertain to any part of the Derivative Works, in at least one
111+
of the following places: within a NOTICE text file distributed
112+
as part of the Derivative Works; within the Source form or
113+
documentation, if provided along with the Derivative Works; or,
114+
within a display generated by the Derivative Works, if and
115+
wherever such third-party notices normally appear. The contents
116+
of the NOTICE file are for informational purposes only and
117+
do not modify the License. You may add Your own attribution
118+
notices within Derivative Works that You distribute, alongside
119+
or as an addendum to the NOTICE text from the Work, provided
120+
that such additional attribution notices cannot be construed
121+
as modifying the License.
122+
123+
You may add Your own copyright statement to Your modifications and
124+
may provide additional or different license terms and conditions
125+
for use, reproduction, or distribution of Your modifications, or
126+
for any such Derivative Works as a whole, provided Your use,
127+
reproduction, and distribution of the Work otherwise complies with
128+
the conditions stated in this License.
129+
130+
5. Submission of Contributions. Unless You explicitly state otherwise,
131+
any Contribution intentionally submitted for inclusion in the Work
132+
by You to the Licensor shall be under the terms and conditions of
133+
this License, without any additional terms or conditions.
134+
Notwithstanding the above, nothing herein shall supersede or modify
135+
the terms of any separate license agreement you may have executed
136+
with Licensor regarding such Contributions.
137+
138+
6. Trademarks. This License does not grant permission to use the trade
139+
names, trademarks, service marks, or product names of the Licensor,
140+
except as required for reasonable and customary use in describing the
141+
origin of the Work and reproducing the content of the NOTICE file.
142+
143+
7. Disclaimer of Warranty. Unless required by applicable law or
144+
agreed to in writing, Licensor provides the Work (and each
145+
Contributor provides its Contributions) on an "AS IS" BASIS,
146+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147+
implied, including, without limitation, any warranties or conditions
148+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149+
PARTICULAR PURPOSE. You are solely responsible for determining the
150+
appropriateness of using or redistributing the Work and assume any
151+
risks associated with Your exercise of permissions under this License.
152+
153+
8. Limitation of Liability. In no event and under no legal theory,
154+
whether in tort (including negligence), contract, or otherwise,
155+
unless required by applicable law (such as deliberate and grossly
156+
negligent acts) or agreed to in writing, shall any Contributor be
157+
liable to You for damages, including any direct, indirect, special,
158+
incidental, or consequential damages of any character arising as a
159+
result of this License or out of the use or inability to use the
160+
Work (including but not limited to damages for loss of goodwill,
161+
work stoppage, computer failure or malfunction, or any and all
162+
other commercial damages or losses), even if such Contributor
163+
has been advised of the possibility of such damages.
164+
165+
9. Accepting Warranty or Additional Liability. While redistributing
166+
the Work or Derivative Works thereof, You may choose to offer,
167+
and charge a fee for, acceptance of support, warranty, indemnity,
168+
or other liability obligations and/or rights consistent with this
169+
License. However, in accepting such obligations, You may act only
170+
on Your own behalf and on Your sole responsibility, not on behalf
171+
of any other Contributor, and only if You agree to indemnify,
172+
defend, and hold each Contributor harmless for any liability
173+
incurred by, or claims asserted against, such Contributor by reason
174+
of your accepting any such warranty or additional liability.
175+
176+
END OF TERMS AND CONDITIONS
177+
178+
APPENDIX: How to apply the Apache License to your work.
179+
180+
To apply the Apache License to your work, attach the following
181+
boilerplate notice, with the fields enclosed by brackets "[]"
182+
replaced with your own identifying information. (Don't include
183+
the brackets!) The text should be enclosed in the appropriate
184+
comment syntax for the file format. We also recommend that a
185+
file or class name and description of purpose be included on the
186+
same "printed page" as the copyright notice for easier
187+
identification within third-party archives.
188+
189+
Copyright [yyyy] [name of copyright owner]
190+
191+
Licensed under the Apache License, Version 2.0 (the "License");
192+
you may not use this file except in compliance with the License.
193+
You may obtain a copy of the License at
194+
195+
http://www.apache.org/licenses/LICENSE-2.0
196+
197+
Unless required by applicable law or agreed to in writing, software
198+
distributed under the License is distributed on an "AS IS" BASIS,
199+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200+
See the License for the specific language governing permissions and
201+
limitations under the License.

‎README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# 笔记模板
2+
3+
![repo size](https://img.shields.io/github/repo-size/xinetzone/xbook.svg)
4+
[![PyPI][pypi-badge]][pypi-link]
5+
[![GitHub issues][issue-badge]][issue-link]
6+
[![GitHub forks][fork-badge]][fork-link]
7+
[![GitHub stars][star-badge]][star-link]
8+
[![GitHub license][license-badge]][license-link]
9+
[![contributors][contributor-badge]][contributor-link]
10+
[![watcher][watcher-badge]][watcher-link]
11+
[![Binder][binder-badge]][binder-link]
12+
[![Downloads][download-badge]][download-link]
13+
[![Documentation Status][status-badge]][status-link]
14+
[![PyPI - Downloads][install-badge]][install-link]
15+
16+
打造优质的笔记模板。
17+
18+
[pypi-badge]: https://img.shields.io/pypi/v/xbook.svg
19+
[pypi-link]: https://pypi.org/project/xbook/
20+
[issue-badge]: https://img.shields.io/github/issues/xinetzone/xbook
21+
[issue-link]: https://github.com/xinetzone/xbook/issues
22+
[fork-badge]: https://img.shields.io/github/forks/xinetzone/xbook
23+
[fork-link]: https://github.com/xinetzone/xbook/network
24+
[star-badge]: https://img.shields.io/github/stars/xinetzone/xbook
25+
[star-link]: https://github.com/xinetzone/xbook/stargazers
26+
[license-badge]: https://img.shields.io/github/license/xinetzone/xbook
27+
[license-link]: https://github.com/xinetzone/xbook/LICENSE
28+
[contributor-badge]: https://img.shields.io/github/contributors/xinetzone/xbook
29+
[contributor-link]: https://github.com/xinetzone/xbook/contributors
30+
[watcher-badge]: https://img.shields.io/github/watchers/xinetzone/xbook
31+
[watcher-link]: https://github.com/xinetzone/xbook/watchers
32+
[binder-badge]: https://mybinder.org/badge_logo.svg
33+
[binder-link]: https://mybinder.org/v2/gh/xinetzone/xbook/main
34+
[install-badge]: https://img.shields.io/pypi/dw/xbook?label=pypi%20installs
35+
[install-link]: https://pypistats.org/packages/xbook
36+
[status-badge]: https://readthedocs.org/projects/xbook/badge/?version=latest
37+
[status-link]: https://xbook.readthedocs.io/zh/latest/?badge=latest
38+
[download-badge]: https://pepy.tech/badge/xbook
39+
[download-link]: https://pepy.tech/project/xbook
40+
41+
## PyPI
42+
43+
支持 PyPI:
44+
45+
```sh
46+
pip install xbook
47+
```
48+

‎doc/.gitignore

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*.mo
2+
draft/
3+
_build/
4+
*.bak
5+
*.dat
6+
*.pickle
7+
*.tar
8+
outputs/
9+
_models/
10+
model/
11+
*.npz
12+
*.onnx
13+
*.log
14+
whatever
15+
*.o
16+
*.csv
17+
*.pdf
18+
*.params

‎doc/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

‎doc/_static/custom.css

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Background of stsable should be green */
2+
#version_switcher a[data-version-name*="stable"] {
3+
background-color: #e2ffe2;
4+
}
5+
6+
/* Color of explicit versions should be orange */
7+
#version_switcher a:not([data-version-name*="stable"]):not([data-version-name="dev"]) {
8+
background-color: #f8f9fa;
9+
color: grey;
10+
}
11+
12+
/* If we're on a dev version, make the switcher button orange */
13+
#version_switcher_button[data-active-version-name*="dev"] {
14+
background-color: rgb(255 138 62);
15+
}
16+
17+
blockquote.epigraph {
18+
background-color: antiquewhite;
19+
}
20+
21+
.dfn {
22+
background-color: rgb(205, 214, 71);
23+
}
24+
25+
caption {
26+
padding-top: .75rem;
27+
padding-bottom: .75rem;
28+
color: #61aced;
29+
text-align: left;
30+
caption-side: top;
31+
}
32+
33+
.topic {
34+
border: 1px solid #ccc;
35+
padding: 7px;
36+
margin: 10px 0 10px 0;
37+
}
38+
39+
.topic-title {
40+
font-size: 1.1em;
41+
font-weight: bold;
42+
margin-top: 10px;
43+
border-bottom: ridge rebeccapurple;
44+
}
45+
46+
.bd-sidebar-primary, .bd-sidebar-secondary {
47+
background-color: #e4e7eb;
48+
}

‎doc/_static/images/favicon.jpg

6.74 KB
Loading

‎doc/_static/images/logo.jpg

25.3 KB
Loading

‎doc/_static/switcher.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"name": "main",
4+
"version": "main",
5+
"url": "https://xinetzone.github.io/xbook/"
6+
},
7+
{
8+
"name": "dev",
9+
"version": "latest",
10+
"url": "https://xbook.readthedocs.io/zh/latest/"
11+
}
12+
]

‎doc/_templates/custom-template.html

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="sidebar-message">
2+
This is a community-supported theme.
3+
If you'd like to contribute,
4+
<a href="https://github.com/pydata/pydata-sphinx-theme">check out our GitHub repository</a>
5+
Your contributions are welcome!
6+
</div>

‎doc/_templates/navbar-version.html

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- A small template snippet for theme testing -->
2+
TEST: v{{ version }}

‎doc/_templates/theme-switcher.html

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<span class="theme-switch-button btn btn-sm btn-outline-primary navbar-btn rounded-circle">
2+
<a class="theme-switch" data-mode="light"><i class="fas fa-sun"></i></a>
3+
<a class="theme-switch" data-mode="dark"><i class="far fa-moon"></i></a>
4+
<a class="theme-switch" data-mode="auto"><i class="fas fa-adjust"></i></a>
5+
</span>

‎doc/about/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# 关于

‎doc/chaos/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# 混沌

‎doc/conf.py

+274
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
import sys
13+
from pathlib import Path
14+
15+
ROOT = Path('__file__').resolve().parents[1]
16+
sys.path.extend([str(ROOT/'src')])
17+
import xbook
18+
19+
if sys.platform == 'win32':
20+
import asyncio
21+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
22+
23+
project = 'xbook'
24+
copyright = '2022, xinetzone'
25+
author = 'xinetzone'
26+
27+
# The full version, including alpha/beta/rc tags
28+
release = xbook.__version__
29+
30+
31+
# -- General configuration ---------------------------------------------------
32+
33+
# Add any Sphinx extension module names here, as strings. They can be
34+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
35+
# ones.
36+
extensions = [
37+
"xyzstyle",
38+
'myst_nb',
39+
'sphinx.ext.intersphinx',
40+
'sphinx_copybutton',
41+
"sphinx_comments",
42+
'sphinx.ext.autosummary',
43+
"sphinx.ext.viewcode",
44+
"sphinxcontrib.bibtex",
45+
'sphinx.ext.autosectionlabel',
46+
"sphinx.ext.graphviz",
47+
"sphinx.ext.viewcode",
48+
"sphinx.ext.napoleon",
49+
# "sphinx_thebe",
50+
"sphinx_sitemap",
51+
"sphinx_design",
52+
]
53+
54+
# Add any paths that contain templates here, relative to this directory.
55+
templates_path = ['_templates']
56+
57+
# The language for content autogenerated by Sphinx. Refer to documentation
58+
# for a list of supported languages.
59+
#
60+
# This is also used if you do content translation via gettext catalogs.
61+
# Usually you set "language" from the command line for these cases.
62+
language = 'zh_CN'
63+
64+
# List of patterns, relative to source directory, that match files and
65+
# directories to ignore when looking for source files.
66+
# This pattern also affects html_static_path and html_extra_path.
67+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
68+
69+
70+
# -- Options for HTML output -------------------------------------------------
71+
72+
# The theme to use for HTML and HTML Help pages. See the documentation for
73+
# a list of builtin themes.
74+
#
75+
html_theme = 'xyzstyle'
76+
77+
# Add any paths that contain custom static files (such as style sheets) here,
78+
# relative to this directory. They are copied after the builtin static files,
79+
# so a file named "default.css" will overwrite the builtin "default.css".
80+
html_static_path = ['_static']
81+
html_css_files = [
82+
'custom.css',
83+
]
84+
85+
# MyST-NB 设置
86+
# 如果你希望stderr和stdout中的每个输出都被合并成一个流,请使用以下配置。
87+
# 避免将 jupter 执行报错的信息输出到 cmd
88+
nb_merge_streams = True
89+
nb_execution_allow_errors = True
90+
nb_execution_mode = 'off'
91+
92+
nb_mime_priority_overrides = [
93+
('html', 'text/plain', 0), # 最高级别
94+
('latex', 'image/jpeg', None), # 禁用
95+
# ('*', 'customtype', 20)
96+
]
97+
98+
# -- 国际化输出 ----------------------------------------------------------------
99+
gettext_compact = False
100+
locale_dirs = ['locales/']
101+
102+
# Napoleon 设置
103+
napoleon_google_docstring = True
104+
napoleon_numpy_docstring = False
105+
napoleon_include_init_with_doc = True
106+
napoleon_include_private_with_doc = True
107+
napoleon_include_special_with_doc = True
108+
napoleon_use_admonition_for_examples = True
109+
napoleon_use_admonition_for_notes = True
110+
napoleon_use_admonition_for_references = True
111+
napoleon_use_ivar = True
112+
napoleon_use_param = True
113+
napoleon_use_rtype = True
114+
napoleon_preprocess_types = True
115+
napoleon_type_aliases = None
116+
napoleon_attr_annotations = True
117+
118+
html_logo = '_static/images/logo.jpg'
119+
# The name of an image file (within the static path) to use as favicon of the
120+
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
121+
# pixels large.
122+
html_favicon = '_static/images/favicon.jpg'
123+
124+
html_last_updated_fmt = '%Y-%m-%d, %H:%M:%S'
125+
126+
127+
128+
extlinks = {
129+
# 'duref': ('https://docutils.sourceforge.io/docs/ref/rst/'
130+
# 'restructuredtext.html#%s', ''),
131+
# 'durole': ('https://docutils.sourceforge.io/docs/ref/rst/'
132+
# 'roles.html#%s', ''),
133+
# 'dudir': ('https://docutils.sourceforge.io/docs/ref/rst/'
134+
# 'directives.html#%s', ''),
135+
'py-doc': ('https://daobook.github.io/cpython/%s', ''),
136+
'daobook': ('https://daobook.github.io/%s', ''),
137+
}
138+
139+
intersphinx_mapping = {
140+
'python': ('https://daobook.github.io/cpython/', None),
141+
'tvm': ('https://daobook.github.io/tvm/', None),
142+
"mxnet": ("https://mxnet.incubator.apache.org/versions/1.9.0/api/python/docs", None)
143+
}
144+
145+
# ``pydata-sphinx-theme`` 配置
146+
# Define the json_url for our version switcher.
147+
json_url = 'https://xinetzone.github.io/xbook/_static/switcher.json'
148+
149+
version = release
150+
151+
switcher_version = f'v{version}'
152+
if "dev" in version:
153+
switcher_version = "dev"
154+
elif "rc" in version:
155+
switcher_version = version.split("rc")[0] + " (rc)"
156+
html_baseurl = "https://xinetzone.github.io/xbook"
157+
autosummary_generate = True
158+
html_theme_options = {
159+
"switcher": {
160+
"json_url": json_url,
161+
"version_match": switcher_version
162+
},
163+
"github_url": "https://github.com/xinetzone/xbook",
164+
"use_edit_page_button": True,
165+
"show_nav_level": 0,
166+
"show_toc_level": 0,
167+
"navigation_with_keys": True,
168+
"collapse_navigation": False,
169+
"navbar_align": "content", # "right", "left", "content"
170+
"navbar_start": "navbar-logo.html",
171+
"navbar_center": "navbar-nav.html",
172+
"navbar_end": ["theme-switcher", "version-switcher", "navbar-icon-links"],
173+
# "page_sidebar_items": [], # 删除右侧边栏
174+
"footer_start": ["copyright", "sphinx-version"],
175+
"footer_end": ["last-updated", ],
176+
# 图标可以参考 https://fontawesome.com/icons
177+
"icon_links": [
178+
# {
179+
# "name": "GitHub",
180+
# "url": "https://github.com/xinetzone/tvm-book",
181+
# "icon": "fa-brands fa-square-github",
182+
# "type": "fontawesome",
183+
# },
184+
{
185+
"name": "知乎",
186+
"url": "https://www.zhihu.com/people/xinetzone",
187+
"icon": "fa-brands fa-zhihu",
188+
"type": "fontawesome",
189+
},
190+
{
191+
"name": "简书",
192+
"url": "https://www.jianshu.com/u/4302480a3e8e",
193+
"icon": "fa-solid fa-book",
194+
"type": "fontawesome",
195+
},
196+
{
197+
"name": "B站",
198+
"url": "https://space.bilibili.com/252192181",
199+
"icon": "fa-brands fa-bilibili",
200+
"type": "fontawesome",
201+
},
202+
{
203+
"name": "博客园",
204+
"url": "https://www.cnblogs.com/q735613050/",
205+
"icon": "https://xinetzone.github.io/xinetzone/media/xinetzone.jpg",
206+
"type": "url",
207+
},
208+
{
209+
"name": "领英",
210+
"url": "https://www.linkedin.com/in/xinet",
211+
"icon": "fa-brands fa-linkedin",
212+
"type": "fontawesome",
213+
},
214+
# {
215+
# "name": "GitLab",
216+
# "url": "https://gitlab.com/<your-org>/<your-repo>",
217+
# "icon": "fa-brands fa-square-gitlab",
218+
# "type": "fontawesome",
219+
# },
220+
# {
221+
# "name": "Twitter",
222+
# "url": "https://twitter.com/<your-handle>",
223+
# "icon": "fa-brands fa-square-twitter",
224+
# # The default for `type` is `fontawesome` so it is not actually required in any of the above examples as it is shown here
225+
# },
226+
# {
227+
# "name": "Mastodon",
228+
# "url": "https://<your-host>@<your-handle>",
229+
# "icon": "fa-brands fa-mastodon",
230+
# },
231+
],
232+
# "use_download_button": True,
233+
# "toc_title": "导航",
234+
# "single_page": True,
235+
}
236+
237+
html_sidebars = {
238+
"contribute/index": [
239+
"search-field",
240+
"sidebar-nav-bs",
241+
"custom-template",
242+
], # This ensures we test for custom sidebars
243+
"demo/no-sidebar": [], # Test what page looks like with no sidebar items
244+
}
245+
246+
html_context = {
247+
"github_user": "xinetzone",
248+
"github_repo": "xbook",
249+
"github_version": "main",
250+
"doc_path": "doc",
251+
}
252+
253+
myst_enable_extensions = [
254+
"amsmath",
255+
"colon_fence",
256+
"deflist",
257+
"dollarmath",
258+
"html_image",
259+
]
260+
261+
262+
bibtex_bibfiles = ["note.bib"]
263+
# To test that style looks good with common bibtex config
264+
bibtex_reference_style = "author_year"
265+
graphviz_output_format = 'svg'
266+
267+
comments_config = {
268+
"hypothesis": True,
269+
"dokieli": False,
270+
"utterances": {
271+
"repo": "xinetzone/xbook",
272+
"optional": "config",
273+
}
274+
}

‎doc/index.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
```{include} ../README.md
2+
```
3+
4+
```{toctree}
5+
:maxdepth: 2
6+
7+
tutorials/index
8+
topics/index
9+
chaos/index
10+
about/index
11+
```
12+
13+
# 索引与表格
14+
15+
* {ref}`genindex`
16+
* {ref}`modindex`
17+
* {ref}`search`

‎doc/logo.jpg

6.74 KB
Loading

‎doc/make.bat

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=_build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.https://www.sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

‎doc/note.bib

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
2+
@Article{ Chen.Li.Li.ea.2015,
3+
title = {MXNet: A flexible and efficient machine learning library
4+
for heterogeneous distributed systems},
5+
author = {Chen, Tianqi and Li, Mu and Li, Yutian and Lin, Min and
6+
Wang, Naiyan and Wang, Minjie and Xiao, Tianjun and Xu,
7+
Bing and Zhang, Chiyuan and Zhang, Zheng},
8+
journal = {arXiv preprint arXiv:1512.01274},
9+
year = {2015}
10+
}
11+
12+
@InProceedings{ Chen.Moreau.Jiang.ea.2018,
13+
title = {TVM: An automated end-to-end optimizing compiler for deep
14+
learning},
15+
author = {Chen, Tianqi and Moreau, Thierry and Jiang, Ziheng and
16+
Zheng, Lianmin and Yan, Eddie and Shen, Haichen and Cowan,
17+
Meghan and Wang, Leyuan and Hu, Yuwei and Ceze, Luis and
18+
others},
19+
booktitle = {13th USENIX Symposium on Operating Systems Design and
20+
Implementation (OSDI 18)},
21+
pages = {578--594},
22+
year = {2018}
23+
}
24+
25+
@Article{ Roesch.Lyubomirsky.Kirisame.ea.2019,
26+
title = {Relay: A High-Level IR for Deep Learning},
27+
author = {Roesch, Jared and Lyubomirsky, Steven and Kirisame, Marisa
28+
and Pollock, Josh and Weber, Logan and Jiang, Ziheng and
29+
Chen, Tianqi and Moreau, Thierry and Tatlock, Zachary},
30+
journal = {arXiv preprint arXiv:1904.08368},
31+
year = {2019}
32+
}
33+
34+
@InProceedings{ Wang.Chen.Liu.ea.2019,
35+
title = {A Unified Optimization Approach for CNN Model Inference on
36+
Integrated GPUs},
37+
author = {Wang, Leyuan and Chen, Zhi and Liu, Yizhi and Wang, Yao
38+
and Zheng, Lianmin and Li, Mu and Wang, Yida},
39+
booktitle = {Proceedings of the 48th International Conference on
40+
Parallel Processing},
41+
pages = {99},
42+
year = {2019},
43+
organization = {ACM}
44+
}
45+
46+
@InProceedings{ Liu.Wang.Yu.ea.2019,
47+
title = {Optimizing CNN Model Inference on CPUs},
48+
author = {Liu, Yizhi and Wang, Yao and Yu, Ruofei and Li, Mu and
49+
Sharma, Vin and Wang, Yida},
50+
booktitle = {2019 USENIX Annual Technical Conference (USENIX ATC 19)},
51+
pages = {1025--1040},
52+
year = {2019}
53+
}
54+
55+
@InProceedings{ Jiang.Chen.Li.2018,
56+
title = {Efficient Deep Learning Inference on Edge Devices},
57+
author = {Jiang, Ziheng and Chen, Tianqi and Li, Mu},
58+
booktitle = {SysML Conference},
59+
year = {2018}
60+
}
61+
62+
@InProceedings{ Lai.Seznec.2013,
63+
title = {Performance upper bound analysis and optimization of SGEMM
64+
on Fermi and Kepler GPUs},
65+
author = {Lai, Junjie and Seznec, Andre},
66+
booktitle = {Proceedings of the 2013 IEEE/ACM International Symposium
67+
on Code Generation and Optimization (CGO)},
68+
pages = {1--10},
69+
year = {2013},
70+
organization = {IEEE}
71+
}
72+
73+
@Article{ Nath.Tomov.Dongarra.2010,
74+
title = {An improved MAGMA GEMM for Fermi graphics processing
75+
units},
76+
author = {Nath, Rajib and Tomov, Stanimire and Dongarra, Jack},
77+
journal = {The International Journal of High Performance Computing
78+
Applications},
79+
volume = {24},
80+
number = {4},
81+
pages = {511--515},
82+
year = {2010},
83+
publisher = {SAGE Publications Sage UK: London, England}
84+
}
85+
86+
@InProceedings{ Ragan-Kelley.Barnes.Adams.ea.2013,
87+
author = {Ragan-Kelley, Jonathan and Barnes, Connelly and Adams,
88+
Andrew and Paris, Sylvain and Durand, Fr{\'e}do and
89+
Amarasinghe, Saman},
90+
title = {Halide: A Language and Compiler for Optimizing
91+
Parallelism, Locality, and Recomputation in Image
92+
Processing Pipelines},
93+
booktitle = {Proceedings of the 34th ACM SIGPLAN Conference on
94+
Programming Language Design and Implementation},
95+
series = {PLDI '13},
96+
year = {2013},
97+
location = {Seattle, Washington, USA},
98+
pages = {519--530},
99+
numpages = {12},
100+
publisher = {ACM}
101+
}
102+
103+
@Article{ Howard.Zhu.Chen.ea.2017,
104+
title = {Mobilenets: Efficient convolutional neural networks for
105+
mobile vision applications},
106+
author = {Howard, Andrew G and Zhu, Menglong and Chen, Bo and
107+
Kalenichenko, Dmitry and Wang, Weijun and Weyand, Tobias
108+
and Andreetto, Marco and Adam, Hartwig},
109+
journal = {arXiv preprint arXiv:1704.04861},
110+
year = {2017}
111+
}

‎doc/topics/docker/dockerfile-help.md

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Dockerfile 指南
2+
3+
## 选择基础镜像
4+
5+
```{topic} 基本原则
6+
- 官方镜像优于非官方的镜像,如果没有官方镜像,则尽量选择 Dockerfile 开源的。
7+
- 固定版本 tag 而不是每次都使用 latest。
8+
- 尽量选择体积小的镜像。
9+
```
10+
11+
## 执行指令
12+
13+
```{topic} RUN
14+
主要用于在镜像里执行指令,比如安装软件,下载文件等。
15+
```
16+
17+
::::{tab-set}
18+
:::{tab-item} 改进版
19+
```Dockerfile
20+
FROM python:3.8.13
21+
RUN apt-get update \
22+
&& apt-get install -y gcc g++ libtinfo-dev zlib1g-dev build-essential cmake \
23+
&& apt install -y clang clangd llvm liblldb-dev libedit-dev libxml2-dev \
24+
&& pip install decorator scipy attrs pandas toml
25+
```
26+
:::
27+
:::{tab-item} 臃肿版
28+
每一行的 `RUN` 命令都会产生一层镜像层,导致镜像的臃肿。
29+
```Dockerfile
30+
FROM python:3.8.13
31+
RUN apt-get update
32+
RUN apt-get install -y gcc g++ libtinfo-dev zlib1g-dev build-essential cmake
33+
RUN apt install -y clang clangd llvm liblldb-dev libedit-dev libxml2-dev
34+
RUN pip install decorator scipy attrs pandas toml
35+
```
36+
:::
37+
::::
38+
39+
```{tip}
40+
`docker image history fe5` 可以用于查看镜像历史。
41+
```
42+
43+
## 文件复制和目录操作
44+
45+
往镜像里复制文件有两种方式,`COPY``ADD`
46+
47+
### 复制普通文件
48+
49+
`COPY``ADD` 都可以把本地文件复制到镜像里,如果目标目录不存在,则会自动创建。
50+
51+
比如把本地的 `hello.py` 复制到 `/app` 目录下。若 `/app` 这个文件不存在,则会自动创建。
52+
53+
```Dockerfile
54+
FROM python:3.9.5-alpine3.13
55+
COPY hello.py /app/hello.py
56+
```
57+
58+
### 复制压缩文件
59+
60+
`ADD``COPY` 高级一点的地方就是,如果复制的是 gzip 等压缩文件时,ADD 会帮助自动解压缩文件。
61+
62+
```Dockerfile
63+
FROM python:3.9.5-alpine3.13
64+
ADD hello.tar.gz /app/
65+
```
66+
67+
### 如何选择
68+
69+
`COPY``ADD` 指令中选择的时候,可以遵循这样的原则:
70+
71+
> 所有的文件复制均使用 `COPY` 指令,仅在需要自动解压缩的场合使用 `ADD`
72+
73+
## 构建参数和环境变量
74+
75+
`ARG``ENV` 是经常容易被混淆的两个 `Dockerfile` 的语法,都可以用来设置 “变量”。 但实际上两者有很多的不同。
76+
77+
::::{tab-set}
78+
:::{tab-item} ENV
79+
```Dockerfile
80+
FROM ubuntu:20.04
81+
ENV VERSION=2.0.1
82+
RUN apt-get update && \
83+
apt-get install -y wget && \
84+
wget https://github.com/ipinfo/cli/releases/download/ipinfo-${VERSION}/ipinfo_${VERSION}_linux_amd64.tar.gz && \
85+
tar zxf ipinfo_${VERSION}_linux_amd64.tar.gz && \
86+
mv ipinfo_${VERSION}_linux_amd64 /usr/bin/ipinfo && \
87+
rm -rf ipinfo_${VERSION}_linux_amd64.tar.gz
88+
```
89+
:::
90+
:::{tab-item} ARG
91+
```Dockerfile
92+
FROM ubuntu:20.04
93+
ARG VERSION=2.0.1
94+
RUN apt-get update && \
95+
apt-get install -y wget && \
96+
wget https://github.com/ipinfo/cli/releases/download/ipinfo-${VERSION}/ipinfo_${VERSION}_linux_amd64.tar.gz && \
97+
tar zxf ipinfo_${VERSION}_linux_amd64.tar.gz && \
98+
mv ipinfo_${VERSION}_linux_amd64 /usr/bin/ipinfo && \
99+
rm -rf ipinfo_${VERSION}_linux_amd64.tar.gz
100+
```
101+
:::
102+
::::
103+
104+
- `ARG` 可以在镜像 build 的时候动态修改 `value`, 通过 `--build-arg`
105+
- `ENV` 设置的变量可以在镜像中保持,并在容器中可以被环境变量覆写。
106+
107+
## 构建镜像
108+
109+
```bash
110+
docker image build -t demo ./
111+
```
112+
113+
- `demo`:镜像的名称
114+
- `./`:build context 所指向的目录
115+
116+
## `.dockerignore` 文件
117+
118+
```
119+
.vscode/
120+
env/
121+
```
122+
123+
有了 `.dockerignore` 文件,构建时, build context 就小了很多。
124+
125+
## 尽量使用非 root 用户
126+
127+
## 多阶段构建镜像
128+

‎doc/topics/docker/index.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Docker
2+
3+
学习资料:[Docker — 从入门到实践](https://docker-practice.github.io/zh-cn/)
4+
5+
```{toctree}
6+
:maxdepth: 2
7+
8+
quickref
9+
dockerfile-help
10+
```

‎doc/topics/docker/quickref.ipynb

+348
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,348 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# 快速参考\n",
8+
"\n",
9+
"参考:[Docker 小技巧](https://www.mianshigee.com/project/jinfagang-alfred)\n",
10+
"\n",
11+
"````{admonition} Docker 命令行的基本使用\n",
12+
":class: tip\n",
13+
"```bash\n",
14+
"docker + 管理对象(比如容器,镜像) + 具体操作(比如创建,启动,停止,删除)\n",
15+
"```\n",
16+
"\n",
17+
"```{admonition} 例子\n",
18+
"- `docker image pull nginx` 拉取 `nginx` 的 docker 镜像\n",
19+
"- `docker container stop web` 停止 `web` 的 docker 容器\n",
20+
"```\n",
21+
"````\n",
22+
"\n",
23+
"```{include} quickref.txt\n",
24+
"```\n",
25+
"\n",
26+
"## 镜像管理和发布\n",
27+
"\n",
28+
"```{topic} 镜像获取\n",
29+
"- `pull`:从 registry 拉取\n",
30+
"- `build`:从 Dockerfile 构建\n",
31+
"- `load`:从本地获取\n",
32+
"```\n",
33+
"\n",
34+
"### 镜像基本操作\n",
35+
"\n",
36+
"查看基本功能:"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": 2,
42+
"metadata": {},
43+
"outputs": [
44+
{
45+
"name": "stdout",
46+
"output_type": "stream",
47+
"text": [
48+
"\n",
49+
"Usage: docker image COMMAND\n",
50+
"\n",
51+
"Manage images\n",
52+
"\n",
53+
"Commands:\n",
54+
" build Build an image from a Dockerfile\n",
55+
" history Show the history of an image\n",
56+
" import Import the contents from a tarball to create a filesystem image\n",
57+
" inspect Display detailed information on one or more images\n",
58+
" load Load an image from a tar archive or STDIN\n",
59+
" ls List images\n",
60+
" prune Remove unused images\n",
61+
" pull Pull an image or a repository from a registry\n",
62+
" push Push an image or a repository to a registry\n",
63+
" rm Remove one or more images\n",
64+
" save Save one or more images to a tar archive (streamed to STDOUT by default)\n",
65+
" tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE\n",
66+
"\n",
67+
"Run 'docker image COMMAND --help' for more information on a command.\n"
68+
]
69+
}
70+
],
71+
"source": [
72+
"!docker image"
73+
]
74+
},
75+
{
76+
"cell_type": "markdown",
77+
"metadata": {},
78+
"source": [
79+
"```{topic} 镜像拉取\n",
80+
"默认从 Docker Hub 拉取,如果不指定版本,会拉取最新版。\n",
81+
"```\n",
82+
"\n",
83+
"比如:"
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": 7,
89+
"metadata": {},
90+
"outputs": [
91+
{
92+
"name": "stdout",
93+
"output_type": "stream",
94+
"text": [
95+
"Using default tag: latest\n",
96+
"latest: Pulling from library/nginx\n",
97+
"Digest: sha256:790711e34858c9b0741edffef6ed3d8199d8faa33f2870dea5db70f16384df79\n",
98+
"Status: Image is up to date for nginx:latest\n",
99+
"docker.io/library/nginx:latest\n"
100+
]
101+
}
102+
],
103+
"source": [
104+
"!docker pull nginx"
105+
]
106+
},
107+
{
108+
"cell_type": "markdown",
109+
"metadata": {},
110+
"source": [
111+
"指定版本:"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": 5,
117+
"metadata": {},
118+
"outputs": [
119+
{
120+
"name": "stdout",
121+
"output_type": "stream",
122+
"text": [
123+
"1.20.0: Pulling from library/nginx\n",
124+
"\n",
125+
"\u001b[1B2152171a: Pulling fs layer \n",
126+
"\u001b[1B15a5cec8: Pulling fs layer \n",
127+
"\u001b[1Bb026b9ce: Pulling fs layer \n",
128+
"\u001b[1Bdc384fb3: Pulling fs layer \n",
129+
"\u001b[1B372d6dee: Pulling fs layer \n",
130+
"\u001b[1BDigest: sha256:ea4560b87ff03479670d15df426f7d02e30cb6340dcd3004cdfc048d6a1d54b4\u001b[2K\u001b[5A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[2A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[1A\u001b[2K\u001b[5A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[6A\u001b[2K\u001b[5A\u001b[2K\u001b[5A\u001b[2K\u001b[5A\u001b[2K\u001b[5A\u001b[2K\u001b[5A\u001b[2K\u001b[5A\u001b[2K\u001b[5A\u001b[2K\u001b[5A\u001b[2K\u001b[4A\u001b[2K\u001b[3A\u001b[2K\u001b[2A\u001b[2K\u001b[1A\u001b[2K\n",
131+
"Status: Downloaded newer image for nginx:1.20.0\n",
132+
"docker.io/library/nginx:1.20.0\n"
133+
]
134+
}
135+
],
136+
"source": [
137+
"!docker pull nginx:1.20.0"
138+
]
139+
},
140+
{
141+
"cell_type": "markdown",
142+
"metadata": {},
143+
"source": [
144+
"从 Quay 上拉取镜像:"
145+
]
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": 6,
150+
"metadata": {},
151+
"outputs": [
152+
{
153+
"name": "stdout",
154+
"output_type": "stream",
155+
"text": [
156+
"Using default tag: latest\n",
157+
"Error response from daemon: unauthorized: access to the requested resource is not authorized\n"
158+
]
159+
}
160+
],
161+
"source": [
162+
"!docker pull quay.io/bitnami/nginx"
163+
]
164+
},
165+
{
166+
"cell_type": "markdown",
167+
"metadata": {},
168+
"source": [
169+
"````{topic} 镜像的查看\n",
170+
"\n",
171+
"比如:\n",
172+
"```bash\n",
173+
"$ docker image ls\n",
174+
"```\n",
175+
"```\n",
176+
"REPOSITORY TAG IMAGE ID CREATED SIZE\n",
177+
"quay.io/bitnami/nginx latest 0922eabe1625 6 hours ago 89.3MB\n",
178+
"nginx 1.20.0 7ab27dbbfbdf 10 days ago 133MB \n",
179+
"``` \n",
180+
"\n",
181+
"查看虚悬镜像:\n",
182+
"```bash\n",
183+
"!docker image ls -f dangling=true\n",
184+
"```\n",
185+
"````\n",
186+
"\n",
187+
"````{topic} 镜像的删除\n",
188+
"```bash\n",
189+
"$ docker image rm 0922eabe1625\n",
190+
"```\n",
191+
"```\n",
192+
"Untagged: quay.io/bitnami/nginx:latest\n",
193+
"Untagged: quay.io/bitnami/nginx@sha256:d143befa04e503472603190da62db157383797d281fb04e6a72c85b48e0b3239\n",
194+
"Deleted: sha256:0922eabe16250e2f4711146e31b7aac0e547f52daa6cf01c9d00cf64d49c68c8\n",
195+
"Deleted: sha256:5eee4ed0f6b242e2c6e4f4066c7aca26bf9b3b021b511b56a0dadd52610606bd\n",
196+
"Deleted: sha256:472a75325eda417558f9100ff8b4a97f4a5e8586a14eb9c8fc12f944b26a21f8\n",
197+
"Deleted: sha256:cdcb5872f8a64a0b5839711fcd2a87ba05795e5bf6a70ba9510b8066cdd25e76\n",
198+
"Deleted: sha256:e0f1b7345a521469bbeb7ec53ef98227bd38c87efa19855c5ba0db0ac25c8e83\n",
199+
"Deleted: sha256:11b9c2261cfc687fba8d300b83434854cc01e91a2f8b1c21dadd937e59290c99\n",
200+
"Deleted: sha256:4819311ec2867ad82d017253500be1148fc335ad13b6c1eb6875154da582fcf2\n",
201+
"Deleted: sha256:784480add553b8e8d5ee1bbd229ed8be92099e5fb61009ed7398b93d5705a560\n",
202+
"Deleted: sha256:e0c520d1a43832d5d2b1028e3f57047f9d9f71078c0187f4bb05e6a6a572993d\n",
203+
"Deleted: sha256:94d5b1d6c9e31de42ce58b8ce51eb6fb5292ec889a6d95763ad2905330b92762\n",
204+
"Deleted: sha256:95deba55c490bbb8de44551d3e6a89704758c93ba8503a593cb7c07dfbae0058\n",
205+
"Deleted: sha256:1ad1d903ef1def850cd44e2010b46542196e5f91e53317dbdb2c1eedfc2d770c\n",
206+
"```\n",
207+
"````\n",
208+
"\n",
209+
"````{topic} 镜像导入\n",
210+
"```bash\n",
211+
"$ docker image load -i .\\nginx.image\n",
212+
"```\n",
213+
"```\n",
214+
"1839f9962bd8: Loading layer [==================================================>] 64.8MB/64.8MB\n",
215+
"a2f4f809e04e: Loading layer [==================================================>] 3.072kB/3.072kB\n",
216+
"9b63e6289fbe: Loading layer [==================================================>] 4.096kB/4.096kB\n",
217+
"f7141923aaa3: Loading layer [==================================================>] 3.584kB/3.584kB\n",
218+
"272bc57d3405: Loading layer [==================================================>] 7.168kB/7.168kB\n",
219+
"Loaded image: nginx:1.20.0\n",
220+
"```\n",
221+
"````\n",
222+
"\n",
223+
"````{topic} 镜像保存\n",
224+
"```bash\n",
225+
"$ docker image save nginx:1.20.0 -o nginx.image\n",
226+
"```\n",
227+
"````\n",
228+
"\n",
229+
"### Dockerfile 基本结构\n",
230+
"\n",
231+
"Docker 可以通过从 `Dockerfile` 中读取指令来自动构建映像。Dockerfile 是文本文档,它包含用户可以在命令行上调用的所有命令来组装镜像。\n",
232+
"\n",
233+
"比如在 Ubuntu 系统下创建简单的 Python 环境:\n",
234+
"\n",
235+
"```Dockerfile\n",
236+
"FROM ubuntu:20.04\n",
237+
"RUN apt-get update && \\\n",
238+
" DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y python3.9 python3-pip python3.9-dev\n",
239+
"ADD hello.py /\n",
240+
"CMD [\"python3\", \"/hello.py\"]\n",
241+
"```\n",
242+
"\n",
243+
"## scratch 镜像\n",
244+
"\n",
245+
"Scratch 是空白 Docker 镜像。\n",
246+
"\n",
247+
"```{rubric} 通过 scratch 来构建基础镜像。\n",
248+
"```\n",
249+
"\n",
250+
"::::{tab-set}\n",
251+
"\n",
252+
":::{tab-item} hello.c\n",
253+
"```\n",
254+
"#include <stdio.h>\n",
255+
"int main()\n",
256+
"{\n",
257+
" printf(\"hello docker\\n\");\n",
258+
"}\n",
259+
"```\n",
260+
":::\n",
261+
"::::\n",
262+
"\n",
263+
"```{rubric} 编译成二进制文件\n",
264+
"```\n",
265+
"```bash\n",
266+
"$ gcc --static -o hello hello.c\n",
267+
"$ ./hello\n",
268+
"hello docker\n",
269+
"$\n",
270+
"```\n",
271+
"\n",
272+
"::::{tab-set}\n",
273+
"\n",
274+
":::{tab-item} Dockerfile\n",
275+
"```\n",
276+
"FROM scratch\n",
277+
"ADD hello /\n",
278+
"CMD [\"/hello\"]\n",
279+
"```\n",
280+
":::\n",
281+
"::::\n",
282+
"\n",
283+
"```{rubric} 构建\n",
284+
"```\n",
285+
"\n",
286+
"```bash\n",
287+
"$ docker build -t hello .\n",
288+
"$ docker image ls\n",
289+
"REPOSITORY TAG IMAGE ID CREATED SIZE\n",
290+
"hello latest 2936e77a9daa 40 minutes ago 872kB\n",
291+
"```\n",
292+
"\n",
293+
"```{rubric} 运行\n",
294+
"```\n",
295+
"```bash\n",
296+
"$ docker container run -it hello\n",
297+
"hello docker\n",
298+
"```\n",
299+
"\n",
300+
"## Docker 数据存储\n",
301+
"\n",
302+
"默认情况下,在运行中的容器里创建的文件,被保存在可写的容器层:\n",
303+
"\n",
304+
"- 如果容器被删除了,则数据也没有了\n",
305+
"- 这个可写的容器层是和特定的容器绑定的,也就是这些数据无法方便的和其它容器共享\n",
306+
"\n",
307+
"Docker 主要提供了两种方式做数据的持久化\n",
308+
"\n",
309+
"- Data Volume:由 Docker 管理(`/var/lib/docker/volumes/` Linux), 持久化数据的最好方式\n",
310+
"- Bind Mount,由用户指定存储的数据具体 mount 在系统什么位置\n"
311+
]
312+
},
313+
{
314+
"cell_type": "code",
315+
"execution_count": null,
316+
"metadata": {},
317+
"outputs": [],
318+
"source": []
319+
}
320+
],
321+
"metadata": {
322+
"kernelspec": {
323+
"display_name": "Python 3.8.13 ('tvmo': conda)",
324+
"language": "python",
325+
"name": "python3"
326+
},
327+
"language_info": {
328+
"codemirror_mode": {
329+
"name": "ipython",
330+
"version": 3
331+
},
332+
"file_extension": ".py",
333+
"mimetype": "text/x-python",
334+
"name": "python",
335+
"nbconvert_exporter": "python",
336+
"pygments_lexer": "ipython3",
337+
"version": "3.8.13"
338+
},
339+
"orig_nbformat": 4,
340+
"vscode": {
341+
"interpreter": {
342+
"hash": "f84f946b1c3af061cd4f6d85753fa9fad51e40b700ed1d7b0dec8a56b8e85b7c"
343+
}
344+
}
345+
},
346+
"nbformat": 4,
347+
"nbformat_minor": 2
348+
}

‎doc/topics/docker/quickref.txt

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## 镜像 vs 容器
2+
3+
```{topic} 镜像
4+
Docker 镜像(image)是 read-only 文件。
5+
6+
- 此文件包含文件系统,源码,库文件,依赖,工具等一些运行应用所需要的文件。
7+
- 可以理解为模板。
8+
- 镜像具有分层的概念。
9+
```
10+
11+
```{topic} 容器
12+
Docker 镜像的运行时。
13+
14+
- 实质是复制 image 并在 image 最上层加上一层 read-write 的层 (称之为 container layer,容器层)。
15+
16+
- 基于同一个 image 可以创建多个容器。
17+
```
18+
19+
## 容器基本操作
20+
21+
```{list-table} 容器命令
22+
:widths: 25 25 25
23+
:header-rows: 1
24+
*
25+
- 操作
26+
- 命令(全)
27+
- 命令(简)
28+
*
29+
- 容器的创建
30+
- `docker container run <image name>`
31+
- `docker run <image name>`
32+
*
33+
- 容器的列出(up)
34+
- `docker container ls`
35+
- `docker ps`
36+
*
37+
- 容器的列出(up和exit)
38+
- `docker container ls -a`
39+
- `docker ps -a`
40+
*
41+
- 容器的停止
42+
- `docker container stop <name or ID>`
43+
- `docker stop <container name or ID>`
44+
*
45+
- 容器的删除
46+
- `docker container rm <name or ID>`
47+
- `docker rm <container name or ID>`
48+
```
49+
50+
```{tip}
51+
- `docker container stop cd3 269 34b 751` 批量删除
52+
- `docker container stop $(docker container ps -aq)` 批量删除
53+
- `docker system prune -a -f` 可以快速对系统进行清理,删除停止的容器,不用的镜像,等等。
54+
```
55+
56+
```{topic} shell 模式
57+
- `docker container run -it`:创建容器并进入交互式模式。
58+
- `docker container exec -it`:在已经运行的容器中执行额外的命令。
59+
```
60+
61+
````{admonition} 例子
62+
```bash
63+
docker container run -d --publish 80:80 --name webhost nginx
64+
```
65+
66+
- 在本地查找是否有 `nginx` 镜像,但是没有发现;
67+
- 去远程的 image registry 查找 `nginx` 镜像(默认的 registry 是 Docker Hub)
68+
- 下载最新版本的 `nginx` 镜像 (`nginx:latest` 默认)
69+
- 基于 `nginx` 镜像来创建新的容器,并且准备运行
70+
- docker engine 给这个容器分配虚拟 IP 地址
71+
- 在宿主机上打开 80 端口并把容器的 80 端口转发到宿主机上
72+
- 启动容器,运行指定的命令(这里是 shell 脚本去启动 nginx)
73+
````

‎doc/topics/index.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 专题
2+
3+
```{toctree}
4+
:maxdepth: 2
5+
6+
Makefile 小抄 <https://xinetzone.github.io/makefile-book/>
7+
docker/index
8+
```

‎doc/tutorials/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# 教程

‎pyproject.toml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[build-system]
2+
build-backend = "flit_core.buildapi"
3+
requires = ["flit_core >=3.4,<4"]
4+
5+
[project]
6+
authors = [{name = "xinetzone", email = "735613050@qq.com"}]
7+
dynamic = ["version", "description"]
8+
license = {file = "LICENSE"}
9+
name = "xbook"
10+
readme = "README.md"
11+
requires-python = ">=3.10"
12+
13+
dependencies = [
14+
"d2py",
15+
"attrs",
16+
"importlib-metadata>=4.12"
17+
]
18+
19+
maintainers = [
20+
{name = "xinetzone", email = "735613050@qq.com"},
21+
]
22+
23+
classifiers = [
24+
"Development Status :: 4 - Beta",
25+
"Programming Language :: Python :: 3",
26+
"Framework :: Sphinx",
27+
"Framework :: Sphinx :: Theme",
28+
"License :: OSI Approved :: Apache Software License",
29+
"Operating System :: OS Independent",
30+
]
31+
32+
[project.urls]
33+
Home = "https://github.com/xinetzone/xbook"
34+
35+
[project.optional-dependencies]
36+
doc = [
37+
"myst-nb",
38+
"xyzstyle",
39+
"sphinx-copybutton",
40+
"sphinxcontrib-bibtex",
41+
"sphinx-thebe",
42+
"sphinx-design",
43+
"sphinx-automodapi",
44+
"sphinx-sitemap",
45+
"sphinx-comments",
46+
]
47+
48+
coverage = [
49+
"pytest-cov",
50+
"pytest-regressions",
51+
"codecov",
52+
"xbook[test]",
53+
]
54+
dev = [
55+
"pyyaml",
56+
"pre-commit",
57+
"note-demo[coverage]",
58+
]
59+
test = [
60+
"pytest",
61+
"xbook[doc]",
62+
]
63+
64+
[project.entry-points]
65+
"sphinx.html_themes" = {xbook = "xbook"}
66+
67+
[tool.flit.sdist]
68+
# include = ["docs/"]
69+
exclude = ['doc', '.git', '.github']

‎readthedocs.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# .readthedocs.yaml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Set the version of Python and other tools you might need
9+
build:
10+
os: ubuntu-20.04
11+
tools:
12+
python: "3.10"
13+
# You can also specify other tool versions:
14+
# nodejs: "16"
15+
# rust: "1.55"
16+
# golang: "1.17"
17+
18+
# Build documentation in the docs/ directory with Sphinx
19+
sphinx:
20+
configuration: doc/conf.py
21+
22+
# If using Sphinx, optionally build your docs in additional formats such as PDF
23+
# Build PDF & ePub * HTML
24+
formats:
25+
- htmlzip
26+
- epub
27+
- pdf
28+
29+
# Optionally declare the Python requirements required to build your docs
30+
python:
31+
install:
32+
- method: pip
33+
path: .
34+
extra_requirements:
35+
- doc
36+
system_packages: true

‎src/xbook/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'''Note Demo
2+
'''
3+
4+
__version__ = '0.0.1'

‎tasks.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import inspect
2+
3+
if not hasattr(inspect, 'getargspec'): # 修复
4+
inspect.getargspec = inspect.getfullargspec
5+
6+
from d2py.tools.write import site
7+
8+
namespace = site('doc', target='doc/_build/html')

0 commit comments

Comments
 (0)
Please sign in to comment.