@@ -24,7 +24,7 @@ sure you have the latest version installed:
2424 A simple project
2525----------------
2626
27- This tutorial uses a simple project named ``example_pkg ``. We recommend
27+ This tutorial uses a simple project named ``example_package ``. We recommend
2828following this tutorial as-is using this project, before packaging your own
2929project.
3030
@@ -34,11 +34,23 @@ Create the following file structure locally:
3434
3535 packaging_tutorial/
3636 └── src/
37- └── example_pkg/
38- └── __init__.py
37+ └── example_package/
38+ ├── __init__.py
39+ └── example.py
3940
40- :file: `src/example_pkg/__init__.py ` is required to import the directory as a
41- package, and should be empty. If you are unfamiliar with Python's modules and
41+ :file: `__init__.py ` is required to import the directory as a package, and
42+ should be empty.
43+
44+ :file: `example.py ` is an an example of a module within the package that could
45+ contain the logic (functions, classes, constants, etc.) of your package.
46+ Open that file and enter the following content:
47+
48+ .. code-block :: python
49+
50+ def add_one (number ):
51+ return number + 1
52+
53+ If you are unfamiliar with Python's :term: `modules <Module> ` and
4254:term: `import packages <Import Package> `, take a few minutes to read over the
4355`Python documentation for packages and modules `_.
4456
@@ -63,8 +75,9 @@ When you're done, the project structure will look like this:
6375 ├── README.md
6476 ├── setup.cfg
6577 ├── src/
66- │ └── example_pkg/
67- │ └── __init__.py
78+ │ └── example_package/
79+ │ ├── __init__.py
80+ │ └── example.py
6881 └── tests/
6982
7083
@@ -206,7 +219,7 @@ be required, but can be omitted with newer versions of setuptools and pip.
206219 <Distribution Package> `. Instead of listing each package manually, we can
207220 use the ``find: `` directive to automatically discover all packages and
208221 subpackages and ``options.packages.find `` to specify the ``package_dir ``
209- to use. In this case, the list of packages will be ``example_pkg `` as
222+ to use. In this case, the list of packages will be ``example_package `` as
210223 that's the only package present.
211224 - ``python_requires `` gives the versions of Python supported by your
212225 project. Installers like :ref: `pip ` will look back though older versions of
@@ -298,7 +311,7 @@ be required, but can be omitted with newer versions of setuptools and pip.
298311 <Distribution Package> `. Instead of listing each package manually, we can
299312 use :func: `find_packages ` to automatically discover all packages and
300313 subpackages under ``package_dir ``. In this case, the list of packages will
301- be ``example_pkg `` as that's the only package present.
314+ be ``example_package `` as that's the only package present.
302315 - ``python_requires `` gives the versions of Python supported by your
303316 project. Installers like :ref: `pip ` will look back though older versions of
304317 packages until it finds one that has a matching Python version.
@@ -419,8 +432,8 @@ files in the :file:`dist` directory:
419432.. code-block :: text
420433
421434 dist/
422- example_pkg_YOUR_USERNAME_HERE -0.0.1-py3-none-any.whl
423- example_pkg_YOUR_USERNAME_HERE -0.0.1.tar.gz
435+ example_package_YOUR_USERNAME_HERE -0.0.1-py3-none-any.whl
436+ example_package_YOUR_USERNAME_HERE -0.0.1.tar.gz
424437
425438 .. note :: If you run into trouble here, please copy the output and file an issue
426439 over on `packaging problems `_ and we'll do our best to help you!
@@ -497,9 +510,9 @@ After the command completes, you should see output similar to this:
497510 Uploading distributions to https://test.pypi.org/legacy/
498511 Enter your username: [your username]
499512 Enter your password:
500- Uploading example_pkg_YOUR_USERNAME_HERE -0.0.1-py3-none-any.whl
513+ Uploading example_package_YOUR_USERNAME_HERE -0.0.1-py3-none-any.whl
501514 100%| █████████████████████| 4.65k/4.65k [00:01< 00:00, 2.88kB/s]
502- Uploading example_pkg_YOUR_USERNAME_HERE -0.0.1.tar.gz
515+ Uploading example_package_YOUR_USERNAME_HERE -0.0.1.tar.gz
503516 100%| █████████████████████| 4.25k/4.25k [00:01< 00:00, 3.05kB/s]
504517
505518
@@ -564,9 +577,11 @@ and import the package:
564577
565578.. code-block :: python
566579
567- >> > import example_pkg
580+ >> > from example_package import example
581+ >> > example.add_one(2 )
582+ 3
568583
569- Note that the :term: `import package <Import Package> ` is ``example_pkg ``
584+ Note that the :term: `import package <Import Package> ` is ``example_package ``
570585regardless of what ``name `` you gave your :term: `distribution package <Distribution
571586Package> ` in :file: `setup.cfg ` or :file: `setup.py ` (in this case,
572587``example-pkg-YOUR-USERNAME-HERE ``).
0 commit comments