Skip to content

Commit 8e2cc41

Browse files
committed
PoC: literalinclude directives
1 parent 0004c40 commit 8e2cc41

File tree

3 files changed

+84
-79
lines changed

3 files changed

+84
-79
lines changed

examples/pure-hatch/pyproject.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "examplePy"
7+
authors = [
8+
{name = "Some Maintainer", email = "[email protected]"},
9+
]
10+
maintainers = [
11+
{name = "All the contributors"},
12+
]
13+
description = "An example Python package used to support Python packaging tutorials"
14+
keywords = ["pyOpenSci", "python packaging"]
15+
readme = "README.md"
16+
classifiers = [
17+
"Programming Language :: Python :: 3",
18+
"License :: OSI Approved :: BSD License",
19+
"Operating System :: OS Independent",
20+
]
21+
dependencies = [
22+
"dependency-package-name-1",
23+
"dependency-package-name-2",
24+
]
25+
26+
[project.optional-dependencies]
27+
tests = [
28+
"pytest",
29+
"pytest-cov"
30+
]
31+
lint = [
32+
"black",
33+
"flake8"
34+
]
35+
docs = [
36+
"sphinx",
37+
"pydata-sphinx-theme"
38+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[build-system]
2+
requires = ["setuptools>=61"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "examplePy"
7+
authors = [
8+
{name = "Some Maintainer", email = "[email protected]"},
9+
]
10+
maintainers = [
11+
{name = "All the contributors"},
12+
]
13+
description = "An example Python package used to support Python packaging tutorials"
14+
keywords = ["pyOpenSci", "python packaging"]
15+
readme = "README.md"
16+
classifiers = [
17+
"Programming Language :: Python :: 3",
18+
"License :: OSI Approved :: BSD License",
19+
"Operating System :: OS Independent",
20+
]
21+
dependencies = [
22+
"dependency-package-name-1",
23+
"dependency-package-name-2",
24+
]

package-structure-code/pyproject-toml-python-package-metadata.md

Lines changed: 22 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,13 @@ Below that table identifier are key/value pairs that
8888
support configuration for that particular table.
8989

9090
- Below `[build-system]` is considered a table in the toml language.
91-
- Within the build-system table below requires = is a key.
92-
- The associated value for requires is an array containing the value "hatchling".
91+
- Within the `build-system` table below `requires =` is a key.
92+
- The associated value for `requires` is an array containing the value `"hatchling"`.
9393

94-
```toml
95-
[build-system] # <- this is a table
96-
requires = ["hatchling"] # requires = is a key and "hatchling" is a value contained within an array specified by square brackets [].
97-
98-
```
94+
:::{literalinclude} ../examples/pure-hatch/pyproject.toml
95+
:language: toml
96+
:lines: 1-2
97+
:::
9998

10099
### How the pyproject.toml is used when you build a package
101100

@@ -160,11 +159,10 @@ what dependencies your package requires.
160159
- **Authors:** these are the original authors of the package. Sometimes the authors are different from the maintainers. Other times they might be the same.
161160
- **Maintainers:** you can choose to populate this or not. You can populate this using a list with a sub element for each author or maintainer name, email
162161

163-
```toml
164-
authors = [
165-
{name = "A. Random Developer", email = "[email protected]" }
166-
]
167-
```
162+
:::{literalinclude} ../examples/pure-hatch/pyproject.toml
163+
:language: toml
164+
:lines: 7-9
165+
:::
168166

169167
- **dependencies:** dependencies are optional but we strongly suggest you include them in your pyproject.toml. Dependencies will be installed by pip when your project is installed creating a better user-experience.
170168

@@ -194,21 +192,10 @@ To add dependencies to your build, add a `[project.optional-dependencies]` table
194192

195193
Then specify dependency groups as follows:
196194

197-
```
198-
[project.optional-dependencies]
199-
tests = [
200-
"pytest,
201-
"pytest-cov"
202-
]
203-
lint = [
204-
"black",
205-
"flake8"
206-
]
207-
docs = [
208-
"sphinx",
209-
"pydata-sphinx-theme
210-
]
211-
```
195+
:::{literalinclude} ../examples/pure-hatch/pyproject.toml
196+
:language: toml
197+
:lines: 26-38
198+
:::
212199

213200
Following the above example, you install dependencies like this:
214201

@@ -232,32 +219,10 @@ You can also setup sets of recursive dependencies. [See this blog post for more.
232219
Below is an example build configuration for a Python project. This example
233220
package setup uses **hatchling** to build the [package's sdist and wheels](python-package-distribution-files-sdist-wheel).
234221

235-
```toml
236-
[build-system]
237-
requires = ["hatchling"]
238-
build-backend = "hatchling.build"
239-
240-
[project]
241-
name = "examplePy"
242-
authors = [
243-
{name = "Some Maintainer", email = "[email protected]"},
244-
]
245-
maintainers = [
246-
{name = "All the contributors"},
247-
]
248-
description = "An example Python package used to support Python packaging tutorials"
249-
keywords = ["pyOpenSci", "python packaging"]
250-
readme = "README.md"
251-
classifiers = [
252-
"Programming Language :: Python :: 3",
253-
"License :: OSI Approved :: BSD License",
254-
"Operating System :: OS Independent",
255-
]
256-
dependencies = [
257-
"dependency-package-name-1",
258-
"dependency-package-name-2",
259-
]
260-
```
222+
:::{literalinclude} ../examples/pure-hatch/pyproject.toml
223+
:language: toml
224+
:lines: 1-24
225+
:::
261226

262227
Notice that dependencies are specified in this file.
263228

@@ -278,32 +243,10 @@ of values. It has two keys that specify the build backend API and containing pac
278243
1. `requires =`
279244
1. `build-back-end =`
280245

281-
```
282-
[build-system]
283-
requires = ["setuptools>=61"]
284-
build-backend = "setuptools.build_meta"
285-
286-
[project]
287-
name = "examplePy"
288-
authors = [
289-
{name = "Some Maintainer", email = "[email protected]"},
290-
]
291-
maintainers = [
292-
{name = "All the contributors"},
293-
]
294-
description = "An example Python package used to support Python packaging tutorials"
295-
keywords = ["pyOpenSci", "python packaging"]
296-
readme = "README.md"
297-
classifiers = [
298-
"Programming Language :: Python :: 3",
299-
"License :: OSI Approved :: BSD License",
300-
"Operating System :: OS Independent",
301-
]
302-
dependencies = [
303-
"dependency-package-name-1",
304-
"dependency-package-name-2",
305-
]
306-
```
246+
:::{literalinclude} ../examples/pure-setuptools/pyproject.toml
247+
:language: toml
248+
:lines: 1-24
249+
:::
307250

308251
```{note}
309252
[Click here to read about our packaging build tools including PDM, setuptools, Poetry and Hatch.](/package-structure-code/python-package-build-tools)

0 commit comments

Comments
 (0)