Skip to content

Commit 8f2ebbf

Browse files
authored
fix: more cog & mention build-and-inspect-python-package (#212)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 3fddb08 commit 8f2ebbf

File tree

8 files changed

+112
-83
lines changed

8 files changed

+112
-83
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ repos:
8989
name: Cog the pages
9090
language: python
9191
entry: cog -P -r -I ./helpers
92-
files: "^docs/pages/guides/packaging_compiled.md"
92+
files: "^docs/pages/guides/(packaging_compiled|docs).md"
9393
additional_dependencies: [cogapp, cookiecutter]

docs/pages/guides/coverage.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,31 @@ One can also configure `Codecov` and coverage reports passed to `Codecov` using
103103
with your `workflows` folder. Additionally, `Codecov` allows you to create and
104104
edit this `YAML` file directly through your `Codecov` project's settings!
105105

106-
A recommended configuration for `Codecov`:
106+
A recommended configuration for `.github/codecov.yml`:
107107

108108
```yaml
109109
codecov:
110110
notify:
111111
after_n_builds: x
112+
coverage:
113+
status:
114+
project:
115+
default:
116+
target: auto
117+
threshold: 5%
118+
patch:
119+
default:
120+
informational: true
112121
```
113122

114123
where `x` is the number of uploaded reports `Codecov` should wait to receive
115124
before sending statuses. This would ensure that the `Codecov` checks don't fail
116-
before all the coverage reports are uploaded. See the
125+
before all the coverage reports are uploaded. You can control the levels which
126+
are considered failing; the config above sets a loss of up to 5% as okay, and
127+
avoids patch coverage reporting a failure (otherwise, just changing a single
128+
uncovered line could cause a "failure" report on the PR). If you have 100%
129+
coverage, then you can remove the coverage failure settings, as you want any
130+
loss of coverage to fail. See the
117131
[docs](https://docs.codecov.com/docs/codecov-yaml) for all the options.
118132

119133
<!-- ### Coverage for projects written in Python and C++

docs/pages/guides/docs.md

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,21 @@ Ideally, software documentation should include:
2828
- **Explanations** to convey deeper understanding of why and how the software
2929
operates the way it does.
3030

31-
This overall framework has a name, [Diátaxis][], and you can read more about it
32-
if you are interested.
31+
{: .note-title }
32+
33+
> The Diátaxis framework
34+
>
35+
> This overall framework has a name, [Diátaxis][], and you can read more about
36+
> it if you are interested.
37+
38+
<!-- [[[cog
39+
from cog_helpers import render_cookie
40+
with render_cookie() as package:
41+
docs_conf_py = package.joinpath("docs/conf.py").read_text(encoding="utf-8").strip()
42+
docs_index_md = package.joinpath("docs/index.md").read_text(encoding="utf-8").strip()
43+
readthedocs_yaml = package.joinpath(".readthedocs.yml").read_text(encoding="utf-8").strip()
44+
]]] -->
45+
<!-- [[[end]]] -->
3346

3447
## Hand-written docs
3548

@@ -40,15 +53,21 @@ is our recommended starting point for `conf.py`:
4053

4154
### conf.py
4255

56+
<!-- prettier-ignore-start -->
57+
<!-- [[[cog
58+
print("```python")
59+
print(docs_conf_py)
60+
print("```")
61+
]]] -->
4362
```python
4463
from __future__ import annotations
4564

4665
import importlib.metadata
4766

48-
project = "<package-name-here>"
49-
copyright = "2023, Your Name"
50-
author = "Your Name"
51-
version = release = importlib.metadata.version("<package-name-here>")
67+
project = "package"
68+
copyright = "2023, My Name"
69+
author = "My Name"
70+
version = release = importlib.metadata.version("package")
5271

5372
extensions = [
5473
"myst_parser",
@@ -60,33 +79,35 @@ extensions = [
6079
"sphinx_copybutton",
6180
]
6281

63-
source_suffix = [".md", ".rst"]
82+
source_suffix = [".rst", ".md"]
6483
exclude_patterns = [
6584
"_build",
85+
"**.ipynb_checkpoints",
6686
"Thumbs.db",
6787
".DS_Store",
68-
"**.ipynb_checkpoints",
6988
".env",
7089
".venv",
7190
]
7291

7392
html_theme = "furo"
7493

75-
intersphinx_mapping = {
76-
"python": ("https://docs.python.org/3", None),
77-
}
78-
7994
myst_enable_extensions = [
8095
"colon_fence",
8196
]
8297

98+
intersphinx_mapping = {
99+
"python": ("https://docs.python.org/3", None),
100+
}
101+
83102
nitpick_ignore = [
84103
("py:class", "_io.StringIO"),
85104
("py:class", "_io.BytesIO"),
86105
]
87106

88107
always_document_param_types = True
89108
```
109+
<!-- [[[end]]] -->
110+
<!-- prettier-ignore-end -->
90111

91112
We start by setting some configuration values, but most notably we are getting
92113
the package version from the installed version of your package. We are listing
@@ -132,12 +153,18 @@ docstrings, even if the parameter isn't documented yet. Feel free to check
132153
[sphinx-autodoc-typehints](https://github.com/tox-dev/sphinx-autodoc-typehints)
133154
for more options.
134155

135-
## index.md
156+
### index.md
136157

137158
Your `index.md` file can start out like this:
138159

160+
<!-- prettier-ignore-start -->
161+
<!-- [[[cog
162+
print("````md")
163+
print(docs_index_md)
164+
print("````")
165+
]]] -->
139166
````md
140-
# Project name
167+
# package
141168

142169
```{toctree}
143170
:maxdepth: 2
@@ -155,6 +182,8 @@ Your `index.md` file can start out like this:
155182
- {ref}`modindex`
156183
- {ref}`search`
157184
````
185+
<!-- [[[end]]] -->
186+
<!-- prettier-ignore-end -->
158187

159188
You can put your project name in as the title. The `toctree` directive houses
160189
your table of contents; you'll list each new page you add inside that directive.
@@ -191,6 +220,12 @@ plugins and try to build against an uninstalled version of your project.
191220
In order to use <https://readthedocs.org> to build, host, and preview your
192221
documentation, you must have a `.reathedocs.yml` file {% rr RTD100 %} like this:
193222

223+
<!-- prettier-ignore-start -->
224+
<!-- [[[cog
225+
print("```yaml")
226+
print(readthedocs_yaml)
227+
print("```")
228+
]]] -->
194229
```yaml
195230
# Read the Docs configuration file
196231
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
@@ -201,7 +236,6 @@ build:
201236
os: ubuntu-22.04
202237
tools:
203238
python: "3.11"
204-
205239
sphinx:
206240
configuration: docs/conf.py
207241

@@ -212,6 +246,8 @@ python:
212246
extra_requirements:
213247
- docs
214248
```
249+
<!-- [[[end]]] -->
250+
<!-- prettier-ignore-end -->
215251
216252
This sets the readthedocs config version (2 is required) {% rr RTD101 %}.
217253

