Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
cc7186cd
Commit
cc7186cd
authored
Mar 30, 2020
by
alvyjudy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First draft for build_meta documentation
parent
578d2eca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
45 deletions
+53
-45
docs/build_meta.txt
docs/build_meta.txt
+53
-45
No files found.
docs/build_meta.txt
View file @
cc7186cd
...
@@ -5,37 +5,39 @@ Documentation to setuptools.build_meta
...
@@ -5,37 +5,39 @@ Documentation to setuptools.build_meta
What is it?
What is it?
-------------
-------------
Setuptools, or Python packaging in general, has faced many
Python packaging has come `a long way <https://www.bernat.tech/pep-517-518/>`_.
`criticism <https://www.bernat.tech/growing-pain>`_ and
`PEP517 <https://www.python.org/dev/peps/pep-0517/>`_ attempts to fix this
The traditional ``setuptools``'s way of packgaging Python modules
issue by ``get distutils-sig out of the business of being a gatekeeper for
uses a ``setup()`` function within the ``setup.py`` script. Commands such as
Python build system``.
``python setup.py bdist`` or ``python setup.py bdist_wheel`` generate a
distribution bundle and ``python setup.py install`` installs the distribution.
A quick overview on the `current state of Python packaging
This interface makes it difficult to choose other packaging tools without an
<https://www.bernat.tech/pep-517-and-python-packaging/>`_. The ``distutils``
overhaul. Additionally, the ``setup.py`` scripts hasn't been the most user
package specified the de facto standard way to bundle up your packages::
friendly tool.
setup.py
PEP517 therefore came to rescue and specified a new standard to
mypkg/__init__.py
package and distribute Python modules. Under PEP517:
And then you run ``python setup.py bdist`` and compressed ``.tar.gz`` will be
a ``pyproject.toml`` file is used to specify what program to use
available for distribution.
for generating distribution.
Following this tradition, several other enhancements have been made: ``pip``
Then, two functions provided by the program,``build_wheel(directory: str)``
was created and user can run ``pip install`` on their downloaded distribution
and ``build_sdist(directory: str)`` create the distribution bundle at the
file and it will be installed. ``wheel`` format was created to minimize the
specified ``directory``. The program is free to use its own configuration
build process for C extension. ``PyPI`` and ``twine`` then made it easier to
script or extend the ``.toml`` file.
upload and download the distribution and finally ``setuptools`` extends the
original ``distutils`` and emcompass everything else and become the standard
Lastly, ``pip install *.whl`` or ``pip install *.tar.gz`` does the actual
way for Python packaging. (check the timeline for accuracy)
installation. If ``*.whl`` is available, ``pip`` will go ahead and copy
the files into ``site-packages`` directory. If not, ``pip`` will look at
I'll skip the many downsides and complexity that came with the development
``pyproject.toml`` and decide what program to use to 'build from source'
of setuptools. PEP517 aims to solve these issues by specifying a new
(the default is ``setuptools``)
standardized way to distribute your packages which is not as compatible as
the setuptools module.
With this standard, switching between packaging tools becomes a lot easier and
in the case of ``setuptools``, ``setup.py`` becomes optional.
``build_meta.py`` therefore acts as an adaptor to the PEP517 and the existing
setuptools.
``build_meta`` is ``setuptools``'s implementation of PEP517. It provides the
two functions, ``build_wheel`` and ``build_sdist``, amongst others and uses
a ``setup.cfg`` to specify the information about the package.
How to use it?
How to use it?
-------------
-------------
...
@@ -46,21 +48,20 @@ scripts, a ``pyproject.toml`` file and a ``setup.cfg`` file.
...
@@ -46,21 +48,20 @@ scripts, a ``pyproject.toml`` file and a ``setup.cfg`` file.
~/meowpkg/
~/meowpkg/
pyproject.toml
pyproject.toml
setup.cfg
setup.cfg
src/
meowpkg/__init__.py
meowpkg/__init__.py
The pyproject.toml file is required
by PEP517 and PEP518 to specify the build
The pyproject.toml file is required
to specify the build system (i.e. what is
system (i.e. what is being used to package your scripts
). To use it with
being used to package your scripts and install from source
). To use it with
setuptools, the content would be::
setuptools, the content would be::
[build-system]
[build-system]
requires = ["setuptools", "wheel"]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build
-meta"
build-backend = "setuptools.build
_meta"
The setup.cfg is used to specify your package information (essentially
``setup.cfg`` is used to specify your package information, specified
replacing setup.py), specified on setuptools `documentation <https://
`here <https://setuptools.readthedocs.io/en/latest/setuptools.html#configuring
setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-
-setup-using-setup-cfg-files>`_ ::
using-setup-cfg-files>`_ ::
[metadata]
[metadata]
name = meowpkg
name = meowpkg
...
@@ -68,13 +69,8 @@ using-setup-cfg-files>`_ ::
...
@@ -68,13 +69,8 @@ using-setup-cfg-files>`_ ::
description = a package that meows
description = a package that meows
[options]
[options]
package_dir=
=src
packages = find:
packages = find:
[options.packages.find]
where=src
Now it's time to actually generate the distribution. PEP517 specifies two
Now it's time to actually generate the distribution. PEP517 specifies two
mandatory functions, ``build_wheel`` and ``build_sdist``, implemented in
mandatory functions, ``build_wheel`` and ``build_sdist``, implemented in
this module. Currently, it has to be done in the interpreter::
this module. Currently, it has to be done in the interpreter::
...
@@ -82,7 +78,19 @@ this module. Currently, it has to be done in the interpreter::
...
@@ -82,7 +78,19 @@ this module. Currently, it has to be done in the interpreter::
>>> import setuptools.build_meta
>>> import setuptools.build_meta
>>> setuptools.build_meta.build_wheel('wheel_dist')
>>> setuptools.build_meta.build_wheel('wheel_dist')
'meowpkg-0.0.1-py3-none-any.whl'
'meowpkg-0.0.1-py3-none-any.whl'
>>> setuptools.build_meta.build_sdist('sdist')
'meowpkg-0.0.1.tar.gz'
And now it's done! The ``.whl`` file and ``.tar.gz`` can then be distributed
And now it's done! The ``.whl`` file and ``.tar.gz`` can then be distributed
and installed!
and installed::
~/newcomputer/
meowpkg-0.0.1.whl
meowpkg-0.0.1.tar.gz
$ pip install meowpkg-0.0.1.whl
or::
$ pip install meowpkg-0.0.1.tar.gz
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment