-
Notifications
You must be signed in to change notification settings - Fork 8
Better Package Style layout #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
91c4676
New Package Style layout
jorgepiloto 45899c0
Apply suggestions from code review
jorgepiloto 3c220c1
Enable graphviz and numrefs
jorgepiloto 129356d
WIP: structure
jorgepiloto 1662c1d
Unify Python library diagrams
jorgepiloto 9ef8773
Fix library typo
jorgepiloto bcd5abd
Complete diagram
jorgepiloto 4678199
Document doc/ dir structure
jorgepiloto d5980e8
Document src/ dir structure
jorgepiloto 5fb0a6b
Document tests/ dir structure
jorgepiloto 1c3e711
Document LICENSE file
jorgepiloto 0005090
Improve doc/ directory explanations
jorgepiloto bbc5928
Document Naming Convention section
jorgepiloto 7fdbc90
Apply suggestions from code review
jorgepiloto 8a85c7b
Document README.rst section
jorgepiloto a59965f
Document pyproject.toml and setup.py sections
jorgepiloto a79e4e0
Add build-systems.rst section
jorgepiloto 036fcf2
Add sphinx-tabs requiremnt
jorgepiloto a8fda14
Fix setuptools link
jorgepiloto af98b56
Apply code suggestions
jorgepiloto 2200a58
Add build-systems.rst diagrams
jorgepiloto 3cb9fb3
Add build system section
jorgepiloto 4ce03e6
Apply suggestions from code review
jorgepiloto ce83137
Enable Sphinx autolabeling
jorgepiloto 340d144
Fix cross references
jorgepiloto 6f6e17f
Fix setuptools tab
jorgepiloto 92822fd
Rename diagrams -> diag
jorgepiloto 371c7ea
Fix sphinx-tabs version
jorgepiloto 854de95
Apply style
jorgepiloto ad59e6d
Rename resources -> code
jorgepiloto 14b2560
Fix cross references
jorgepiloto 8b1e5ba
Ignore duplicated autosectionlabel references
jorgepiloto 5757697
Add diagrams dependencies in CI deps
jorgepiloto 8155ca8
Apply suggestions from code review
jorgepiloto eb4532f
Apply suggestions from code review
jorgepiloto 2b4fafa
Apply suggestions from code review
jorgepiloto deb6814
Apply suggestions from code review
jorgepiloto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
.. _ref_build_system: | ||
|
||
############ | ||
Build System | ||
############ | ||
|
||
The build system is a fundamental tool for packaging Python | ||
libraries. It generates distribution files that can be shared with | ||
users and developers. | ||
|
||
|
||
Artifacts | ||
========= | ||
|
||
The build-system allows maintainers to generate artifacts for their Python | ||
jorgepiloto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
libraries. Here, `artifacts` refers to both wheel and source files: | ||
|
||
- ``Wheel files`` have the ``*.whl`` file extension. | ||
- ``Source files`` have the ``*.tar.gz`` or ``*.zip`` extension. | ||
|
||
These are the files to upload to `PyPI`_ when releasing a new version of a | ||
PyAnsys project. | ||
|
||
.. warning:: | ||
|
||
Not all files are included by default in the source distribution. A | ||
`MANIFEST.in`_ is required at the root of the project to specify additional | ||
files. | ||
|
||
|
||
The interaction between the maintainer and the build-system is performed using a | ||
jorgepiloto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
build-system tool. This tool provides a frontend and a backend. The maintainers | ||
trigger the frontend, which then calls the backend. The backend then reads the | ||
project directory and generates the artifacts, as :numref:`build system diag`: | ||
jorgepiloto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. include:: diag/build_system_diag.rst | ||
|
||
|
||
PEP 517 and PEP 518 | ||
=================== | ||
|
||
For a long time, the ``setup.py`` file was the only way of specifying the | ||
project structure, metadata, and installation workflow that `pip`_ was to follow. | ||
However, having to execute a Python file when installing a Python package | ||
introduced the following problems: | ||
|
||
- It was not possible to know which dependencies required the ``setup.py`` file | ||
to be properly executed. | ||
|
||
- The default Python package installer, `pip`_, expected `setuptools`_ to be the | ||
default build system tool, excluding others like `flit`_ and `poetry`_. | ||
|
||
These problems led to the acceptance of `PEP 517`_ and `PEP 518`_. | ||
|
||
|
||
PEP 517 | ||
------- | ||
|
||
`PEP 517`_ allows Python developers to specify the build-backend tool for | ||
generating artifacts. As seen in the :numref:`build system diag` figure, these | ||
are the most popular backends: | ||
jorgepiloto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- `Setuptools`_ , while very popular, lacks build time dependency declaration | ||
and is difficult to extend. | ||
jorgepiloto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- `Flit`_ is a lightweight build system tool for Python. | ||
- `Poetry`_ focuses on dependency management and environment isolation. | ||
|
||
`PEP 517` introduced the ``build-backend`` key inside the | ||
``[build-system]`` table in the ``pyproject.toml``. | ||
|
||
|
||
PEP 518 | ||
------- | ||
|
||
In addition to the ``setup.py`` file, a new project file named | ||
``pyproject.toml`` file was specified by the `PEP 518`_. The main goal of this | ||
file was to specify build time dependencies. However, some build system tools | ||
like `flit`_ or `poetry`_ are able to specify all the project metadata inside | ||
the ``pyproject.toml`` file and eliminate the usage of the ``setup.py``. | ||
jorgepiloto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
To specify the build time requirements, the ``[build-system]`` table must be | ||
declared in the ``pyproject.toml`` file. Within it, the ``requires`` key is | ||
assigned to a list of strings, which are the build time | ||
requirements. | ||
|
||
The combination of `PEP 517`_ and `PEP 518`_ leads to the following syntax in a | ||
``pyproject.toml`` file: | ||
|
||
.. code:: toml | ||
|
||
[build-system] | ||
requires = ["flit"] # Defined by PEP 518 | ||
build-backend = "flit_core.api" # Defined by PEP 517 | ||
|
||
|
||
Build-backend Tools | ||
jorgepiloto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
=================== | ||
|
||
This section lists some of the most popular build systems in the | ||
Python ecosystem. Although all of them achieve the same goal, there are a few | ||
differences regarding their capabilities and the way of specifying project | ||
metadata. | ||
|
||
.. TODO: Include links to each build system allowed metadata fields | ||
|
||
Setuptools | ||
---------- | ||
|
||
`Setuptools`_ has been a part of the Python ecosystem for a long time. Unless | ||
you require high control over your project's installation steps, you should use | ||
`flit`_ or `poetry`_. | ||
|
||
If you do not need a dynamic installation process, you can consider using a | ||
``setup.cfg`` file. However, the ``setup.py`` file is still required. The ``setup.cfg`` file | ||
should have a call to the ``setup()`` function to act as the entry point of the | ||
build backend system. | ||
|
||
All of these `setuptools metadata fields`_ are valid and must be | ||
specified either in the ``setup.py`` or ``setup.cfg`` file. | ||
|
||
|
||
Flit | ||
---- | ||
|
||
Flit is a modern and lightweight build system that requires developers | ||
to manage virtual environments on their own. Developers must: | ||
|
||
* Create a virtual environment and activate it. | ||
* Install the package in editable mode. | ||
|
||
Flit is the default tool for creating a new ``pyansys`` project when using the | ||
`ansys-templates tool`_. | ||
|
||
The ``[project]`` section specifies the project's metadata and required | ||
dependencies. For more information, see `flit pyproject.toml | ||
guidelines`_. | ||
|
||
|
||
Poetry | ||
------ | ||
|
||
Because of its ``poetry.lock`` file, Poetry provides strong dependency pinning. When | ||
installing a package, poetry creates a virtual environment, thus ensuring an isolated | ||
package development environment. | ||
|
||
Nevertheless, it is possible to make Poetry ignore the ``poetry.lock`` file with: | ||
|
||
.. code:: bash | ||
|
||
poetry config virtualenvs.create false --local | ||
|
||
Using `poetry`_ is popular because it: | ||
|
||
* Supports pinning dependency versions via a ``poetry.lock`` file that can be | ||
used for testing and CI | ||
* Allows downstream packages to still consume a loose dependency specification | ||
* Integrates with `dependabot`_ to update the pinned version | ||
|
||
The ``[tool.poetry]`` section contains metadata and defines project | ||
dependencies. For more information, see `poetry pyproject.toml documentation`_. | ||
|
||
|
||
.. _MANIFEST.in: https://packaging.python.org/en/latest/guides/using-manifest-in/ | ||
.. _PyPI: https://pypi.org/ | ||
.. _pip: | ||
.. _flit: https://flit.pypa.io/en/latest/ | ||
.. _poetry: https://python-poetry.org/ | ||
.. _poetry pyproject.toml documentation: https://python-poetry.org/docs/pyproject/ | ||
.. _setuptools: https://pypi.org/project/setuptools/ | ||
.. _setuptools metadata fields: https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#declarative-config | ||
.. _flit pyproject.toml guidelines: https://flit.readthedocs.io/en/latest/pyproject_toml.html | ||
.. _dependabot: https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/about-dependabot-version-updates | ||
.. _ansys-templates tool: https://github.com/pyansys/ansys-templates |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.. code:: text | ||
|
||
MIT License | ||
|
||
Copyright (c) <YEAR> ANSYS, Inc. All rights reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the “Software”), to | ||
deal in the Software without restriction, including without limitation the | ||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
sell copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
IN THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.. tabs:: | ||
|
||
.. tab:: setuptools | ||
|
||
.. include:: code/pyproject_setuptools_code.rst | ||
|
||
.. tab:: flit | ||
|
||
.. include:: code/pyproject_flit_code.rst | ||
|
||
.. tab:: poetry | ||
|
||
.. include:: code/pyproject_poetry_code.rst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
.. code:: toml | ||
|
||
[build-system] | ||
requires = ["flit_core >=3.2,<4"] | ||
build-backend = "flit_core.buildapi" | ||
|
||
[project] | ||
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections | ||
name = "Py<Product> <Library>" | ||
version = "<version>" | ||
description = "A Python wrapper for Ansys <Product> <Library>" | ||
readme = "README.rst" | ||
requires-python = ">=3.<minor>" | ||
license = {file = "LICENSE"} | ||
authors = [ | ||
{name = "ANSYS, Inc.", email = "[email protected]"}, | ||
] | ||
maintainers = [ | ||
{name = "PyAnsys developers", email = "[email protected]"}, | ||
] | ||
|
||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
] | ||
dependencies = [ | ||
"importlib-metadata >=4.0", | ||
] | ||
|
||
[tool.flit.module] | ||
name = "ansys.<product>.<library>" | ||
|
||
[project.urls] | ||
Source = "https://github.com/pyansys/py<product>-<library>" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.