Skip to content

Commit fbe8c77

Browse files
committed
Adjusting Python packaging slides according to slide mode on HedgeDoc
1 parent 8abacb6 commit fbe8c77

2 files changed

Lines changed: 65 additions & 52 deletions

File tree

03_building_and_packaging/intro_slides.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ slideOptions:
3030
## Learning goals of chapter
3131

3232
- Explain why software is packaged.
33-
- Create a distributable package of a raw Python code, publish on PyPI, and install with pip.
33+
- Create a distributable package of a Python code, publish on PyPI, and install with pip.
3434
- Understand the difference between static and dynamic libraries and common ways of installation on Linux.
3535
- Build C++ software and handle dependencies with Make and CMake.
3636
- Package C++ software with CPack and create Debian packages.
@@ -73,10 +73,10 @@ slideOptions:
7373

7474
- First step is finding the right standard for your code.
7575
- There are several options:
76-
- One of the many Linux package managers: apt, dpkg, yum, RPM and many more ...
77-
- [CMake](https://cmake.org/) <span>: building / installation / packaging tool mostly for C, C++ projects<!-- .element: class="fragment" data-fragment-index="1" --></span>
78-
- [Spack](https://spack.io/) <span>: a package management tool mostly for supercomputing centers<!-- .element: class="fragment" data-fragment-index="1" --></span>
79-
- [Conan](https://conan.io/) <span>: open-source package manager for C and C++ development<!-- .element: class="fragment" data-fragment-index="1" --></span>
76+
- Linux package managers: apt, dpkg, yum, RPM, etc.
77+
- [CMake](https://cmake.org/)
78+
- [Spack](https://spack.io/)
79+
- [Conan](https://conan.io/)
8080
- [pip](https://pypi.org/project/pip/)
8181
- [Conda](https://docs.conda.io/en/latest/)
8282
- and many more ...
@@ -87,7 +87,7 @@ slideOptions:
8787

8888
- Python is easy to understand and widely used in research software.
8989
- Well established package managers and packaging tools already exist in the Python community.
90-
- Several examples of packaged codes: [NumPy](https://pypi.org/project/numpy/), [SciPy](https://pypi.org/project/scipy/), [PyTorch](https://pypi.org/project/torch/) and more ...
90+
- Several examples of packaged codes: [NumPy](https://pypi.org/project/numpy/), [SciPy](https://pypi.org/project/scipy/), [PyTorch](https://pypi.org/project/torch/).
9191

9292
---
9393

03_building_and_packaging/pypi_slides.md

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ slideOptions:
3333

3434
## Python Package Managers 1/3
3535

36-
The most significant package managers:
37-
38-
- pip
39-
- Conda
40-
- Poetry
41-
- uv
36+
Many package managers out there: **pip**, **Conda**, **Poetry**, **uv**, and more.
4237

4338
---
4439

@@ -58,41 +53,35 @@ Poetry and uv are newer variants with better functionality and speed.
5853

5954
## Python Package Managers 3/3
6055

61-
In this lecture, we work with pip, because ...
56+
In this lecture we work with pip, because ...
6257

6358
- ... of its wide use in the Python community.
64-
- ... the package repository PyPI is large.
65-
- ... it is still the fundamental way to package Python code.
59+
- ... the packaging index PyPI is large.
60+
- ... it is still the go-to solution to package Python code.
6661
- ... it is easy to understand and use.
6762

6863
---
6964

7065
## Python Enhancement Proposals (PEPs)
7166

72-
- PEP is an evolving design document which provides information regarding new features, processes and new environments.
73-
- PEPs typically involve concise technical information, which also acts as standardizations.
67+
- PEP is an evolving design document which guides Python development.
68+
- PEPs typically involve concise technical information, which also act as standards.
7469
- Packaging is standardized by [Packaging PEPs](https://peps.python.org/topic/packaging/).
7570
- Example of a Packaging PEP: [PEP 427 – The Wheel Binary Package Format 1.0](https://peps.python.org/pep-0427/).
7671

7772
---
7873

7974
## Distribution Package vs. Import Package
8075

81-
Distribution package
82-
83-
- Something you can install.
84-
- `pip install pkg`.
85-
- Directly acquired from a packaging index.
86-
87-
Import package
88-
89-
- An import package is a Python module which typically contains submodules.
90-
- Writing `import pkg` in a file. Potentially also `from pkg import xyz`.
91-
- Import package is available when its distribution package is installed.
92-
93-
Distribution package name and import package need not be the same, but usually is.
76+
- Distribution package is ...
77+
- ... something you can install, like `pip install pkg`.
78+
- ... directly acquired from a packaging index.
79+
- Import package
80+
- ... is a Python module which typically contains submodules.
81+
- ... is used within a file: `import pkg` or `from pkg import xyz`.
82+
- ... is available when its distribution package is installed.
9483

95-
Read more about [distribution package vs. import package](https://packaging.python.org/en/latest/discussions/distribution-package-vs-import-package/#distribution-package-vs-import-package).
84+
Distribution package name and import package need not be the same, but usually is. Read more about [distribution package vs. import package](https://packaging.python.org/en/latest/discussions/distribution-package-vs-import-package/#distribution-package-vs-import-package).
9685

9786
---
9887

@@ -101,7 +90,7 @@ Read more about [distribution package vs. import package](https://packaging.pyth
10190
1. Get or create a source tree of the code.
10291
2. Write a packaging configuration file, typically `pyproject.toml`.
10392
3. Create build artifacts.
104-
4. Upload the build artifacts to the package distribution service (PyPI).
93+
4. Upload the build artifacts to a packaging index.
10594

10695
---
10796

@@ -147,7 +136,7 @@ Four places where naming is relevant:
147136
- Name of the distribution package.
148137
- Name of the import package.
149138

150-
**All names are independent of each other, but try to have one name.**
139+
**All names are independent of each other, but try to have a single name.**
151140

152141
---
153142

@@ -187,51 +176,69 @@ What happened to the files `setup.py` and `setup.cfg`?
187176

188177
- `setup.py` is a configuration file for the build backend `setuptools`.
189178
- It still remains a valid configuration file.
190-
- Using `setup.py` as a command line tool is **deprecated**, avoid `python setup.py`.
179+
- Using `setup.py` as a command line tool is **deprecated**.
191180
- `setup.cfg` is yet another valid configuration file for `setuptools`.
192-
- These files are necessary if the Python package as C extensions.
181+
- These files are necessary if the Python package has C extensions.
193182

194183
Read more in [is setup.py deprecated?](https://packaging.python.org/en/latest/discussions/setup-py-deprecated/#setup-py-deprecated).
195184

196185
---
197186

198187
## Create Build Artifacts 1/3
199188

200-
Source distribution (sdist) vs. built distribution (wheel)
189+
Source distribution (sdist) vs. built distribution (wheel).
201190

202-
Base command is `python3 -m build`.
191+
Base command
192+
193+
```bash
194+
python3 -m build
195+
```
203196

204197
---
205198

206199
## Create Build Artifacts 2/3
207200

208201
Source distribution (sdist)
209202

210-
- Contains files enough to install the package from source at end location.
211-
- Run `python3 -m build --sdist source-tree-directory`.
203+
- Contains files enough to install the package from source.
204+
- Run
205+
206+
```bash
207+
python3 -m build --sdist source-tree-directory
208+
```
212209

213210
---
214211

215212
## Create Build Artifacts 3/3
216213

217214
Built distribution (wheel)
218215

219-
- Contains files needed only to run package at end location.
220-
- No compilation done, just a copy paste into a directory at end location.
216+
- Contains files needed only to run package.
217+
- No compilation done, just a copy paste into a directory.
221218
- In most cases only one generic wheel is required. Exceptions are different Python interpreters, different OS configurations.
222-
- Run `python3 -m build --wheel source-tree-directory`.
219+
- Run
220+
221+
```bash
222+
python3 -m build --wheel source-tree-directory
223+
```
224+
223225
- If no wheel is available, pip falls back to source distribution.
224226

225227
---
226228

227229
## Uploading Build Artifacts
228230

229-
- The [twine](https://twine.readthedocs.io/en/latest/) is a tool to upload the build artifacts.
230-
- Run `twine upload dist/package-name-version.tar.gz dist/package-name-version-py3-none-any.whl`.
231-
- Why Twine?
232-
- Secure authentication of the user over HTTPS using a verified connection.
233-
- Its predecessor `python setup.py upload` required careful configuration, and is deprecated.
234-
- Encourages users to create distribution files to promote testing before releasing.
231+
- [twine](https://twine.readthedocs.io/en/latest/) is a tool to upload the build artifacts.
232+
- Run
233+
234+
```bash
235+
twine upload dist/package-name-version.tar.gz dist/package-name-version-py3-none-any.whl
236+
```
237+
238+
- Use `twine` because ...
239+
- ... it uses secure authentication of the user over HTTPS.
240+
- ... its predecessor `python setup.py upload` required careful configuration, and is deprecated.
241+
- ... encourages users to create distribution files to promote testing before releasing.
235242
- The archive files are uploaded to a package index from where pip can get them.
236243

237244
---
@@ -244,6 +251,10 @@ Built distribution (wheel)
244251

245252
---
246253

254+
## pip Demo
255+
256+
---
257+
247258
## pip 2/3
248259

249260
Executing:
@@ -319,7 +330,11 @@ List packages by running
319330
pip freeze
320331
```
321332

322-
also useful to generate `requirements.txt`: `pip freeze > requirements.txt`.
333+
also useful to generate `requirements.txt`:
334+
335+
```bash
336+
pip freeze > requirements.txt
337+
```
323338

324339
Additionally what works is
325340

@@ -348,9 +363,7 @@ pipx list
348363

349364
---
350365

351-
## Example of PyPI package: fenicsprecice
352-
353-
- Having a look at [fenicsprecice](https://pypi.org/project/fenicsprecice/)
366+
## Example of PyPI package: [fenicsprecice](https://pypi.org/project/fenicsprecice/)
354367

355368
---
356369

0 commit comments

Comments
 (0)