Skip to content

Commit 18def95

Browse files
authored
Merge pull request #3603 from mrmundt/modernize-infrastructure
Modernize infrastructure to use `pyproject.toml`
2 parents 49bfc6b + 33fe42b commit 18def95

File tree

35 files changed

+406
-309
lines changed

35 files changed

+406
-309
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,14 +654,15 @@ jobs:
654654
655655
- name: Install Pyomo
656656
run: |
657+
export PYOMO_SETUP_ARGS=${{ matrix.setup_options }}
657658
echo ""
658659
echo "Clone Pyomo-model-libraries..."
659660
URL=https://github.com/Pyomo/pyomo-model-libraries.git
660661
git clone -b ${SRC_REF##*/} $URL || git clone -b main $URL
661662
echo ""
662663
echo "Install Pyomo..."
663664
echo ""
664-
$PYTHON_EXE setup.py develop ${{matrix.setup_options}}
665+
$PYTHON_EXE -m pip install -e .
665666
echo ""
666667
echo "Set custom PYOMO_CONFIG_DIR"
667668
echo ""
@@ -790,7 +791,7 @@ jobs:
790791
echo ""
791792
echo "Install Pyomo..."
792793
echo ""
793-
python setup.py develop
794+
python -m pip install -e .
794795
echo ""
795796
echo "Set custom PYOMO_CONFIG_DIR"
796797
echo ""
@@ -868,13 +869,14 @@ jobs:
868869
869870
- name: Install Pyomo
870871
run: |
872+
export PYOMO_SETUP_ARGS=${{ matrix.setup_options }}
871873
echo ""
872874
echo "Clone Pyomo-model-libraries..."
873875
git clone https://github.com/Pyomo/pyomo-model-libraries.git
874876
echo ""
875877
echo "Install Pyomo..."
876878
echo ""
877-
$PYTHON_EXE setup.py develop ${{matrix.setup_options}}
879+
$PYTHON_EXE -m pip install -e .
878880
echo ""
879881
echo "Set custom PYOMO_CONFIG_DIR"
880882
echo ""

.github/workflows/test_pr_and_main.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,14 +706,15 @@ jobs:
706706
707707
- name: Install Pyomo
708708
run: |
709+
export PYOMO_SETUP_ARGS=${{ matrix.setup_options }}
709710
echo ""
710711
echo "Clone Pyomo-model-libraries..."
711712
URL=https://github.com/Pyomo/pyomo-model-libraries.git
712713
git clone -b ${SRC_REF##*/} $URL || git clone -b main $URL
713714
echo ""
714715
echo "Install Pyomo..."
715716
echo ""
716-
$PYTHON_EXE setup.py develop ${{matrix.setup_options}}
717+
$PYTHON_EXE -m pip install -e .
717718
echo ""
718719
echo "Set custom PYOMO_CONFIG_DIR"
719720
echo ""
@@ -843,7 +844,7 @@ jobs:
843844
echo ""
844845
echo "Install Pyomo..."
845846
echo ""
846-
python setup.py develop
847+
python -m pip install -e .
847848
echo ""
848849
echo "Set custom PYOMO_CONFIG_DIR"
849850
echo ""
@@ -921,13 +922,14 @@ jobs:
921922
922923
- name: Install Pyomo
923924
run: |
925+
export PYOMO_SETUP_ARGS=${{ matrix.setup_options }}
924926
echo ""
925927
echo "Clone Pyomo-model-libraries..."
926928
git clone https://github.com/Pyomo/pyomo-model-libraries.git
927929
echo ""
928930
echo "Install Pyomo..."
929931
echo ""
930-
$PYTHON_EXE setup.py develop ${{matrix.setup_options}}
932+
$PYTHON_EXE -m pip install -e .
931933
echo ""
932934
echo "Set custom PYOMO_CONFIG_DIR"
933935
echo ""

.jenkins.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#
2929
# DISABLE_COVERAGE: if nonempty, then coverage analysis is disabled
3030
#
31-
# PYOMO_SETUP_ARGS: passed to the 'python setup.py develop' command
31+
# PYOMO_SETUP_ARGS: passed to the 'pip install' command
3232
# (e.g., to specify --with-cython)
3333
#
3434
# PYOMO_DOWNLOAD_ARGS: passed to the 'pyomo download-extensions' command
@@ -94,7 +94,7 @@ if test -z "$MODE" -o "$MODE" == setup; then
9494
echo "PyUtilib not found; skipping"
9595
fi
9696
pushd "$WORKSPACE/pyomo" || exit 1
97-
python setup.py develop $PYOMO_SETUP_ARGS || exit 1
97+
pip install -e . || exit 1
9898
popd
9999
#
100100
# DO NOT install pyomo-model-libraries

doc/OnlineDocs/getting_started/installation.rst

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ packages including but not limited to: matplotlib, networkx, numpy,
5151
openpyxl, pandas, pint, pymysql, pyodbc, pyro4, scipy, sympy, and
5252
xlrd.
5353

54-
A full list of conditional dependencies can be found in Pyomo's
55-
``setup.py`` and displayed using:
54+
A full list of optional dependencies can be found in Pyomo's
55+
``pyproject.toml`` under the ``[project.optional-dependencies]`` table.
56+
They can be displayed by running:
5657

5758
::
5859

60+
# Legacy format
5961
python setup.py dependencies --extra optional
62+
# Newer format - prints as a JSON
63+
python -m pip install --dry-run --report - '.[optional]'
6064

6165
Pyomo extensions that require any of these packages will generate
6266
an error message for missing dependencies upon use.
@@ -86,16 +90,31 @@ initialized.
8690
.. note::
8791
This can only be done via ``pip`` or from source.
8892

89-
Via ``pip``:
93+
Installation via ``pip`` or from source is done the same way - using environment
94+
variables. On Linux/MacOS:
9095

9196
::
9297

93-
pip install pyomo --global-option="--with-cython"
98+
export PYOMO_SETUP_ARGS=--with-cython
99+
pip install pyomo
100+
101+
On Windows:
102+
103+
::
104+
105+
# Via command prompt
106+
set PYOMO_SETUP_ARGS=--with-cython
107+
# Via powershell
108+
$env:PYOMO_SETUP_ARGS="--with-cython"
109+
pip install pyomo
110+
94111

95112
From source (recommended for advanced users only):
96113

97114
::
98115

116+
export PYOMO_SETUP_ARGS=--with-cython
99117
git clone https://github.com/Pyomo/pyomo.git
100118
cd pyomo
101-
python setup.py install --with-cython
119+
# Use -e to install in editable mode
120+
pip install .

examples/pyomobook/strip_examples.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ def f(file):
2121
if prefix.endswith('_strip'):
2222
return
2323

24-
with open(base + '/' + prefix + '_strip.py', 'w') as OUTPUT, open(
25-
file, 'r'
26-
) as INPUT:
24+
with (
25+
open(base + '/' + prefix + '_strip.py', 'w') as OUTPUT,
26+
open(file, 'r') as INPUT,
27+
):
2728
for line in INPUT:
2829
if line[0] == '#' and '@' in line:
2930
continue

pyomo/common/tests/test_tee.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,9 @@ def flush(self):
679679
tee._poll_timeout = tee._poll_interval * 2**5 # 0.0032
680680
tee._poll_timeout_deadlock = tee._poll_interval * 2**7 # 0.0128
681681
try:
682-
with LoggingIntercept() as LOG, self.assertRaisesRegex(
683-
RuntimeError, 'deadlock'
682+
with (
683+
LoggingIntercept() as LOG,
684+
self.assertRaisesRegex(RuntimeError, 'deadlock'),
684685
):
685686
with tee.TeeStream(MockStream()) as t:
686687
t.STDERR.write('*')
@@ -697,8 +698,9 @@ def flush(self):
697698
tee._poll_timeout = tee._poll_interval * 2**5 # 0.0032
698699
tee._poll_timeout_deadlock = tee._poll_interval * 2**7 # 0.0128
699700
try:
700-
with LoggingIntercept() as LOG, self.assertRaisesRegex(
701-
ValueError, 'testing'
701+
with (
702+
LoggingIntercept() as LOG,
703+
self.assertRaisesRegex(ValueError, 'testing'),
702704
):
703705
with tee.TeeStream(MockStream()) as t:
704706
t.STDERR.write('*')

pyomo/contrib/cp/interval_var.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def __init__(
167167
length=None,
168168
optional=False,
169169
name=None,
170-
doc=None
170+
doc=None,
171171
): ...
172172

173173
def __init__(self, *args, **kwargs):

pyomo/contrib/latex_printer/tests/test_latex_printer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def ruleMaker(m):
503503
self.assertRaises(
504504
ValueError,
505505
latex_printer,
506-
**{'pyomo_component': m.constraint, 'latex_component_map': lcm}
506+
**{'pyomo_component': m.constraint, 'latex_component_map': lcm},
507507
)
508508

509509
def test_latexPrinter_indexedParam(self):
@@ -540,7 +540,7 @@ def ruleMaker_2(m):
540540
self.assertRaises(
541541
ValueError,
542542
latex_printer,
543-
**{'pyomo_component': m, 'latex_component_map': lcm}
543+
**{'pyomo_component': m, 'latex_component_map': lcm},
544544
)
545545

546546
def test_latexPrinter_involvedModel(self):
@@ -767,7 +767,7 @@ def ruleMaker_2(m, i):
767767
self.assertRaises(
768768
RuntimeError,
769769
latex_printer,
770-
**{'pyomo_component': m, 'throw_templatization_error': True}
770+
**{'pyomo_component': m, 'throw_templatization_error': True},
771771
)
772772
pstr = latex_printer(m)
773773
bstr = dedent(

pyomo/contrib/mindtpy/algorithm_base_class.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,8 +2795,9 @@ def solve(self, model, **kwds):
27952795
)
27962796

27972797
self.create_utility_block(self.working_model, 'MindtPy_utils')
2798-
with time_code(self.timing, 'total', is_main_timer=True), lower_logger_level_to(
2799-
config.logger, new_logging_level
2798+
with (
2799+
time_code(self.timing, 'total', is_main_timer=True),
2800+
lower_logger_level_to(config.logger, new_logging_level),
28002801
):
28012802
self._log_solver_intro_message()
28022803
self.initialize_subsolvers()

pyomo/contrib/solver/solvers/ipopt.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,11 @@ def solve(self, model, **kwds):
333333
# be terminated with '\n' regardless of platform. We will
334334
# disable universal newlines in the NL file to prevent
335335
# Python from mapping those '\n' to '\r\n' on Windows.
336-
with open(
337-
basename + '.nl', 'w', newline='\n', encoding='utf-8'
338-
) as nl_file, open(
339-
basename + '.row', 'w', encoding='utf-8'
340-
) as row_file, open(
341-
basename + '.col', 'w', encoding='utf-8'
342-
) as col_file:
336+
with (
337+
open(basename + '.nl', 'w', newline='\n', encoding='utf-8') as nl_file,
338+
open(basename + '.row', 'w', encoding='utf-8') as row_file,
339+
open(basename + '.col', 'w', encoding='utf-8') as col_file,
340+
):
343341
timer.start('write_nl_file')
344342
self._writer.config.set_value(config.writer_config)
345343
try:

pyomo/contrib/trustregion/TRF.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def solve(
470470
model,
471471
degrees_of_freedom_variables,
472472
ext_fcn_surrogate_map_rule=None,
473-
**kwds
473+
**kwds,
474474
):
475475
"""
476476
This method calls the TRF algorithm.

pyomo/core/base/PyomoModel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ def create_instance(
643643
namespaces=None,
644644
profile_memory=0,
645645
report_timing=False,
646-
**kwds
646+
**kwds,
647647
):
648648
"""
649649
Create a concrete instance of an abstract model, possibly using data

pyomo/core/base/component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def pprint(self, ostream=None, verbose=False, prefix=""):
519519
self.local_name,
520520
self.doc,
521521
self.is_constructed(),
522-
*self._pprint()
522+
*self._pprint(),
523523
)
524524

525525
def display(self, ostream=None, verbose=False, prefix=""):

pyomo/core/kernel/block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def write(
277277
format=None,
278278
_solver_capability=None,
279279
_called_by_solver=False,
280-
**kwds
280+
**kwds,
281281
):
282282
"""
283283
Write the model to a file, with a given format.

0 commit comments

Comments
 (0)