forked from Pyomo/pyomo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply black to root directory py files
- Loading branch information
Showing
2 changed files
with
87 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -17,11 +17,13 @@ | |
import platform | ||
import sys | ||
from setuptools import setup, find_packages, Command | ||
|
||
try: | ||
from setuptools import DistutilsOptionError | ||
except ImportError: | ||
from distutils.errors import DistutilsOptionError | ||
|
||
|
||
def read(*rnames): | ||
with open(os.path.join(os.path.dirname(__file__), *rnames)) as README: | ||
# Strip all leading badges up to, but not including the COIN-OR | ||
|
@@ -34,6 +36,7 @@ def read(*rnames): | |
break | ||
return line + README.read() | ||
|
||
|
||
def import_pyomo_module(*path): | ||
_module_globals = dict(globals()) | ||
_module_globals['__name__'] = None | ||
|
@@ -42,13 +45,16 @@ def import_pyomo_module(*path): | |
exec(_FILE.read(), _module_globals) | ||
return _module_globals | ||
|
||
|
||
def get_version(): | ||
# Source pyomo/version/info.py to get the version number | ||
return import_pyomo_module('pyomo','version','info.py')['__version__'] | ||
return import_pyomo_module('pyomo', 'version', 'info.py')['__version__'] | ||
|
||
|
||
CYTHON_REQUIRED = "required" | ||
if not any(arg.startswith(cmd) | ||
for cmd in ('build','install','bdist') for arg in sys.argv): | ||
if not any( | ||
arg.startswith(cmd) for cmd in ('build', 'install', 'bdist') for arg in sys.argv | ||
): | ||
using_cython = False | ||
else: | ||
using_cython = "automatic" | ||
|
@@ -66,16 +72,18 @@ def get_version(): | |
# break out of this try-except (disable Cython) | ||
raise RuntimeError("Cython is only supported under CPython") | ||
from Cython.Build import cythonize | ||
|
||
# | ||
# Note: The Cython developers recommend that you distribute C source | ||
# files to users. But this is fine for evaluating the utility of Cython | ||
# | ||
import shutil | ||
|
||
files = [ | ||
"pyomo/core/expr/numvalue.pyx", | ||
"pyomo/core/expr/numeric_expr.pyx", | ||
"pyomo/core/expr/logical_expr.pyx", | ||
#"pyomo/core/expr/visitor.pyx", | ||
# "pyomo/core/expr/visitor.pyx", | ||
"pyomo/core/util.pyx", | ||
"pyomo/repn/standard_repn.pyx", | ||
"pyomo/repn/plugins/cpxlp.pyx", | ||
|
@@ -85,20 +93,22 @@ def get_version(): | |
] | ||
for f in files: | ||
shutil.copyfile(f[:-1], f) | ||
ext_modules = cythonize(files, | ||
compiler_directives={"language_level": 3}) | ||
ext_modules = cythonize(files, compiler_directives={"language_level": 3}) | ||
except: | ||
if using_cython == CYTHON_REQUIRED: | ||
print(""" | ||
print( | ||
""" | ||
ERROR: Cython was explicitly requested with --with-cython, but cythonization | ||
of core Pyomo modules failed. | ||
""") | ||
""" | ||
) | ||
raise | ||
using_cython = False | ||
|
||
if (('--with-distributable-extensions' in sys.argv) | ||
or (os.getenv('PYOMO_SETUP_ARGS') is not None and | ||
'--with-distributable-extensions' in os.getenv('PYOMO_SETUP_ARGS'))): | ||
if ('--with-distributable-extensions' in sys.argv) or ( | ||
os.getenv('PYOMO_SETUP_ARGS') is not None | ||
and '--with-distributable-extensions' in os.getenv('PYOMO_SETUP_ARGS') | ||
): | ||
try: | ||
sys.argv.remove('--with-distributable-extensions') | ||
except: | ||
|
@@ -108,10 +118,14 @@ def get_version(): | |
# NOTE: There is inconsistent behavior in Windows for APPSI. | ||
# As a result, we will NOT include these extensions in Windows. | ||
if not sys.platform.startswith('win'): | ||
appsi_extension = import_pyomo_module( | ||
'pyomo', 'contrib', 'appsi', 'build.py')['get_appsi_extension']( | ||
in_setup=True, appsi_root=os.path.join( | ||
os.path.dirname(__file__), 'pyomo', 'contrib', 'appsi')) | ||
appsi_extension = import_pyomo_module('pyomo', 'contrib', 'appsi', 'build.py')[ | ||
'get_appsi_extension' | ||
]( | ||
in_setup=True, | ||
appsi_root=os.path.join( | ||
os.path.dirname(__file__), 'pyomo', 'contrib', 'appsi' | ||
), | ||
) | ||
ext_modules.append(appsi_extension) | ||
|
||
|
||
|
@@ -127,24 +141,22 @@ class DependenciesCommand(Command): | |
`extras_require`). | ||
""" | ||
|
||
description = "list the dependencies for this package" | ||
user_options = [ | ||
('extras=', None, 'extra targets to include'), | ||
] | ||
user_options = [('extras=', None, 'extra targets to include')] | ||
|
||
def initialize_options(self): | ||
self.extras = None | ||
|
||
def finalize_options(self): | ||
if self.extras is not None: | ||
self.extras = [ | ||
e for e in (_.strip() for _ in self.extras.split(',')) if e | ||
] | ||
self.extras = [e for e in (_.strip() for _ in self.extras.split(',')) if e] | ||
for e in self.extras: | ||
if e not in setup_kwargs['extras_require']: | ||
raise DistutilsOptionError( | ||
"extras can only include {%s}" | ||
% (', '.join(setup_kwargs['extras_require']))) | ||
% (', '.join(setup_kwargs['extras_require'])) | ||
) | ||
|
||
def run(self): | ||
deps = list(self._print_deps(setup_kwargs['install_requires'])) | ||
|
@@ -165,26 +177,26 @@ def _print_deps(self, deplist): | |
|
||
|
||
setup_kwargs = dict( | ||
name = 'Pyomo', | ||
name='Pyomo', | ||
# | ||
# Note: the release number is set in pyomo/version/info.py | ||
# | ||
cmdclass = {'dependencies': DependenciesCommand}, | ||
version = get_version(), | ||
maintainer = 'Pyomo Developer Team', | ||
maintainer_email = '[email protected]', | ||
url = 'http://pyomo.org', | ||
project_urls = { | ||
cmdclass={'dependencies': DependenciesCommand}, | ||
version=get_version(), | ||
maintainer='Pyomo Developer Team', | ||
maintainer_email='[email protected]', | ||
url='http://pyomo.org', | ||
project_urls={ | ||
'Documentation': 'https://pyomo.readthedocs.io/', | ||
'Source': 'https://github.com/Pyomo/pyomo', | ||
}, | ||
license = 'BSD', | ||
platforms = ["any"], | ||
description = 'Pyomo: Python Optimization Modeling Objects', | ||
long_description = read('README.md'), | ||
long_description_content_type = 'text/markdown', | ||
keywords = ['optimization'], | ||
classifiers = [ | ||
license='BSD', | ||
platforms=["any"], | ||
description='Pyomo: Python Optimization Modeling Objects', | ||
long_description=read('README.md'), | ||
long_description_content_type='text/markdown', | ||
keywords=['optimization'], | ||
classifiers=[ | ||
'Development Status :: 5 - Production/Stable', | ||
'Intended Audience :: End Users/Desktop', | ||
'Intended Audience :: Science/Research', | ||
|
@@ -203,12 +215,11 @@ def _print_deps(self, deplist): | |
'Programming Language :: Python :: Implementation :: CPython', | ||
'Programming Language :: Python :: Implementation :: PyPy', | ||
'Topic :: Scientific/Engineering :: Mathematics', | ||
'Topic :: Software Development :: Libraries :: Python Modules' ], | ||
python_requires = '>=3.7', | ||
install_requires = [ | ||
'ply', | ||
'Topic :: Software Development :: Libraries :: Python Modules', | ||
], | ||
extras_require = { | ||
python_requires='>=3.7', | ||
install_requires=['ply'], | ||
extras_require={ | ||
'tests': [ | ||
#'codecov', # useful for testing infrastructures, but not required | ||
'coverage', | ||
|
@@ -223,26 +234,26 @@ def _print_deps(self, deplist): | |
'sphinx_rtd_theme>0.5', | ||
'sphinxcontrib-jsmath', | ||
'sphinxcontrib-napoleon', | ||
'numpy', # Needed by autodoc for pynumero | ||
'scipy', # Needed by autodoc for pynumero | ||
'numpy', # Needed by autodoc for pynumero | ||
'scipy', # Needed by autodoc for pynumero | ||
], | ||
'optional': [ | ||
'dill', # No direct use, but improves lambda pickle | ||
'ipython', # contrib.viewer | ||
'dill', # No direct use, but improves lambda pickle | ||
'ipython', # contrib.viewer | ||
# Note: matplotlib 3.6.1 has bug #24127, which breaks | ||
# seaborn's histplot (triggering parmest failures) | ||
'matplotlib!=3.6.1', | ||
'networkx', # network, incidence_analysis, community_detection | ||
'numpy', | ||
'openpyxl', # dataportals | ||
#'pathos', # requested for #963, but PR currently closed | ||
'pint', # units | ||
'python-louvain', # community_detection | ||
'pyyaml', # core | ||
'pint', # units | ||
'python-louvain', # community_detection | ||
'pyyaml', # core | ||
'scipy', | ||
'sympy', # differentiation | ||
'xlrd', # dataportals | ||
'z3-solver', # community_detection | ||
'sympy', # differentiation | ||
'xlrd', # dataportals | ||
'z3-solver', # community_detection | ||
# | ||
# subprocess output is merged more reliably if | ||
# 'PeekNamedPipe' is available from pywin32 | ||
|
@@ -255,28 +266,28 @@ def _print_deps(self, deplist): | |
# DAE can use casadi; as of 1 Nov 22, casadi has not been | ||
# released for Python 3.11 | ||
'casadi; implementation_name!="pypy" and python_version<"3.11"', | ||
'numdifftools; implementation_name!="pypy"', # pynumero | ||
'numdifftools; implementation_name!="pypy"', # pynumero | ||
'pandas; implementation_name!="pypy"', | ||
'seaborn; implementation_name!="pypy"', # parmest.graphics | ||
'seaborn; implementation_name!="pypy"', # parmest.graphics | ||
], | ||
}, | ||
packages = find_packages(exclude=("scripts",)), | ||
package_data = { | ||
packages=find_packages(exclude=("scripts",)), | ||
package_data={ | ||
"pyomo.contrib.ampl_function_demo": ["src/*"], | ||
"pyomo.contrib.appsi.cmodel": ["src/*"], | ||
"pyomo.contrib.mcpp": ["*.cpp"], | ||
"pyomo.contrib.pynumero": ['src/*', 'src/tests/*'], | ||
"pyomo.contrib.viewer": ["*.ui"], | ||
}, | ||
ext_modules = ext_modules, | ||
entry_points = """ | ||
ext_modules=ext_modules, | ||
entry_points=""" | ||
[console_scripts] | ||
pyomo = pyomo.scripting.pyomo_main:main_console_script | ||
[pyomo.command] | ||
pyomo.help = pyomo.scripting.driver_help | ||
pyomo.viewer=pyomo.contrib.viewer.pyomo_viewer | ||
""" | ||
""", | ||
) | ||
|
||
|
||
|
@@ -290,23 +301,31 @@ def _print_deps(self, deplist): | |
if 'Microsoft Visual C++' not in str(e_info): | ||
raise | ||
elif using_cython == CYTHON_REQUIRED: | ||
print(""" | ||
print( | ||
""" | ||
ERROR: Cython was explicitly requested with --with-cython, but cythonization | ||
of core Pyomo modules failed. | ||
""") | ||
""" | ||
) | ||
raise | ||
else: | ||
print(""" | ||
print( | ||
""" | ||
ERROR: setup() failed: | ||
%s | ||
Re-running setup() without the Cython modules | ||
""" % (str(e_info),)) | ||
""" | ||
% (str(e_info),) | ||
) | ||
setup_kwargs['ext_modules'] = [] | ||
setup(**setup_kwargs) | ||
print(""" | ||
print( | ||
""" | ||
WARNING: Installation completed successfully, but the attempt to cythonize | ||
core Pyomo modules failed. Cython provides performance | ||
optimizations and is not required for any Pyomo functionality. | ||
Cython returned the following error: | ||
"%s" | ||
""" % (str(e_info),)) | ||
""" | ||
% (str(e_info),) | ||
) |