docs/pages/guides/gha_pure.md

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -101,35 +101,30 @@ and then use `python -m build` or `pyproject-build`, but it's better to use
101101
`pipx` to install and run python applications. Pipx is provided by default by
102102
GitHub Actions (in fact, they use it to setup other applications).
103103

104-
{% details Classic SDist builds %}
105-
106-
If you don't have a pyproject.toml, you might need to use the raw `setup.py`
107-
commands. This is the classic way to do things, though you should consider
108-
direct usage of setup.py to be an implementation detail, and setup.py is not
109-
even required in modern packages.
110-
111-
You must install SDist requirements by hand since `python setup.py sdist` does
112-
not get the benefits of having pip install things. If you have any special
113-
requirements in your `pyproject.toml` (and still don't want to use `build`),
114-
you'll need to list them. This is special just for the SDist, not for making
115-
wheels (which should be done by the PEP 517/518 process for you because you will
116-
use `build` or `pip`).
117-
118-
To build the wheel, you can use `python -m pip wheel . -w wheelhouse`. Unlike
119-
build, this is a wheelhouse, not the output wheel; any wheels it makes during
120-
the process will be put here, not just the one you wanted to upload. Be sure to
121-
use something like `wheelhouse/my_package*.whl` when you pick your items from
122-
this folder so as not to pick a random dependency that didn't have a binary
123-
wheel already. Or just use PyPA/build.
124-
125-
{% enddetails %}
126-
127104
We upload the artifact just to make it available via the GitHub PR/Checks API.
128105
You can download a file to test locally if you want without making a release.
129106

130107
We also add an optional check using twine for the metadata (it will be tested
131108
later in the upload action for the release job, as well).
132109

110+
{: .highlight-title }
111+
112+
> All-in-one action
113+
>
114+
> There is an
115+
> [all-in-one action](https://github.com/hynek/build-and-inspect-python-package)
116+
> that does all the work for you for a pure Python package, including extra
117+
> pre-upload checks & nice GitHub summaries.
118+
>
119+
> ```yaml
120+
> steps:
121+
> - uses: actions/checkout@v3
122+
> - uses: hynek/build-and-inspect-python-package@v1
123+
> ```
124+
>
125+
> The artifact it produces is named `Packages`, so that's what you need to use
126+
> later to publish.
127+
133128
And then, you need a release job:
134129

135130
{% tabs %} {% tab oidc Trusted Publishing %}
@@ -218,19 +213,10 @@ jobs:
218213
runs-on: ubuntu-latest
219214
steps:
220215
- uses: actions/checkout@v3
221-
222216
with:
223217
fetch-depth: 0
224218
225-
- name: Build SDist and wheel
226-
run: pipx run build
227-
228-
- uses: actions/upload-artifact@v3
229-
with:
230-
path: dist/*
231-
232-
- name: Check metadata
233-
run: pipx run twine check dist/*
219+
- uses: hynek/build-and-inspect-python-package@v1
234220
235221
publish:
236222
needs: [dist]
@@ -272,19 +258,10 @@ jobs:
272258
runs-on: ubuntu-latest
273259
steps:
274260
- uses: actions/checkout@v3
275-
276261
with:
277262
fetch-depth: 0
278263
279-
- name: Build SDist and wheel
280-
run: pipx run build
281-
282-
- uses: actions/upload-artifact@v3
283-
with:
284-
path: dist/*
285-
286-
- name: Check metadata
287-
run: pipx run twine check dist/*
264+
- uses: hynek/build-and-inspect-python-package@v1
288265
289266
publish:
290267
needs: [dist]
@@ -294,7 +271,7 @@ jobs:
294271
steps:
295272
- uses: actions/download-artifact@v3
296273
with:
297-
name: artifact
274+
name: Packages
298275
path: dist
299276
300277
- uses: pypa/gh-action-pypi-publish@release/v1

docs/pages/guides/gha_wheels.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,15 @@ multiple places, you can set `skip_existing` (but generally it's better to not
227227
try to upload the same file from two places - you can trick Travis into avoiding
228228
the sdist, for example).
229229

230+
{: .note-title }
231+
232+
> Other architectures
233+
>
230234
> On Travis, `cibuildwheel` even has the ability to create ARM and PowerPC
231235
> builds natively. IBM Z builds are also available but in beta. However, due to
232236
> Travis CI's recent dramatic reduction on open source support, emulating these
233-
> architectures on GHA or Azure is probably better.
237+
> architectures on GHA or Azure is probably better. Maybe look into Cirrus CI,
238+
> which has some harder-to-find architectures.
234239

235240
<!-- prettier-ignore-start -->
236241

docs/pages/guides/packaging_compiled.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ options in `tool.*` settings.
8484
<!-- [[[cog
8585
from cog_helpers import render_cookie
8686
with render_cookie(backend="skbuild") as skbuild:
87-
skbuild_cmakelists_txt = skbuild.joinpath("CMakeLists.txt").read_text(encoding="utf-8")
88-
skbuild_src_main_cpp = skbuild.joinpath("src/main.cpp").read_text(encoding="utf-8")
87+
skbuild_cmakelists_txt = skbuild.joinpath("CMakeLists.txt").read_text(encoding="utf-8").strip()
88+
skbuild_src_main_cpp = skbuild.joinpath("src/main.cpp").read_text(encoding="utf-8").strip()
8989
with render_cookie(backend="mesonpy") as mesonpy:
90-
mesonpy_meson_build = mesonpy.joinpath("meson.build").read_text(encoding="utf-8")
91-
mesonpy_src_main_cpp = mesonpy.joinpath("src/main.cpp").read_text(encoding="utf-8")
90+
mesonpy_meson_build = mesonpy.joinpath("meson.build").read_text(encoding="utf-8").strip()
91+
mesonpy_src_main_cpp = mesonpy.joinpath("src/main.cpp").read_text(encoding="utf-8").strip()
9292
with render_cookie(backend="maturin") as maturin:
93-
maturin_cargo_toml = maturin.joinpath("Cargo.toml").read_text(encoding="utf-8")
94-
maturin_src_lib_rs = maturin.joinpath("src/lib.rs").read_text(encoding="utf-8")
93+
maturin_cargo_toml = maturin.joinpath("Cargo.toml").read_text(encoding="utf-8").strip()
94+
maturin_src_lib_rs = maturin.joinpath("src/lib.rs").read_text(encoding="utf-8").strip()
9595
]]] -->
9696
<!-- [[[end]]] -->
9797

@@ -109,16 +109,13 @@ print("```")
109109
]]] -->
110110
```cmake
111111
cmake_minimum_required(VERSION 3.15...3.26)
112-
project(
113-
${SKBUILD_PROJECT_NAME}
114-
VERSION ${SKBUILD_PROJECT_VERSION}
115-
LANGUAGES CXX)
112+
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)
116113
114+
set(PYBIND11_FINDPYTHON ON)
117115
find_package(pybind11 CONFIG REQUIRED)
118116
119117
pybind11_add_module(_core MODULE src/main.cpp)
120118
install(TARGETS _core DESTINATION ${SKBUILD_PROJECT_NAME})
121-
122119
```
123120
<!-- [[[end]]] -->
124121
<!-- prettier-ignore-end -->
@@ -168,7 +165,6 @@ py.extension_module('_core',
168165
'cpp_rtti=true',
169166
]
170167
)
171-
172168
```
173169
<!-- [[[end]]] -->
174170
<!-- prettier-ignore-end -->
@@ -205,7 +201,6 @@ version = "0.18.1"
205201
# "extension-module" tells pyo3 we want to build an extension module (skips linking against libpython.so)
206202
# "abi3-py38" tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.8
207203
features = ["extension-module", "abi3-py38"]
208-
209204
```
210205
<!-- [[[end]]] -->
211206
<!-- prettier-ignore-end -->
@@ -253,7 +248,6 @@ PYBIND11_MODULE(_core, m) {
253248
Some other explanation about the subtract function.
254249
)pbdoc");
255250
}
256-
257251
```
258252
<!-- [[[end]]] -->
259253
<!-- prettier-ignore-end -->
@@ -297,7 +291,6 @@ PYBIND11_MODULE(_core, m) {
297291
Some other explanation about the subtract function.
298292
)pbdoc");
299293
}
300-
301294
```
302295
<!-- [[[end]]] -->
303296
<!-- prettier-ignore-end -->
@@ -334,7 +327,6 @@ fn _core(_py: Python, m: &PyModule) -> PyResult<()> {
334327

335328
Ok(())
336329
}
337-
338330
```
339331
<!-- [[[end]]] -->
340332
<!-- prettier-ignore-end -->

0 commit comments

Comments
 (0)