Skip to content

Commit ea3fd2f

Browse files
HenrZupatricklnzreneSchm
authored
1110 Migrate Python packages to use pyproject.toml for builds (#1409)
- Replace setuptools `setup.py` with PEP 621 `pyproject.toml` across all Python subpackages. - Move python tests outside of the subpackage directories to avoid import errors. - Add a reusable lint helper for packages that used a custom pylint command. - Update CI build/test actions. Co-authored-by: patricklnz <patrick.lenz01@icloud.com> Co-authored-by: reneSchm <49305466+reneSchm@users.noreply.github.com>
1 parent b63776a commit ea3fd2f

File tree

106 files changed

+563
-528
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+563
-528
lines changed

.github/actions/build-py/action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ runs:
1919
shell: bash
2020
run: |
2121
cd pycode/memilio-${{ inputs.package }}/
22-
/opt/python/cp38-cp38/bin/python -m pip install scikit-build
22+
/opt/python/cp38-cp38/bin/python -m pip install --upgrade pip setuptools wheel
23+
/opt/python/cp38-cp38/bin/python -m pip install scikit-build scikit-build-core
2324
/opt/python/cp38-cp38/bin/python -m build --no-isolation --wheel
24-
/opt/python/cp311-cp311/bin/python -m pip install scikit-build
25+
/opt/python/cp311-cp311/bin/python -m pip install --upgrade pip setuptools wheel
26+
/opt/python/cp311-cp311/bin/python -m pip install scikit-build scikit-build-core
2527
/opt/python/cp311-cp311/bin/python -m build --no-isolation --wheel
2628
# Exclude memilio-generation, because its a pure python package, cmake is only used in the build process to retrieve data from cpp
2729
if [[ -f "CMakeLists.txt" ]] && [ "${{ inputs.package }}" != "generation" ]; then

.github/actions/test-py/action.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,20 @@ runs:
5050
shell: bash
5151
run: |
5252
export PYTHON_VERSION_NO_DOT=$(echo "${{ inputs.version }}" | sed 's/\.//g')
53-
for pkg in `ls pycode/wheelhouse/*cp$PYTHON_VERSION_NO_DOT*.whl`; do python -m pip install $pkg; done # packages that contain native extensions are version specific
54-
for pkg in `ls pycode/wheelhouse/*py3*.whl`; do python -m pip install $pkg; done # pure python packages are not version specific
55-
pip install -r pycode/memilio-${{ inputs.package }}/requirements-dev.txt
53+
shopt -s nullglob
54+
for pkg in pycode/wheelhouse/*cp$PYTHON_VERSION_NO_DOT*.whl; do python -m pip install "$pkg"; done # packages that contain native extensions are version specific
55+
for pkg in pycode/wheelhouse/*py3*.whl; do python -m pip install "$pkg"; done # pure python packages are not version specific
56+
python -m pip install --upgrade-strategy only-if-needed --prefer-binary --find-links pycode/wheelhouse "memilio-${{ inputs.package }}[dev]"
5657
- name: Run unit tests
5758
shell: bash
5859
run: |
59-
cd pycode/memilio-${{inputs.package}}/memilio/${{inputs.package}}_test
60+
cd pycode/memilio-${{inputs.package}}/tests
6061
if [[ "${{ inputs.coverage }}" == "ON" ]]; then
6162
python -W ignore::DeprecationWarning -m coverage run --include=**/site-packages/memilio/* -m unittest
6263
python -m coverage report
6364
python -m coverage xml -o coverage_python.xml
6465
python -m coverage html -d coverage_python
65-
cp -r coverage_python ../../../../
66+
cp -r coverage_python ../../../
6667
else
6768
python -m unittest
6869
fi

.github/actions/test-pylint/action.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,29 @@ runs:
1313
sudo apt-get -qq update
1414
sudo apt-get -qq -y install python3-pip gnupg
1515
python -m pip install --upgrade pip
16+
# Pylint runs against the prebuilt wheels in pycode/wheelhouse/*cp311*.
17+
# So, use current latest supported Python version.
18+
- name: Set up Python 3.11
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.11"
1622
- name: Download Python Wheels
1723
uses: actions/download-artifact@v4
1824
with:
1925
name: python-wheels-${{ inputs.package }}
26+
path: pycode/wheelhouse
2027
- name: Install Python Wheels
2128
shell: bash
2229
run: |
23-
for pkg in `ls pycode/wheelhouse/*cp311*.whl`; do python -m pip install $pkg; done # packages that contain native extensions are version specific
24-
for pkg in `ls pycode/wheelhouse/*py3*.whl`; do python -m pip install $pkg; done # pure python packages are not version specific
25-
pip install -r pycode/memilio-${{ inputs.package }}/requirements-dev.txt
30+
shopt -s nullglob
31+
for pkg in pycode/wheelhouse/*cp311*.whl; do python -m pip install "$pkg"; done # packages that contain native extensions are version specific
32+
for pkg in pycode/wheelhouse/*py3*.whl; do python -m pip install "$pkg"; done # pure python packages are not version specific
33+
python -m pip install --upgrade-strategy only-if-needed --prefer-binary --find-links pycode/wheelhouse "memilio-${{ inputs.package }}[dev]"
2634
- name: Run pylint
2735
shell: bash
2836
run: |
29-
cd pycode/memilio-${{ inputs.package }}
30-
mkdir -p build_pylint
31-
python setup.py pylint
32-
pylint-json2html -f jsonextended -o build_pylint/pylint.html < build_pylint/pylint_extended.json
37+
python pycode/run_pylint.py --package-dir memilio-${{ inputs.package }}
38+
pylint-json2html -f jsonextended -o pycode/memilio-${{ inputs.package }}/build_pylint/pylint.html < pycode/memilio-${{ inputs.package }}/build_pylint/pylint_extended.json
3339
- name: Upload Pylint Report
3440
uses: actions/upload-artifact@v4
3541
with:

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build:
1111
jobs:
1212
install:
1313
- pip install --exists-action=w --no-cache-dir -r docs/requirements-build.txt
14-
- pip install --exists-action=w --no-cache-dir -r docs/requirements.txt --no-build-isolation
14+
- pip install --exists-action=w --no-cache-dir -r docs/requirements.txt
1515

1616
sphinx:
1717
configuration: docs/source/conf.py

cpp/thirdparty/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if(MEMILIO_USE_BUNDLED_SPDLOG)
3737

3838
if(NOT spdlog_POPULATED)
3939
FetchContent_Populate(spdlog)
40+
4041
add_subdirectory(${spdlog_SOURCE_DIR} ${spdlog_BINARY_DIR} EXCLUDE_FROM_ALL)
4142
endif()
4243

@@ -198,6 +199,7 @@ else()
198199
endif()
199200

200201
find_package(sbml ${MEMILIO_SBML_VERSION} CONFIG)
202+
201203
if(sbml_FOUND)
202204
set(MEMILIO_HAS_SBML ON)
203205
message(STATUS "Found libSBML: ${libsbml_INCLUDE_DIRS}")

docs/source/python/m-epidata.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ When you start creating a new script:
8585

8686
When you add a new script
8787

88-
- Add an executable to the setup.py in "pycode/memilio-epidata".
88+
- Add a console script entry to the ``pycode/memilio-epidata/pyproject.toml`` file.
8989
- Add it to the cli_dict in getDataIntoPandasDataFrame.py.
9090
- Add a meaningful key for the new script.
9191
- for the dict value add a list in the form [comment to print when script is started, list of used parser arguments (optional)].

docs/source/python/m-generation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ For a successful build, the development libraries for Python need to be installe
3030
.. warning::
3131
Generation currently requires specifically version ``18.1.1`` of `libclang.so`, since the function ``create_ast`` in `ast.py <https://github.com/SciCompMod/memilio/blob/main/pycode/memilio-generation/memilio/generation/ast.py>`_ generates the abstract syntax tree using `clang-18`. Different versions may lead to unsupported abstractions.
3232

33-
If you want to try a different version, set your `libclang` version under ``install_requires`` in the `setup.py <https://github.com/SciCompMod/memilio/blob/main/pycode/memilio-generation/setup.py>`_ and change the clang command in ``create_ast`` in `ast.py <https://github.com/SciCompMod/memilio/blob/main/pycode/memilio-generation/memilio/generation/ast.py>`_.
33+
If you want to try a different version, set your `libclang` version under ``dependencies`` in the `pyproject.toml <https://github.com/SciCompMod/memilio/blob/main/pycode/memilio-generation/pyproject.toml>`_ and change the clang command in ``create_ast`` in `ast.py <https://github.com/SciCompMod/memilio/blob/main/pycode/memilio-generation/memilio/generation/ast.py>`_.
3434

3535
Usage
3636
-----

docs/source/python/python_packages.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,21 @@ Please see the individual package documentation for more details on the function
111111
Installation
112112
------------
113113

114-
Each package provides a `setup.py` script that installs the package and its dependencies.
114+
Each package provides a ``pyproject.toml`` that installs the package and its dependencies with pip.
115115
The dependencies of the individual packages are denoted in their documentation.
116-
The installation can be run with the following command (from the directory containing the `setup.py`)
116+
The installation can be run with the following command (from the directory containing the ``pyproject.toml`` file)
117117

118118
.. code-block:: console
119119
120-
pip install .
120+
python -m pip install .
121121
122122
This copies the package and the required dependencies to your site-packages.
123123

124124
For development of code use this command instead
125125

126126
.. code-block:: console
127127
128-
pip install -e .[dev]
128+
python -m pip install -e .[dev]
129129
130130
This command allows you to work on the code without having to reinstall the package after a change. It also installs all additional dependencies required for development and maintenance.
131131

@@ -157,7 +157,7 @@ To get the coverage report do in the package folder
157157
158158
Coverage report for actual master:
159159

160-
`Coverage Report <https://scicompmod.github.io/memilio/coverage/python/>`_
160+
`Coverage Report <https://scicompmod.github.io/memilio/coverage/python/>`__
161161

162162
Inspection via pylint
163163
---------------------
@@ -171,9 +171,12 @@ Run pylint with the commands in the package folder
171171

172172
.. code-block:: console
173173
174-
python setup.py pylint
174+
python ../run_pylint.py
175175
pylint-json2html -f jsonextended -o build_pylint/pylint.html < build_pylint/pylint_extended.json
176176
177+
From the repository root you can also target a package explicitly, for example
178+
``python pycode/run_pylint.py --package-dir memilio-plot``.
179+
177180
Pylint report for actual master:
178181

179-
`Pylint Report <https://dlr-sc.github.io/memilio/pylint/>`_
182+
`Pylint Report <https://dlr-sc.github.io/memilio/pylint/>`__

pycode/memilio-epidata/README.rst

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ A more detailed description of the sources can be found in the `epidata subfolde
2323
Installation
2424
------------
2525

26-
Use the provided ``setup.py`` script to install the package and its dependencies.
26+
This project uses ``pyproject.toml`` to install the package and its dependencies.
2727

28-
To install the package, use (from the directory that contains ``setup.py``)
28+
To install the package, run (from the directory that contains ``pyproject.toml``)
2929

3030
.. code:: sh
3131
@@ -84,11 +84,21 @@ The following packages are used by the tests:
8484

8585
See Installation on how to install all these dependencies automatically.
8686

87-
To run the tests make
88-
89-
.. code:: sh
87+
To run the tests, make sure the package is installed, and you are in the source directory, then run:
9088

89+
```bash
90+
cd tests
9191
python -m unittest
92+
```
93+
94+
This works with both normal (`pip install .`) and editable (`pip install -e .`) installations.
95+
96+
Alternatively, you can run the tests from outside the source directory:
97+
98+
```bash
99+
cd /path/to/another/directory
100+
python -m unittest discover -s /path/to/memilio/pycode/memilio-epidata/tests
101+
```
92102

93103
To get the coverage report do
94104

@@ -116,7 +126,7 @@ Run pylint with the commands
116126

117127
.. code:: sh
118128
119-
python setup.py pylint
129+
python ../run_pylint.py
120130
pylint-json2html -f jsonextended -o build_pylint/pylint.html < build_pylint/pylint_extended.json
121131
122132
Pylint report for actual master:
@@ -163,7 +173,7 @@ When you start creating a new script:
163173

164174
When you add a new script
165175

166-
- add a executable to the setup.py in "pycode/memilio-epidata"
176+
- add a script entry to ``pyproject.toml`` in "pycode/memilio-epidata"
167177
- add it to the cli_dict in getDataIntoPandasDataFrame.py
168178
- add a meaningfull key for the new script
169179
- as the value add a list in the form [comment to print when script is started, list of used parser arguments (optional)]

pycode/memilio-epidata/memilio/epidata_test/__init__.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)