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: ch04packaging/03Packaging.ipynb.py
+89-49Lines changed: 89 additions & 49 deletions
Original file line number
Diff line number
Diff line change
@@ -82,22 +82,38 @@
82
82
# %autoreload 2
83
83
84
84
# %% [markdown]
85
-
# ### Using setuptools
85
+
# ### Using pyproject.toml
86
86
87
87
# %% [markdown]
88
+
# Since June 2020, python's recommendation for creating a package is to specify package information in a `pyproject.toml` file.
89
+
# Older projects used a `setup.py` or `setup.cfg` file instead - and in fact the new `pyproject.toml` file in many ways mirrors this old format.
90
+
# A lot of projects and packages have not yet switched over from `setup.py` to `pyproject.toml`, so don't be surprised to see a mixture of the two formats when you're looking at other people's packages.
91
+
92
+
# %% [markdown]
93
+
# For our `greetings` package, right now we are adding only the name of the package and its version number.
94
+
# This information is included in the `project` section of our `pyproject.toml` file.
95
+
#
96
+
# But we also need to tell users how to build the package from these specifications.
97
+
# This information is specified in the `build-system` section of our `toml` file.
98
+
# In this case, we'll be using `setuptools` to build our package, so we list it in the `requires` field.
99
+
# We also need `setuptools_scm[toml]` so that `setuptools` can understand the settings we give it in our `.toml` file, and `wheel` to make the package distribution.
88
100
#
89
-
# To make python code into a package, we need to write a `setup.py` file. For now we are adding only the name of the package and its version number.
101
+
# Finally, we can set specific options for `setuptools` using additional sections in `pyproject.toml`: in this case, we will tell `setuptools` that it needs to find **and include** all of the files in our `greetings` folder.
# And the package will be then available to use everywhere on the system. But so far this package doesn't contain anythin and there's nothing we can run! We need to add some files first.
128
+
# And the package will be then available to use everywhere on the system. But so far this package doesn't contain anything and there's nothing we can run! We need to add some files first.
113
129
#
114
130
115
131
# %% [markdown]
@@ -256,20 +272,25 @@ def process():
256
272
# %% [markdown]
257
273
# This allows us to create a command to execute part of our library. In this case when we execute `greet` on the terminal, we will be calling the `process` function under `greetings/command.py`.
258
274
#
275
+
# We can encode this into our package information by specifying the `project.scripts` field in our `pyproject.toml` file.
# When installing the package now, pip will also install the dependencies automatically.
@@ -569,23 +596,36 @@ def test_greeter(fixture):
569
596
# pytest --doctest-modules
570
597
571
598
# %% [markdown]
572
-
# Finally, if we don't want to include the tests when we distribute our software for our users, you can include that using the `exclude` option on `find_packages` on `setup.py`.
599
+
# Finally, we typically don't want to include the tests when we distribute our software for our users.
600
+
# We can make sure they are not included using the `exclude` option on when telling `setuptools` to find packages.
601
+
#
602
+
# Additionally, we can make sure that our README and LICENSE are included in our package metadata by declaring them in the `readme` and `license` fields under the `project` section.
603
+
# If you're using a particularly common or standard license, you can even provide the name of the license, rather than the file, and your package builder will take care of the rest!
0 commit comments