@@ -38,34 +38,38 @@ projects. It needs to at least contain a ``[build-system]`` section, which deter
38
38
how the project is built. Some commonly used packaging tools are `setuptools `_,
39
39
`poetry `_, or `flit `_.
40
40
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
44
45
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
46
51
47
52
.. code :: toml
48
53
49
54
[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"
55
57
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.
58
60
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:
60
63
61
- dynamic = ["version"]
64
+ .. code :: python
62
65
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
65
70
66
- .. code :: python
71
+ __version__ = importlib_metadata.version( __name__ .replace( " . " , " - " ))
67
72
68
- __version__ = " 0.1.0"
69
73
70
74
Where supported, we aim to put all tooling-related configuration into ``pyproject.toml ``.
71
75
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
166
170
.. _setuptools : https://setuptools.pypa.io
167
171
.. _poetry : https://python-poetry.org/docs/
168
172
.. _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/
170
176
.. _black : https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-via-a-file
171
177
.. _mypy : https://mypy.readthedocs.io/en/stable/config_file.html#the-mypy-configuration-file
172
178
.. _trunk-based development : https://trunkbaseddevelopment.com/
0 commit comments