Skip to content

Commit

Permalink
Merge branch 'main' into edi_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmundt authored Dec 9, 2024
2 parents 6207fe1 + 6f36384 commit ff1787f
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .coin-or/projDesc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Carl D. Laird, Chair, Pyomo Management Committee, claird at andrew dot cmu dot e

<platform>
<operatingSystem>Any</operatingSystem>
<compiler>Python 3.8, 3.9, 3.10, 3.11, 3.12, 3.13</compiler>
<compiler>Python 3.9, 3.10, 3.11, 3.12, 3.13</compiler>
</platform>

</testedPlatforms>
Expand Down
12 changes: 3 additions & 9 deletions .github/workflows/release_wheel_creation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ jobs:
matrix:
os: [ubuntu-22.04, windows-latest, macos-latest]
arch: [all]
wheel-version: ['cp38*', 'cp39*', 'cp310*', 'cp311*', 'cp312*', 'cp313*']
wheel-version: ['cp39*', 'cp310*', 'cp311*', 'cp312*', 'cp313*']

include:
- wheel-version: 'cp38*'
TARGET: 'py38'
GLOBAL_OPTIONS: "--with-cython --with-distributable-extensions"
- wheel-version: 'cp39*'
TARGET: 'py39'
GLOBAL_OPTIONS: "--with-cython --with-distributable-extensions"
Expand Down Expand Up @@ -96,12 +93,9 @@ jobs:
matrix:
os: [ubuntu-22.04]
arch: [all]
wheel-version: ['cp38*', 'cp39*', 'cp310*', 'cp311*', 'cp312*', 'cp313*']
wheel-version: ['cp39*', 'cp310*', 'cp311*', 'cp312*', 'cp313*']

include:
- wheel-version: 'cp38*'
TARGET: 'py38'
GLOBAL_OPTIONS: "--with-cython --with-distributable-extensions"
- wheel-version: 'cp39*'
TARGET: 'py39'
GLOBAL_OPTIONS: "--with-cython --with-distributable-extensions"
Expand Down Expand Up @@ -185,7 +179,7 @@ jobs:
include:
- os: ubuntu-latest
TARGET: generic_tarball
python-version: [3.8]
python-version: [3.9]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
22 changes: 8 additions & 14 deletions .github/workflows/test_branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,14 @@ jobs:
other: [""]
category: [""]

# win/3.8 conda builds no longer work due to environment not being able
# to resolve. We are skipping it now.
exclude:
- os: windows-latest
python: 3.8

include:
- os: ubuntu-latest
python: '3.13'
TARGET: linux
PYENV: pip

- os: macos-latest
python: '3.10'
python: '3.11'
TARGET: osx
PYENV: pip

Expand Down Expand Up @@ -125,7 +119,7 @@ jobs:
PACKAGES: cython

- os: windows-latest
python: 3.8
python: '3.10'
other: /pip
skip_doctest: 1
TARGET: win
Expand Down Expand Up @@ -693,17 +687,17 @@ jobs:
bare-python-env:
name: linux/3.8/bare-env
name: linux/3.9/bare-env
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout Pyomo source
uses: actions/checkout@v4

- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.9

- name: Install Pyomo
run: |
Expand Down Expand Up @@ -761,17 +755,17 @@ jobs:
# id: pip-cache
# with:
# path: cache/pip
# key: pip-${{env.CACHE_VER}}.0-${{runner.os}}-3.8
# key: pip-${{env.CACHE_VER}}.0-${{runner.os}}-3.9

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.9

- name: Install Python Packages (pip)
shell: bash # DO NOT REMOVE: see note above
Expand Down
26 changes: 10 additions & 16 deletions .github/workflows/test_pr_and_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,10 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: [ 3.8, 3.9, '3.10', '3.11', '3.12', '3.13' ]
python: [ 3.9, '3.10', '3.11', '3.12', '3.13' ]
other: [""]
category: [""]

# win/3.8 conda builds no longer work due to environment not being able
# to resolve. We are skipping it now.
exclude:
- os: windows-latest
python: 3.8

include:
- os: ubuntu-latest
TARGET: linux
Expand Down Expand Up @@ -119,7 +113,7 @@ jobs:
PACKAGES: cython

- os: windows-latest
python: 3.8
python: 3.9
other: /pip
skip_doctest: 1
TARGET: win
Expand All @@ -134,7 +128,7 @@ jobs:
PYENV: pip

- os: ubuntu-latest
python: 3.8
python: 3.9
other: /slim
slim: 1
skip_doctest: 1
Expand All @@ -151,7 +145,7 @@ jobs:
PACKAGES: "gurobipy dill numpy>2.0 scipy networkx"

- os: ubuntu-latest
python: 3.9
python: '3.10'
other: /pyutilib
TARGET: linux
PYENV: pip
Expand Down Expand Up @@ -727,18 +721,18 @@ jobs:
bare-python-env:
name: linux/3.8/bare-env
name: linux/3.9/bare-env
needs: lint # the linter job is a prerequisite for PRs
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout Pyomo source
uses: actions/checkout@v4

- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.9

- name: Install Pyomo
run: |
Expand Down Expand Up @@ -796,17 +790,17 @@ jobs:
# id: pip-cache
# with:
# path: cache/pip
# key: pip-${{env.CACHE_VER}}.0-${{runner.os}}-3.8
# key: pip-${{env.CACHE_VER}}.0-${{runner.os}}-3.9

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.9

