Skip to content

Commit 822ca74

Browse files
greschdjorgepiloto
authored andcommitted
Switch from 'flit' to 'poetry'
1 parent 65a87bb commit 822ca74

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

doc/source/library_description/packaging.rst

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,38 @@ projects. It needs to at least contain a ``[build-system]`` section, which deter
3838
how the project is built. Some commonly used packaging tools are `setuptools`_,
3939
`poetry`_, or `flit`_.
4040

41-
When writing a *library*, `flit`_ is a good default choice. For *applications*,
42-
`poetry`_ is a good default as it provides features to pin dependency versions.
43-
We use `flit`_ in the template repository and the description below.
41+
We use `poetry`_ as a default choice in the `PyAnsys template`_, for the following reasons:
42+
* it supports pinning dependency versions, which we use for testing / CI
43+
* downstream packages can still consume a loose dependency specification
44+
* it integrates with `dependabot`_ to update the pinned version
4445

45-
To use `flit`_ as a packaging tool, the ``pyproject.toml`` should contain
46+
Feel free to use any one of the packaging tools mentioned above that best suits
47+
your needs. The advantage of `flit`_ is its simplicity, while `setuptools`_ is most useful
48+
when custom build steps need to be implemented as Python code.
49+
50+
To use `poetry`_ as a packaging tool, the ``pyproject.toml`` should contain
4651

4752
.. code:: toml
4853
4954
[build-system]
50-
requires = ["flit_core >=3.2,<4"]
51-
build-backend = "flit_core.buildapi"
52-
53-
The ``[project]`` section contains metadata, and defines the project's dependencies. Refer to the
54-
`flit metadata documentation`_ for details.
55+
requires = ["poetry-core>=1.0.0"]
56+
build-backend = "poetry.core.masonry.api"
5557
56-
Flit can automatically determine the project's version from the source code.
57-
In the ``[project]`` section, add
58+
The ``[tool.poetry]`` section contains metadata, and defines the project's dependencies. Refer to the
59+
`poetry pyproject.toml documentation`_ for details.
5860

59-
.. code:: toml
61+
Since poetry cannot automatically determine a package's version, we instead specify it in the ``[tool.poetry]``
62+
section, and add code to ``__init__.py`` which obtains the version from the installation metadata:
6063

61-
dynamic = ["version"]
64+
.. code:: python
6265
63-
The version is parsed from the ``ansys/package/library/__init__.py`` file, which must
64-
contain a statement
66+
try:
67+
import importlib.metadata as importlib_metadata
68+
except ModuleNotFoundError:
69+
import importlib_metadata
6570
66-
.. code:: python
71+
__version__ = importlib_metadata.version(__name__.replace(".", "-"))
6772
68-
__version__ = "0.1.0"
6973
7074
Where supported, we aim to put all tooling-related configuration into ``pyproject.toml``.
7175
For example, it can also be used to configure the code formatter `black`_ or the static
@@ -166,7 +170,9 @@ To create a package complying with the above standards, here is the minimal cont
166170
.. _setuptools: https://setuptools.pypa.io
167171
.. _poetry: https://python-poetry.org/docs/
168172
.. _flit: https://flit.readthedocs.io
169-
.. _flit metadata documentation: https://flit.readthedocs.io/en/latest/pyproject_toml.html#new-style-metadata
173+
.. _dependabot: https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/about-dependabot-version-updates
174+
.. _PyAnsys template: https://github.com/pyansys/template
175+
.. _poetry pyproject.toml documentation: https://python-poetry.org/docs/pyproject/
170176
.. _black: https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-via-a-file
171177
.. _mypy: https://mypy.readthedocs.io/en/stable/config_file.html#the-mypy-configuration-file
172178
.. _trunk-based development: https://trunkbaseddevelopment.com/

0 commit comments

Comments
 (0)