|
|
xi | |
|
|
xiii | |
Preface |
|
xv | |
About the authors |
|
xix | |
|
|
1 | (2) |
|
1.1 Why you should create packages |
|
|
2 | (1) |
|
|
3 | (14) |
|
2.1 The command-line interface |
|
|
3 | (1) |
|
|
3 | (2) |
|
|
3 | (1) |
|
2.2.2 Install packaging software |
|
|
4 | (1) |
|
2.3 Register for a PyPI account |
|
|
5 | (1) |
|
2.4 Set up Git and GitHub |
|
|
5 | (1) |
|
2.5 Python integrated development environments |
|
|
6 | (5) |
|
|
7 | (1) |
|
|
8 | (2) |
|
|
10 | (1) |
|
2.6 Developing with Docker |
|
|
11 | (6) |
|
2.6.1 Docker with Visual Studio Code |
|
|
12 | (2) |
|
2.6.2 Docker with JupyterLab |
|
|
14 | (3) |
|
3 How to package a Python |
|
|
17 | (66) |
|
3.1 Counting words in a text file |
|
|
17 | (5) |
|
3.1.1 Developing our code |
|
|
17 | (3) |
|
3.1.2 Turning our code into functions |
|
|
20 | (2) |
|
|
22 | (4) |
|
3.2.1 A brief introduction |
|
|
22 | (1) |
|
3.2.2 Creating a package structure |
|
|
23 | (3) |
|
3.3 Put your package under version control |
|
|
26 | (4) |
|
3.3.1 Set up local version control |
|
|
26 | (1) |
|
3.3.2 Set up remote version control |
|
|
27 | (3) |
|
|
30 | (2) |
|
3.5 Test drive your package code |
|
|
32 | (5) |
|
3.5.1 Create a virtual environment |
|
|
32 | (1) |
|
3.5.2 Installing your package |
|
|
33 | (4) |
|
3.6 Adding dependencies to your package |
|
|
37 | (6) |
|
3.6.1 Dependency version constraints |
|
|
40 | (3) |
|
|
43 | (6) |
|
|
43 | (2) |
|
|
45 | (3) |
|
|
48 | (1) |
|
3.8 Package documentation |
|
|
49 | (23) |
|
3.8.1 Writing documentation |
|
|
52 | (2) |
|
|
54 | (5) |
|
3.8.3 Creating usage examples |
|
|
59 | (1) |
|
3.8.4 Building documentation |
|
|
60 | (9) |
|
3.8.5 Hosting documentation online |
|
|
69 | (3) |
|
3.9 Tagging a package release with version control |
|
|
72 | (2) |
|
3.10 Building and distributing your package |
|
|
74 | (5) |
|
3.10.1 Building your package |
|
|
74 | (4) |
|
3.10.2 Publishing to TestPyPI |
|
|
78 | (1) |
|
3.10.3 Publishing to PyPI |
|
|
79 | (1) |
|
3.11 Summary and next steps |
|
|
79 | (4) |
|
4 Package structure and distribution |
|
|
83 | (28) |
|
4.1 Packaging fundamentals |
|
|
83 | (6) |
|
|
89 | (14) |
|
|
89 | (3) |
|
4.2.2 Package and module names |
|
|
92 | (1) |
|
4.2.3 Intra-package references |
|
|
93 | (1) |
|
|
94 | (3) |
|
4.2.5 Including non-code files in a package |
|
|
97 | (1) |
|
4.2.6 Including data in a package |
|
|
98 | (3) |
|
|
101 | (2) |
|
4.3 Package distribution and installation |
|
|
103 | (7) |
|
4.3.1 Package installation |
|
|
104 | (3) |
|
4.3.2 Building sdists and wheels |
|
|
107 | (1) |
|
|
108 | (1) |
|
4.3.4 Package repositories |
|
|
109 | (1) |
|
|
110 | (1) |
|
|
111 | (28) |
|
|
111 | (3) |
|
|
114 | (2) |
|
|
116 | (10) |
|
|
116 | (4) |
|
5.3.2 Test that a specific error is raised |
|
|
120 | (3) |
|
|
123 | (1) |
|
|
124 | (2) |
|
5.3.5 How many tests should you write |
|
|
126 | (1) |
|
5.4 Advanced testing methods |
|
|
126 | (6) |
|
|
127 | (2) |
|
|
129 | (3) |
|
|
132 | (6) |
|
|
133 | (1) |
|
|
134 | (1) |
|
5.5.3 Calculating coverage |
|
|
134 | (2) |
|
|
136 | (2) |
|
|
138 | (1) |
|
|
139 | (26) |
|
6.1 Documentation content and workflow |
|
|
139 | (4) |
|
6.2 Writing documentation |
|
|
143 | (11) |
|
|
144 | (1) |
|
|
145 | (1) |
|
6.2.3 Contributing guidelines |
|
|
146 | (1) |
|
|
146 | (1) |
|
|
147 | (1) |
|
|
148 | (2) |
|
|
150 | (3) |
|
6.2.8 Application programming interface (API) reference |
|
|
153 | (1) |
|
6.2.9 Other package documentation |
|
|
153 | (1) |
|
6.3 Building documentation |
|
|
154 | (8) |
|
6.4 Hosting documentation online |
|
|
162 | (3) |
|
7 Releasing and versioning |
|
|
165 | (20) |
|
|
165 | (3) |
|
|
168 | (4) |
|
7.2.1 Manual version bumping |
|
|
168 | (1) |
|
7.2.2 Automatic version bumping |
|
|
169 | (3) |
|
7.3 Checklist for releasing a new package version |
|
|
172 | (9) |
|
7.3.1 Step 1: make changes to package source files |
|
|
173 | (1) |
|
7.3.2 Step 2: document your changes |
|
|
173 | (1) |
|
7.3.3 Step 3: bump version number |
|
|
174 | (2) |
|
7.3.4 Step 4: run tests and build documentation |
|
|
176 | (1) |
|
7.3.5 Step 5: tag a release with version control |
|
|
177 | (1) |
|
7.3.6 Step 6: build and release package to PyPI |
|
|
178 | (3) |
|
|
181 | (1) |
|
7.5 Breaking changes and deprecating package functionality |
|
|
181 | (2) |
|
7.6 Updating dependency versions |
|
|
183 | (2) |
|
8 Continuous integration and deployment |
|
|
185 | (34) |
|
8.1 An introduction to CI/CD |
|
|
185 | (1) |
|
|
186 | (1) |
|
8.3 Introduction to GitHub Actions |
|
|
187 | (6) |
|
|
187 | (1) |
|
|
188 | (4) |
|
8.3.3 Actions and commands |
|
|
192 | (1) |
|
8.4 Setting up continuous integration |
|
|
193 | (7) |
|
|
193 | (3) |
|
|
196 | (1) |
|
8.4.3 Recording code coverage |
|
|
196 | (1) |
|
8.4.4 Build documentation |
|
|
197 | (1) |
|
8.4.5 Testing continuous integration |
|
|
198 | (2) |
|
8.5 Setting up continuous deployment |
|
|
200 | (14) |
|
|
201 | (3) |
|
8.5.2 Automatically creating a new package version |
|
|
204 | (3) |
|
8.5.3 Uploading to TestPyPI and PyPI |
|
|
207 | (3) |
|
8.5.4 Testing continuous deployment |
|
|
210 | (4) |
|
|
214 | (5) |
Bibliography |
|
219 | (2) |
Index |
|
221 | |