Commit b2af2ea9 authored by alvyjudy's avatar alvyjudy

docs: update quickstart

added a few sections (WIP) to make it more complete
parent 8dbae6ee
...@@ -2,20 +2,18 @@ ...@@ -2,20 +2,18 @@
``setuptools`` Quickstart ``setuptools`` Quickstart
========================== ==========================
.. contents::
Installation Installation
============ ============
.. _Installing Packages: https://packaging.python.org/tutorials/installing-packages/
To install the latest version of setuptools, use:: To install the latest version of setuptools, use::
pip install --upgrade setuptools pip install --upgrade setuptools
Refer to `Installing Packages`_ guide for more information.
Python packaging at a glance Python packaging at a glance
============================ ============================
The landscape of Python packaging is shifting and ``Setuptools`` has evolved to The landscape of Python packaging is shifting and ``Setuptools`` has evolved to
only provide backend support, no longer being the de-facto packaging tool in only provide backend support, no longer being the de-facto packaging tool in
the market. All python package must provide a ``pyproject.toml`` and specify the market. All python package must provide a ``pyproject.toml`` and specify
...@@ -27,9 +25,9 @@ change is driven under `PEP 517 <https://www.python.org/dev/peps/pep-0517/# ...@@ -27,9 +25,9 @@ change is driven under `PEP 517 <https://www.python.org/dev/peps/pep-0517/#
build-requirements>``. To learn more about Python packaging in general, build-requirements>``. To learn more about Python packaging in general,
navigate to the `bottom <Resources on python packaging>`_ of this page. navigate to the `bottom <Resources on python packaging>`_ of this page.
Basic Use Basic Use
========= =========
For basic use of setuptools, you will need a ``pyproject.toml`` with the For basic use of setuptools, you will need a ``pyproject.toml`` with the
exact following info, which declares you want to use ``setuptools`` to exact following info, which declares you want to use ``setuptools`` to
package your project: package your project:
...@@ -62,14 +60,14 @@ This is what your project would look like:: ...@@ -62,14 +60,14 @@ This is what your project would look like::
setup.cfg setup.cfg
mypackage/__init__.py mypackage/__init__.py
Then, you need an installer, such as ``pep517 <https://pypi.org/project/pep517/`` Then, you need an installer, such as `pep517 <https://pypi.org/project/pep517/>`_
which you can obtain via ``pip install pep517``. After downloading it, invoke which you can obtain via ``pip install pep517``. After downloading it, invoke
the installer:: the installer::
pep517 build pep517 build
You now have your distribution ready (e.g. a ``tar.gz`` file and a ``.whl`` You now have your distribution ready (e.g. a ``tar.gz`` file and a ``.whl``
file in the ``dist``), which you can upload to PyPI! file in the ``dist`` directory), which you can upload to PyPI!
Of course, before you release your project to PyPI, you'll want to add a bit Of course, before you release your project to PyPI, you'll want to add a bit
more information to your setup script to help people find or learn about your more information to your setup script to help people find or learn about your
...@@ -78,9 +76,9 @@ dependencies, and perhaps some data files and scripts. In the next few section, ...@@ -78,9 +76,9 @@ dependencies, and perhaps some data files and scripts. In the next few section,
we will walk through those additional but essential information you need we will walk through those additional but essential information you need
to specify to properly package your project. to specify to properly package your project.
Automatic package discovery Automatic package discovery
=========================== ===========================
For simple projects, it's usually easy enough to manually add packages to For simple projects, it's usually easy enough to manually add packages to
the ``packages`` keyword in ``setup.cfg``. However, for very large projects the ``packages`` keyword in ``setup.cfg``. However, for very large projects
, it can be a big burden to keep the package list updated. ``setuptools`` , it can be a big burden to keep the package list updated. ``setuptools``
...@@ -105,9 +103,9 @@ that each entry in the ``[options.packages.find]`` is optional. The above ...@@ -105,9 +103,9 @@ that each entry in the ``[options.packages.find]`` is optional. The above
setup also allows you to adopt a ``src/`` layout. For more details and advanced setup also allows you to adopt a ``src/`` layout. For more details and advanced
use, go to :ref:`package_discovery` use, go to :ref:`package_discovery`
Entry points and automatic script creation Entry points and automatic script creation
=========================================== ===========================================
Setuptools support automatic creation of scripts upon installation, that runs Setuptools support automatic creation of scripts upon installation, that runs
code within your package if you specify them with the ``entry_point`` keyword. code within your package if you specify them with the ``entry_point`` keyword.
This is what allows you to run commands like ``pip install`` instead of having This is what allows you to run commands like ``pip install`` instead of having
...@@ -126,9 +124,9 @@ invoke the ``some_func`` in the ``__init__.py`` file when called by the user. ...@@ -126,9 +124,9 @@ invoke the ``some_func`` in the ``__init__.py`` file when called by the user.
For detailed usage, including managing the additional or optional dependencies, For detailed usage, including managing the additional or optional dependencies,
go to :ref:`entry_point`. go to :ref:`entry_point`.
Dependency management Dependency management
===================== =====================
``setuptools`` supports automatically installing dependencies when a package is ``setuptools`` supports automatically installing dependencies when a package is
installed. The simplest way to include requirement specifiers is to use the installed. The simplest way to include requirement specifiers is to use the
``install_requires`` argument to ``setup.cfg``. It takes a string or list of ``install_requires`` argument to ``setup.cfg``. It takes a string or list of
...@@ -151,9 +149,9 @@ care of those needed by automatically generated scripts. It also provides ...@@ -151,9 +149,9 @@ care of those needed by automatically generated scripts. It also provides
mechanisms to handle dependencies that are not in PyPI. For more advanced use, mechanisms to handle dependencies that are not in PyPI. For more advanced use,
see :ref:`dependency_management` see :ref:`dependency_management`
Including Data Files Including Data Files
==================== ====================
The distutils have traditionally allowed installation of "data files", which The distutils have traditionally allowed installation of "data files", which
are placed in a platform-specific location. Setuptools offers three ways to are placed in a platform-specific location. Setuptools offers three ways to
specify data files to be included in your packages. For the simpliest use, you specify data files to be included in your packages. For the simpliest use, you
...@@ -166,5 +164,27 @@ can simply use the ``include_package_data`` keyword: ...@@ -166,5 +164,27 @@ can simply use the ``include_package_data`` keyword:
This tells setuptools to install any data files it finds in your packages. This tells setuptools to install any data files it finds in your packages.
The data files must be specified via the distutils' ``MANIFEST.in`` file. The data files must be specified via the distutils' ``MANIFEST.in`` file.
For more details, see :ref:`datafiles` For more details, see :ref:`datafiles`
Uploading your package to PyPI
==============================
After generating the distribution files, next step would be to upload your
distribution so others can use it. This functionality is provided by
``twine <https://pypi.org/project/twine/>`` and we will only demonstrate the
basic use here.
Transitioning from ``setup.py`` to ``setup.cfg``
==================================================
To avoid executing arbitary scripts and boilerplate code, we are transitioning
into a full-fledged ``setup.cfg`` to declare your package information instead
of running ``setup()``. This inevitably brings challenges due to a different
syntax. Here we provide a quick guide to understanding how ``setup.cfg`` is
parsed by ``setuptool`` to ease the pain of transition.
Resources on Python packaging
=============================
Packaging in Python is hard. Here we provide a list of links for those that
want to learn more.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment