Skip to content

Commit 8f69ee5

Browse files
committed
Modernize Pyomo build infrastructure to use pyproject.toml
1 parent 5bd2849 commit 8f69ee5

File tree

6 files changed

+135
-101
lines changed

6 files changed

+135
-101
lines changed

.github/workflows/release_wheel_creation.yml

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,8 @@ jobs:
5959

6060
steps:
6161
- uses: actions/checkout@v4
62-
- name: Create pyproject.toml
63-
run: |
64-
# Per the cibuildwheel documentation, you can technically use
65-
# CIBW_BEFORE_BUILD to do these steps; however, as of the newest
66-
# version (2.21.3) this feature does not work. This is a hack
67-
# to make cibuildwheel recognize our pre-build requirements
68-
echo -e '[build-system]\n\nrequires = [ "setuptools", "wheel", "cython", "pybind11" ]' > $GITHUB_WORKSPACE/pyproject.toml
69-
cat $GITHUB_WORKSPACE/pyproject.toml
70-
ls -la $GITHUB_WORKSPACE
7162
- name: Build wheels
72-
uses: pypa/cibuildwheel@v2.21.3
63+
uses: pypa/cibuildwheel@main
7364
with:
7465
output-dir: dist
7566
env:
@@ -118,17 +109,8 @@ jobs:
118109
uses: docker/setup-qemu-action@v3
119110
with:
120111
platforms: all
121-
- name: Create pyproject.toml
122-
run: |
123-
# Per the cibuildwheel documentation, you can technically use
124-
# CIBW_BEFORE_BUILD to do these steps; however, as of the newest
125-
# version (2.21.3) this feature does not work. This is a hack
126-
# to make cibuildwheel recognize our pre-build requirements
127-
echo -e '[build-system]\n\nrequires = [ "setuptools", "wheel", "cython", "pybind11" ]' > $GITHUB_WORKSPACE/pyproject.toml
128-
cat $GITHUB_WORKSPACE/pyproject.toml
129-
ls -la $GITHUB_WORKSPACE
130112
- name: Build wheels
131-
uses: pypa/cibuildwheel@v2.21.3
113+
uses: pypa/cibuildwheel@main
132114
with:
133115
output-dir: dist
134116
env:
@@ -158,10 +140,11 @@ jobs:
158140
- name: Install dependencies
159141
run: |
160142
python -m pip install --upgrade pip
161-
pip install twine wheel setuptools pybind11
143+
pip install build twine wheel setuptools pybind11
162144
- name: Build pure python wheel
163145
run: |
164-
python setup.py --without-cython sdist --format=gztar bdist_wheel
146+
export PYOMO_SETUP_ARGS=--without-cython
147+
python -m build --wheel --outdir dist --config-setting="--build-option=--without-cython"
165148
- name: Upload artifact
166149
uses: actions/upload-artifact@v4
167150
with:
@@ -189,10 +172,11 @@ jobs:
189172
- name: Install dependencies
190173
run: |
191174
python -m pip install --upgrade pip
192-
pip install twine wheel setuptools pybind11
175+
pip install build twine wheel 'setuptools>=65' pybind11
193176
- name: Build generic tarball
194177
run: |
195-
python setup.py --without-cython sdist --format=gztar
178+
export PYOMO_SETUP_ARGS=--without-cython
179+
python -m build --sdist --outdir dist --config-setting="--build-option=--without-cython"
196180
- name: Upload artifact
197181
uses: actions/upload-artifact@v4
198182
with:

.github/workflows/test_branches.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ jobs:
118118
- os: ubuntu-latest
119119
python: 3.12
120120
other: /cython
121-
setup_options: --with-cython
122121
TARGET: linux
123122
PYENV: pip
124123
PACKAGES: cython
@@ -654,14 +653,19 @@ jobs:
654653
655654
- name: Install Pyomo
656655
run: |
656+
# Turn on cython through env vars
657+
if [[ "${{ matrix.other }}" == *cython* ]]; then
658+
echo "Cython requested; turning on cythonization options in environment"
659+
export PYOMO_SETUP_ARGS=--with-cython
660+
fi
657661
echo ""
658662
echo "Clone Pyomo-model-libraries..."
659663
URL=https://github.com/Pyomo/pyomo-model-libraries.git
660664
git clone -b ${SRC_REF##*/} $URL || git clone -b main $URL
661665
echo ""
662666
echo "Install Pyomo..."
663667
echo ""
664-
$PYTHON_EXE setup.py develop ${{matrix.setup_options}}
668+
$PYTHON_EXE -m pip install -e .
665669
echo ""
666670
echo "Set custom PYOMO_CONFIG_DIR"
667671
echo ""
@@ -790,7 +794,7 @@ jobs:
790794
echo ""
791795
echo "Install Pyomo..."
792796
echo ""
793-
python setup.py develop
797+
python -m pip install -e .
794798
echo ""
795799
echo "Set custom PYOMO_CONFIG_DIR"
796800
echo ""
@@ -868,13 +872,18 @@ jobs:
868872
869873
- name: Install Pyomo
870874
run: |
875+
# Turn on cython through env vars
876+
if [[ "${{ matrix.other }}" == *cython* ]]; then
877+
echo "Cython requested; turning on cythonization options in environment"
878+
export PYOMO_SETUP_ARGS=--with-cython
879+
fi
871880
echo ""
872881
echo "Clone Pyomo-model-libraries..."
873882
git clone https://github.com/Pyomo/pyomo-model-libraries.git
874883
echo ""
875884
echo "Install Pyomo..."
876885
echo ""
877-
$PYTHON_EXE setup.py develop ${{matrix.setup_options}}
886+
$PYTHON_EXE -m pip install -e .
878887
echo ""
879888
echo "Set custom PYOMO_CONFIG_DIR"
880889
echo ""

.github/workflows/test_pr_and_main.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ jobs:
127127
- os: ubuntu-latest
128128
python: 3.12
129129
other: /cython
130-
setup_options: --with-cython
131130
TARGET: linux
132131
PYENV: pip
133132
PACKAGES: cython
@@ -706,14 +705,19 @@ jobs:
706705
707706
- name: Install Pyomo
708707
run: |
708+
# Turn on cython through env vars
709+
if [[ "${{ matrix.other }}" == *cython* ]]; then
710+
echo "Cython requested; turning on cythonization options in environment"
711+
export PYOMO_SETUP_ARGS=--with-cython
712+
fi
709713
echo ""
710714
echo "Clone Pyomo-model-libraries..."
711715
URL=https://github.com/Pyomo/pyomo-model-libraries.git
712716
git clone -b ${SRC_REF##*/} $URL || git clone -b main $URL
713717
echo ""
714718
echo "Install Pyomo..."
715719
echo ""
716-
$PYTHON_EXE setup.py develop ${{matrix.setup_options}}
720+
$PYTHON_EXE -m pip install -e .
717721
echo ""
718722
echo "Set custom PYOMO_CONFIG_DIR"
719723
echo ""
@@ -843,7 +847,7 @@ jobs:
843847
echo ""
844848
echo "Install Pyomo..."
845849
echo ""
846-
python setup.py develop
850+
python -m pip install -e .
847851
echo ""
848852
echo "Set custom PYOMO_CONFIG_DIR"
849853
echo ""
@@ -921,13 +925,18 @@ jobs:
921925
922926
- name: Install Pyomo
923927
run: |
928+
# Turn on cython through env vars
929+
if [[ "${{ matrix.other }}" == *cython* ]]; then
930+
echo "Cython requested; turning on cythonization options in environment"
931+
export PYOMO_SETUP_ARGS=--with-cython
932+
fi
924933
echo ""
925934
echo "Clone Pyomo-model-libraries..."
926935
git clone https://github.com/Pyomo/pyomo-model-libraries.git
927936
echo ""
928937
echo "Install Pyomo..."
929938
echo ""
930-
$PYTHON_EXE setup.py develop ${{matrix.setup_options}}
939+
$PYTHON_EXE -m pip install -e .
931940
echo ""
932941
echo "Set custom PYOMO_CONFIG_DIR"
933942
echo ""

pyproject.toml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
[build-system]
2+
requires = [
3+
"setuptools>=65",
4+
"wheel",
5+
# leave Cython as an optional, runtime‑selectable extra
6+
# setuptools will still import it from setup.py when requested
7+
"cython",
8+
"pybind11",
9+
]
10+
build-backend = "setuptools.build_meta"
11+
12+
# project metadata
13+
14+
[project]
15+
name = "pyomo"
16+
description = "The Pyomo optimization modeling framework"
17+
readme = "README.md"
18+
license = { file = "LICENSE.md" }
19+
authors = [{name = "Pyomo Development Team", email = "[email protected]"}]
20+
requires-python = ">=3.9"
21+
keywords=['optimization']
22+
classifiers=[
23+
'Development Status :: 5 - Production/Stable',
24+
'Intended Audience :: End Users/Desktop',
25+
'Intended Audience :: Science/Research',
26+
'License :: OSI Approved :: BSD License',
27+
'Natural Language :: English',
28+
'Operating System :: MacOS',
29+
'Operating System :: Microsoft :: Windows',
30+
'Operating System :: Unix',
31+
'Programming Language :: Python',
32+
'Programming Language :: Python :: 3',
33+
'Programming Language :: Python :: 3.9',
34+
'Programming Language :: Python :: 3.10',
35+
'Programming Language :: Python :: 3.11',
36+
'Programming Language :: Python :: 3.12',
37+
'Programming Language :: Python :: 3.13',
38+
'Programming Language :: Python :: Implementation :: CPython',
39+
'Programming Language :: Python :: Implementation :: PyPy',
40+
'Topic :: Scientific/Engineering :: Mathematics',
41+
'Topic :: Software Development :: Libraries :: Python Modules',
42+
]
43+
44+
# All fields that are generated in setup.py must be declared dynamic
45+
dynamic = [
46+
"version",
47+
"dependencies",
48+
"optional-dependencies",
49+
]
50+
51+
[project.urls]
52+
Homepage = "https://www.pyomo.org"
53+
Documentation = "https://pyomo.readthedocs.io/en/stable/"
54+
Source = "https://github.com/Pyomo/pyomo"
55+
56+
57+
[project.scripts]
58+
pyomo = "pyomo.scripting.pyomo_main:main_console_script"
59+
60+
[project.entry-points."pyomo.command"]
61+
"pyomo.help" = "pyomo.scripting.driver_help"
62+
"pyomo.viewer" = "pyomo.contrib.viewer.pyomo_viewer"
63+
64+
[tool.setuptools.dynamic]
65+
version = {attr = "pyomo.version.info.__version__"}
66+
67+
# pytest configuration (moved from setup.cfg)
68+
69+
[tool.pytest.ini_options]
70+
filterwarnings = ["ignore::RuntimeWarning"]
71+
junit_family = "xunit2"
72+
markers = [
73+
"default: mark a test that should always run by default",
74+
"expensive: marks tests as expensive",
75+
"mpi: marks tests that require MPI",
76+
"neos: marks tests that require NEOS server connections",
77+
"importtest: marks tests that checks for warnings when importing modules",
78+
"book: marks tests from the Pyomo book",
79+
"performance: marks performance tests",
80+
"long: marks long performance tests",
81+
"short: marks short performance tests",
82+
"devel: marks developer-created performance tests",
83+
"nl: marks nl tests",
84+
"lp: marks lp tests",
85+
"gams: marks gams tests",
86+
"bar: marks bar tests",
87+
"builders: tests that should be run when testing custom (extension) builders",
88+
]

setup.cfg

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

setup.py

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import os
1717
import platform
1818
import sys
19+
from pathlib import Path
1920
from setuptools import setup, find_packages, Command
2021

2122
try:
@@ -204,47 +205,8 @@ def __ne__(self, other):
204205

205206

206207
setup_kwargs = dict(
207-
name='pyomo',
208-
#
209-
# Note: the release number is set in pyomo/version/info.py
210-
#
211208
cmdclass={'dependencies': DependenciesCommand},
212209
version=get_version(),
213-
maintainer='Pyomo Developer Team',
214-
maintainer_email='[email protected]',
215-
url='http://pyomo.org',
216-
project_urls={
217-
'Documentation': 'https://pyomo.readthedocs.io/',
218-
'Source': 'https://github.com/Pyomo/pyomo',
219-
},
220-
license='BSD',
221-
platforms=["any"],
222-
description='Pyomo: Python Optimization Modeling Objects',
223-
long_description=read('README.md'),
224-
long_description_content_type='text/markdown',
225-
keywords=['optimization'],
226-
classifiers=[
227-
'Development Status :: 5 - Production/Stable',
228-
'Intended Audience :: End Users/Desktop',
229-
'Intended Audience :: Science/Research',
230-
'License :: OSI Approved :: BSD License',
231-
'Natural Language :: English',
232-
'Operating System :: MacOS',
233-
'Operating System :: Microsoft :: Windows',
234-
'Operating System :: Unix',
235-
'Programming Language :: Python',
236-
'Programming Language :: Python :: 3',
237-
'Programming Language :: Python :: 3.9',
238-
'Programming Language :: Python :: 3.10',
239-
'Programming Language :: Python :: 3.11',
240-
'Programming Language :: Python :: 3.12',
241-
'Programming Language :: Python :: 3.13',
242-
'Programming Language :: Python :: Implementation :: CPython',
243-
'Programming Language :: Python :: Implementation :: PyPy',
244-
'Topic :: Scientific/Engineering :: Mathematics',
245-
'Topic :: Software Development :: Libraries :: Python Modules',
246-
],
247-
python_requires='>=3.9',
248210
install_requires=['ply'],
249211
extras_require={
250212
# There are certain tests that also require pytest-qt, but because those
@@ -315,18 +277,22 @@ def __ne__(self, other):
315277
"pyomo.contrib.simplification.ginac": ["src/*.cpp", "src/*.hpp"],
316278
},
317279
ext_modules=ext_modules,
318-
entry_points="""
319-
[console_scripts]
320-
pyomo = pyomo.scripting.pyomo_main:main_console_script
321-
322-
[pyomo.command]
323-
pyomo.help = pyomo.scripting.driver_help
324-
pyomo.viewer=pyomo.contrib.viewer.pyomo_viewer
325-
""",
326280
)
327281

328282

329283
try:
284+
# setuptools.build_meta (>=68) forbids absolute paths in the `sources=` list.
285+
# This resets the extensions (only for those items that are absolute paths)
286+
# to use relative paths
287+
ROOT = Path(__file__).parent.resolve()
288+
for ext in ext_modules:
289+
rel_sources = []
290+
for src in ext.sources:
291+
p = Path(src)
292+
if p.is_absolute():
293+
p = p.relative_to(ROOT)
294+
rel_sources.append(p.as_posix())
295+
ext.sources[:] = rel_sources
330296
setup(**setup_kwargs)
331297
except SystemExit as e_info:
332298
# Cython can generate a SystemExit exception on Windows if the

0 commit comments

Comments
 (0)