You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: package-structure-code/python-package-structure.md
+28-9Lines changed: 28 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -57,10 +57,11 @@ for new maintainers. It is also recommended in the
57
57
makes it easier for you to create a package build workflow that tests your
58
58
package as it will be installed on a users computer.
59
59
60
-
The key characteristic of this layout is that your package
61
-
uses a **src/package-name** directory structure. With this layout it is also
62
-
common to include your `tests/` directory outside of the package
63
-
directory.
60
+
The key characteristics of this layout include:
61
+
62
+
- Your package uses a **src/package-name** directory structure,
63
+
- You include a `tests/` directory outside of the package
64
+
directory.
64
65
65
66
```{admonition} Example scientific packages that use **src/package-name** layout
66
67
@@ -90,15 +91,33 @@ The benefits of the **src/package-name** layout include:
90
91
package rather than on the flat files imported directly from your package. If you run your tests on your flat files, you may be missing issues that users encounter when your package is installed.
91
92
- If `tests/` are outside of the **src/package-name** directory, they aren't by default
92
93
delivered to a user
93
-
installing your package. However, you can chose to add them to the package archive (which is a good idea). When test files (.py files only) are not included in the package archive your package size will be slightly smaller.
94
+
installing your package. When test files (.py files only) are not included in the package wheel your package size will be slightly smaller. This places a smaller storage burden on PyPI which has over 400,000 packages to support.
94
95
95
-
```{admonition} A note about including tests and data in your package distribution
96
-
If you decide to include tests in your package, be sure to read the [pytest documentation](https://docs.pytest.org/en/7.2.x/explanation/goodpractices.html#choosing-a-test-layout-import-rules).
96
+
````{admonition} A note about including tests and data in your package distribution
97
+
If you decide to include tests in your package, your directory structure
98
+
will look like the example below. Notice that below the tests directory
99
+
is contained within the src/package-name directory ensuring the tests will be included in your package's wheel.
97
100
98
-
Also check out the testing section of our guide. Large datasets associated with tests will slow down your package's install which can be frustrating to users. It also will consume more storage space on PyPI which is largely supported by volunteer maintainers and has storage costs to consider for it's 400,000+ packages. As such you
99
-
will want to ensure that large tests datasets are not included in your package distribution.
101
+
```bash
102
+
src/
103
+
package-name/
104
+
tests/
105
+
docs/
100
106
```
101
107
108
+
Be sure to read the [pytest documentation](https://docs.pytest.org/en/7.2.x/explanation/goodpractices.html#choosing-a-test-layout-import-rules).
109
+
110
+
### **Don't include test suite datasets in your package**
111
+
112
+
Large datasets associated with tests will slow down your package's install which can be frustrating to users. It also will consume more storage space on PyPI which is largely supported by volunteer maintainers and has storage costs to consider for it's 400,000+ packages.
113
+
114
+
As such you
115
+
should never include datasets needed for your tests in your package
116
+
distribution. Rather consider hosting them on a data repository such as figshare or zenodo and using a tool such as [Pooch](https://www.fatiando.org/pooch/latest/) to access them when you run tests.
117
+
Check out the testing section of our guide for more information about tests.
118
+
119
+
````
120
+
102
121
- The **src/package-name** layout is semantically more clear. Code is always found in the
103
122
**src/package-name** directory, `tests/` and `docs/`are in the root directory.
0 commit comments