@@ -13,8 +13,8 @@ which needs some explanation.
1313
1414## Project structure
1515
16- First an overview of the main folder structure. See line comments for details on what
17- folder or file purpose.
16+ First an overview of the main folder structure. See line comments for details on what
17+ is the purpose of each folder or file:
1818
1919``` bash
2020python_package
@@ -32,23 +32,30 @@ python_package
3232
3333## Core packaging files
3434
35- We will first look at ` pyproject.toml ` and it's relation to the ` src ` directory.
35+ We will first look at [ ` pyproject.toml ` ] and it's relation to the [ ` src ` ] ( src ) directory. The
36+ [ ` project.toml ` ] ( pyproject.toml ) file is the main configuration file for the Python package
37+ and is used to specify the package metadata, dependencies, build tools and configurations.
38+ The [ ` src ` ] ( src ) folder stores the actual source code of the package, where the package itself is
39+ the subdirectories of the [ ` src ` ] ( src ) directory. The (e.g. ` src/python_package ` ).
3640
3741<details >
3842<summary >About <code >setup.py</code > and <code >setup.cfg</code > configuration files</summary >
3943
40- The ` setup.py ` file is an artefact for backward compatibility and should not be changed.
41- Everything that used to be in ` setup.py ` or ` setup.cfg ` is now largely in ` pyproject.toml ` .
44+ The [ ` setup.py ` ] ( setup.py ) file is an artefact for backward compatibility and should not
45+ be changed. Everything that used to be in [ ` setup.py ` ] ( setup.py ) or
46+ [ ` setup.cfg ` ] ( setup.cfg ) is now largely in [ ` pyproject.toml ` ] ( pyproject.toml ) .
4247The notable exception is specifying the desired maximum line length in ` setup.cfg ` via
43- the ` flake8 ` section, which is not yet supported in ` pyproject.toml ` . We specify the line
44- length for ruff in ` pyproject.toml ` and for flake8 in ` setup.cfg ` .
48+ the [ ` flake8 ` ] ( https://flake8.pycqa.org/ ) section, which is not yet supported in
49+ [ ` pyproject.toml ` ] ( pyproject.toml ) .
50+ We specify the line length for ruff in [ ` pyproject.toml ` ] ( pyproject.toml ) . and
51+ for flake8 in [ ` setup.cfg ` ] ( setup.cfg ) .
4552
4653</details >
4754
4855### Changes required in ` pyproject.toml `
4956
5057You have to change entries under the ` [project] ` section to match your project name,
51- description, author, license, etc. The ` dependencies ` section can list the dependencies
58+ description, author, license, etc. The ` dependencies ` key can list the dependencies
5259and is currently commented out. The dependencies could also be specified in via a
5360` requirements.txt ` , if you already have such a file.
5461
@@ -88,13 +95,13 @@ dynamic = ["version"]
8895
8996means that the version is loaded dynamically using the extension
9097[ setuptools_scm] ( https://setuptools-scm.readthedocs.io/ )
91- we list under the ` [build-system] ` section in ` pyproject.toml ` .
98+ we list under the ` [build-system] ` section in [ ` pyproject.toml ` ] ( pyproject.toml ) .
9299This is done to avoid having to manually update the version and integrate with automatic
93100versioning through releases on GitHub. It also
94101ensures that each commit has a unique version number, which is useful for attributing
95102errors to specific non-released versions. The dynamic version is picked up in the
96103` __version__ ` variable in the ` __init__.py ` file of the package, which is located in the
97- ` src/python_package ` directory.
104+ [ ` src/python_package ` ] ( src/python_package ) directory.
98105
99106``` toml
100107[build-system ]
@@ -136,8 +143,9 @@ name = "my_package"
136143```
137144
138145Strictly speaking you can give different names in both places, but this will only confuse
139- potential users. Think of ` scikit-learn ` for an example of a package that has a different
140- name in the [ ` pyproject.toml ` ] ( pyproject.toml ) file and the source code directory name.
146+ potential users. Think of ` scikit-learn ` for an example of a package that uses a different
147+ name in the [ ` pyproject.toml ` ] ( pyproject.toml ) file and the source code directory name,
148+ leading to the ` sklearn ` package name when imported.
141149
142150## Documentation
143151
@@ -146,7 +154,7 @@ which is common for Python documentation. It relies additionally on several exte
146154enabling the use of ` markdown ` and ` jupyter ` notebooks.
147155
148156The documentation is located in the [ ` docs ` ] ( docs ) directory. Sphinx is configured via
149- the [ ` conf.py ` ] ( docs/conf.py ) file, where you can specify the extension you want.
157+ the [ ` conf.py ` ] ( docs/conf.py ) file, where you can specify the extension you want:
150158
151159``` python
152160# in docs/conf.py
@@ -180,6 +188,8 @@ docs = [
180188]
181189```
182190
191+ ### Required changes in ` conf.py `
192+
183193The required changes in [ ` conf.py ` ] ( docs/conf.py ) are at the following places:
184194
185195``` python
@@ -212,6 +222,8 @@ if os.environ.get("READTHEDOCS") == "True":
212222The last block is for Read The Docs to be able to generate the API documentation of your
213223package on the fly. See the Read The Docs section below for more details.
214224
225+ ### Theme, autodoc and intersphinx
226+
215227We build the documentation based on the template
216228[ sphinx_book_theme] ( https://sphinx-book-theme.readthedocs.io ) , which is set in the
217229[ ` conf.py ` ] ( docs/conf.py ) file and parts of our docs requirements in
@@ -226,8 +238,10 @@ html_theme = "sphinx_book_theme"
226238> [ sphinx-themes.org] ( https://sphinx-themes.org/ )
227239
228240The API of the Python package in the ` src ` directory is automatically included
229- in the documentation using the ` autodoc ` extension. The API documentation can be
230- augumented with hightlights from other types from projects using ` intersphinx ` :
241+ in the documentation using the
242+ [ ` autodoc ` extension] ( https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html ) .
243+ The API documentation can be augmented with highlights from other types from projects
244+ using ` intersphinx ` :
231245
232246``` python
233247# Intersphinx options
@@ -242,9 +256,11 @@ intersphinx_mapping = {
242256Here we only add the core Python documentation, but you can add more projects
243257like ` pandas ` , ` scikit-learn ` , or ` matplotlib ` to the mapping.
244258
259+ ### Building the documentation locally (with integration tests)
260+
245261To build the documentation locally, you can follow the instructions in the
246262[ ` docs/README.md ` ] ( docs/README.md ) , which you should also update with your name changes.
247- In short, you can run the following commands in the ` docs ` directory:
263+ In short, you can run the following commands in the [ ` docs ` ] ( docs ) directory:
248264
249265``` bash
250266# in root of the project
@@ -255,8 +271,8 @@ sphinx-build -n -W --keep-going -b html ./ ./_build/
255271```
256272
257273this will create a ` reference ` directory with the API documentation of the Python package
258- ` python_package ` , a ` jupyter_execute ` for the tutorial in ` docs/tutorial ` and a
259- ` _build ` directory with an HTML version of the documentation. You can open the
274+ ` python_package ` , a ` jupyter_execute ` for the tutorial in [ ` docs/tutorial ` ] ( docs/tutorial )
275+ and a ` _build ` directory with an HTML version of the documentation. You can open the
260276` _build/index.html ` file in your browser to view the documentation built locally.
261277
262278The tutorial related configuration in ` conf.py ` is the following, specifying that
@@ -297,9 +313,9 @@ format to `py:percent` and automatically allows syncing of new notebooks.
297313### Read The Docs
298314
299315To build the documentation on Read The Docs, you need to create a file called
300- ` .readthedocs.yaml ` , which is located in the root of the project and specifies which
301- dependencies are needed. The core is the following specifying where the ` conf.py ` file
302- is and from where to install the required dependencies:
316+ [ ` .readthedocs.yaml ` ] ( .readthedocs.yaml ) , which is located in the root of the project and
317+ specifies which dependencies are needed. The core is the following specifying where the
318+ [ ` conf.py ` ] ( docs/conf.py ) file is and from where to install the required dependencies:
303319
304320``` yaml
305321# Build documentation in the "docs/" directory with Sphinx
@@ -317,8 +333,9 @@ python:
317333You will need to manually register your project repository on
318334[Read The Docs](https://readthedocs.org/) in order that it can build the documentation
319335by the service. I recommend to activate builds for Pull Requests, so that
320- the documentation is built for each PR and you can see if the documentation gradually
321- breaking and your work advancing. See their documentation
336+ the documentation is built for each PR and you can see if the documentation is gradually
337+ breaking, i.e. your integration test using the notebooks in
338+ [` docs/tutorial`](docs/tutorial) fail. See their documentation
322339[on adding a project](https://docs.readthedocs.com/platform/stable/intro/add-project.html)
323340for instructions.
324341
@@ -335,15 +352,15 @@ linter `ruff`:
335352dev = ["black[jupyter]", "ruff", "pytest"]
336353` ` `
337354
338- Instead of running these tools manually, typing :
355+ Instead of running these tools manually, typing
339356
340357` ` ` bash
341358black .
342359ruff check .
343360pytest tests
344361` ` `
345362
346- Read the next section to see how this is automated using `GitHub Actions`.
363+ read the next section to see how this is automated using `GitHub Actions`.
347364
348365# # GitHub Actions
349366
@@ -414,7 +431,7 @@ jobs:
414431 run: python -m pytest tests
415432` ` `
416433
417- This files also allows to create `PyPI` releases automatically if you register your
434+ This workflow also allows to create `PyPI` releases automatically if you register your
418435project on `PyPI` (or `TestPyPI` for testing first) and create a GitHub release :
419436
420437` ` ` yaml
@@ -441,9 +458,10 @@ project on `PyPI` (or `TestPyPI` for testing first) and create a GitHub release:
441458 repository-url: https://test.pypi.org/legacy/
442459` ` `
443460
444- To setup the `gh-action-pypi-publish` action, you need to register the repository
445- on `PyPI` or `TestPyPI`, which allows PyPI and GitHub to communicate securely.
446- See the instructions on
461+ To setup the [`gh-action-pypi-publish`](https://github.com/pypa/gh-action-pypi-publish)
462+ action, you need to register the repository
463+ on [PyPI](https://pypi.org/) or [`TestPyPI`](https://test.pypi.org/), which allows PyPI
464+ and GitHub to communicate securely. See the instructions on
447465[packaging.python.org](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/).
448466
449467> The wheels are not built by default, but you can be necessary for packages which need
@@ -468,13 +486,11 @@ python_package
468486├── tests
469487│ ├── __init__.py
470488│ └── test_mockup.py # files and test_function need to start with test_ to be recognized by pytest
471- ├── LICENSE
472- ├── MANIFEST.in
473- ├── pyproject.toml
474- ├── pytest.ini
475- ├── README.md
476- ├ ── setup.cfg # only used to set flake8 line length
477- └── setup.py
489+ ├── LICENSE # License file specifying usage terms
490+ ├── MANIFEST.in # non-python files to include into the build package
491+ ├── pyproject.toml # python package metadata, dependencies and configurations (incl. build tools)
492+ ├── pytest.ini # pytest configuration
493+ ├── README.md # README which is rendered on GitHub (or other hosting services)
494+ └ ── setup.cfg # old python configuration file, only used to set flake8 line length
495+ └── setup.py # artefact for backward compatibility, do not change
478496` ` `
479-
480-
0 commit comments