Skip to content

Commit 34dbc73

Browse files
committed
Add packaging docs.
1 parent 105bb4f commit 34dbc73

3 files changed

Lines changed: 79 additions & 15 deletions

File tree

‎README.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ TODO
121121
====
122122

123123
- writing: packaging
124+
- badge for google slides
124125
- change documentation links to main branch
125126
- joblib example in profile
126127
- github page
@@ -129,3 +130,4 @@ TODO
129130
- manifest file to not include file in package
130131
- GitHub actions for releasing to PyPi when changes to version
131132
- cupy / pytorch compatible
133+
- Cython / C++

‎docs/source/documentation.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Documentation
66
*-- Damian Conway*
77

88
Documentation is a critical part of any software project. It is the first
9-
point of contact for new users, and it is the first place to look for
10-
developers when they need to understand how a piece of code works. It is
9+
point of contact for new users, and it is the first thing developers look
10+
for when they need to understand how a piece of code works. It is
1111
also a great way to share your knowledge with the community.
1212

1313
*As a minimum*, it's good to have a README file that describes:

‎docs/source/packaging.rst‎

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,93 @@
11
Packaging
22
=========
33

4+
Packaging your code is the process of organizing your project files
5+
so that it can be built and installed by other users. As well as
6+
your source code, there are a few files that are needed by
7+
`setuptools <https://setuptools.pypa.io/en/latest/>`__ -- the
8+
commonly-used Python library for packaging code that can be
9+
installed with `pip <https://pypi.org/project/pip>`_ and uploaded
10+
to `PyPI <http://pypi.org/>`_.
11+
12+
413
Project structure
514
-----------------
615

7-
Folder with package subfolder and ``setup.py``
16+
A typical (minimal) file structure for a Python project to be
17+
"pip-installable" looks like so:
818

9-
``setup.py``
10-
------------
19+
.. code::
1120
12-
Specifying metadata and packages.
21+
project/
22+
|-- __init__.py
23+
|-- code.py
24+
|-- # other files
25+
README.rst # or .md, .txt, etc
26+
setup.py
1327
14-
Releasing new version and deploying to PyPi
15-
-------------------------------------------
28+
where:
29+
30+
* The folder ``project`` contains your source code files and
31+
an ``__init__.py``, which could be empty.
32+
* ``README.rst`` which is not necessary for building the Python, but
33+
is often the first file that new users will look into to learn
34+
about the project, how to install it, and how to use it. On GitHub
35+
and PyPI, it will be rendered as the "homepage" for your project.
36+
* ``setup.py`` is a configuration file for installing the project. More
37+
on that :ref:`below <setup.py>`.
38+
39+
The project can then be built (locally) with the command below:
40+
41+
.. code:: bash
42+
43+
(project_env) pip install -e .
44+
45+
The project can be imported in your Python script as:
46+
47+
.. code:: Python
1648
17-
Uploading to PyPi is done via `twine <https://pypi.org/project/twine/>`__.
49+
import project
1850
19-
In the steps below and **after merging to** ``main``, replace "X.X.X" with the appropriate version number.
2051
21-
See `Semantic Versioning <https://semver.org/>`__ for recommendations on picking version numbers.
52+
setup.py
53+
--------
54+
55+
The ``setup.py`` is used to configure the project packaging by ``setuptools``.
56+
Below is the ``setup.py`` file for this "dummy" project.
57+
58+
.. literalinclude:: ../../setup.py
59+
:caption: setup.py
60+
:linenos:
61+
62+
* Lines 3-4: use the contents of ``README.rst`` to be rendered for the homepage
63+
on PyPI. *Be sure to set the correct file extension and set Line 13
64+
accordingly*.
65+
* Line 7: specifies the name of the package / in which folder the source code
66+
is located, such that the package can be installed with ``pip install pydevtips``
67+
if on PyPI and imported as ``import pydevtips``.
68+
* Line 8: sets the package version, *which should be (typically) modified before
69+
uploading a new version to PyPI (below)*.
70+
* Line 9-10: for your name and contact info.
71+
* Line 20-26: specifies the Python version and package dependencies.
72+
73+
Releasing new version and deploying to PyPI
74+
-------------------------------------------
75+
76+
Uploading your project to PyPI is done via the `twine <https://pypi.org/project/twine/>`__
77+
library.
2278

2379
.. code:: bash
2480
2581
# inside virtual environment
2682
(project_env) pip install twine
2783
28-
# edit version in setup
84+
In the steps below, replace "X.X.X" with the appropriate version number, *matching the one
85+
in your* ``setup.py`` *file*. See `Semantic Versioning <https://semver.org/>`__ for
86+
recommendations on picking version numbers.
87+
88+
.. code:: bash
89+
90+
# edit version in `setup.py`
2991
# build package
3092
(project_env) python setup.py sdist bdist_wheel
3193
# -- creates zip in dist folder
@@ -40,8 +102,8 @@ See `Semantic Versioning <https://semver.org/>`__ for recommendations on picking
40102
git tag -a X.X.X -m "version X.X.X"
41103
git push origin X.X.X
42104
43-
On `GitHub <https://github.com/ebezzam/python-dev-tips/tags>`__ create a new release by:
105+
If you project is hosted on GitHub, you can create a new release by:
44106

45-
#. Clicking (the rightmost) "..." dropdown menu.
107+
#. Clicking (the rightmost) "..." dropdown menu (from the `tags page <https://github.com/ebezzam/python-dev-tips/tags>`_).
46108
#. Selecting "Create release".
47-
#. At the bottom pressing "Publish release".
109+
#. At the bottom pressing "Publish release".

0 commit comments

Comments
 (0)