- name: Install Python Packages (pip)
shell: bash # DO NOT REMOVE: see note above
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Pyomo is available under the BSD License - see the

Pyomo is currently tested with the following Python implementations:

* CPython: 3.8, 3.9, 3.10, 3.11, 3.12, 3.13
* CPython: 3.9, 3.10, 3.11, 3.12, 3.13
* PyPy: 3.9

_Testing and support policy_:
Expand Down
2 changes: 1 addition & 1 deletion doc/OnlineDocs/getting_started/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Installation

Pyomo currently supports the following versions of Python:

* CPython: 3.8, 3.9, 3.10, 3.11, 3.12, 3.13
* CPython: 3.9, 3.10, 3.11, 3.12, 3.13
* PyPy: 3

At the time of the first Pyomo release after the end-of-life of a minor Python
Expand Down
18 changes: 14 additions & 4 deletions pyomo/common/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import inspect
import importlib
import importlib.util
import logging
import sys
import warnings
Expand Down Expand Up @@ -520,13 +521,22 @@ def find_spec(self, fullname, path, target=None):

spec = None
# Continue looking for the finder that would have originally
# loaded the deferred import module b starting at the next
# loaded the deferred import module by starting at the next
# finder in sys.meta_path (this way, we are agnostic to where
# the module is coming from: file system, registry, etc.)
for finder in sys.meta_path[sys.meta_path.index(self) + 1 :]:
spec = finder.find_spec(fullname, path, target)
if spec is not None:
break
if hasattr(finder, 'find_spec'):
# Support standard importlib MetaPathFinders
spec = finder.find_spec(fullname, path, target)
if spec is not None:
break
else:
# Support for imp finders/loaders (deprecated, but
# supported through Python 3.11)
loader = finder.find_module(fullname, path)
if loader is not None:
spec = importlib.util.spec_from_loader(fullname, loader)
break
else:
# Module not found. Returning None will proceed to the next
# finder (which will eventually raise a ModuleNotFoundError)
Expand Down
17 changes: 17 additions & 0 deletions pyomo/common/tests/mod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ___________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2024
# National Technology and Engineering Solutions of Sandia, LLC
# Under the terms of Contract DE-NA0003525 with National Technology and
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________
#

# This is a simple module used as part of testing import callbacks


class Foo(object):
data = 42
67 changes: 67 additions & 0 deletions pyomo/common/tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# ___________________________________________________________________________

import inspect
import sys
from importlib.machinery import PathFinder
from io import StringIO

import pyomo.common.unittest as unittest
Expand All @@ -24,6 +26,7 @@
UnavailableClass,
_DeferredAnd,
_DeferredOr,
_DeferredImportCallbackFinder,
check_min_version,
dill,
dill_available,
Expand Down Expand Up @@ -248,6 +251,70 @@ def _record_avail(module, avail):
self.assertFalse(avail1)
self.assertEqual(ans, [True, False])

def test_callback_on_import(self):
sys.modules.pop('pyomo.common.tests.mod', None)
ans = []

class ImpFinder(object):
# This is an "imp" module-style finder (deprecated in Python
# 3.4 and removed in Python 3.12, but Google Collab still
# defines finders like this)
match = ''

def find_module(self, fullname, path=None):
if fullname != self.match:
ans.append('pass')
return None
ans.append('load')
spec = PathFinder().find_spec(fullname, path)
return spec.loader

def load_module(self, name):
pass

def _callback(module, avail):
ans.append(len(ans))

attempt_import('pyomo.common.tests.mod', defer_import=True, callback=_callback)
self.assertEqual(ans, [])
import pyomo.common.tests.mod as m

self.assertEqual(ans, [0])
self.assertEqual(m.Foo.data, 42)

sys.modules.pop('pyomo.common.tests.mod', None)
del m
attempt_import('pyomo.common.tests.mod', defer_import=True, callback=_callback)

try:
# Test deferring to an imp-style finder that does not match
# the target module name
_finder = ImpFinder()
sys.meta_path.insert(
sys.meta_path.index(_DeferredImportCallbackFinder) + 1, _finder
)
import pyomo.common.tests.mod as m

self.assertEqual(ans, [0, 'pass', 2])
self.assertEqual(m.Foo.data, 42)

sys.modules.pop('pyomo.common.tests.mod', None)
del m
attempt_import(
'pyomo.common.tests.mod', defer_import=True, callback=_callback
)

# Test deferring to an imp-style finder that DOES match the
# target module name
_finder.match = 'pyomo.common.tests.mod'

import pyomo.common.tests.mod as m

self.assertEqual(ans, [0, 'pass', 2, 'load', 4])
self.assertEqual(m.Foo.data, 42)
finally:
sys.meta_path.remove(_finder)

def test_import_exceptions(self):
mod, avail = attempt_import(
'pyomo.common.tests.dep_mod_except',
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ def __ne__(self, other):
'Operating System :: Unix',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
Expand All @@ -245,7 +244,7 @@ def __ne__(self, other):
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Software Development :: Libraries :: Python Modules',
],
python_requires='>=3.8',
python_requires='>=3.9',
install_requires=['ply'],
extras_require={
# There are certain tests that also require pytest-qt, but because those
Expand Down

0 comments on commit ff1787f

Please sign in to comment.