Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add true deprecation warning to pyomo command #2740

Merged
merged 5 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pyomo/scripting/pyomo_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import sys
import copy
from pyomo.common.deprecation import deprecation_warning

try:
import pkg_resources
Expand Down Expand Up @@ -55,13 +56,16 @@ def main(args=None):
#
if not args:
args.append('-h')
# FIXME: This should use the logger and not print()
if args[0][0] == '-':
if args[0] not in ['-h', '--help', '--version']:
print("WARNING: converting to the 'pyomo solve' subcommand")
deprecation_warning("Running the 'pyomo' script with no subcommand is deprecated. "
"Defaulting to 'pyomo solve'",
version='TBD')
args = ['solve'] + args[0:]
elif args[0] not in pyomo_parser.subparsers:
print("WARNING: converting to the 'pyomo solve' subcommand")
deprecation_warning("Running the 'pyomo' script with no subcommand is deprecated. "
"Defaulting to 'pyomo solve'",
version='TBD')
args = ['solve'] + args[0:]
#
# Process arguments
Expand Down
8 changes: 8 additions & 0 deletions pyomo/scripting/tests/test_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
import re
import pyomo.common.unittest as unittest
from pyomo.common.tee import capture_output
from pyomo.common.log import LoggingIntercept

from pyomo.environ import SolverFactory
from pyomo.scripting.driver_help import help_solvers, help_transformations
from pyomo.scripting.pyomo_main import main


class Test(unittest.TestCase):

def test_pyomo_main_deprecation(self):
with LoggingIntercept() as LOG:
with unittest.pytest.raises(SystemExit) as e:
main(args=['--solvers=glpk', 'foo.py'])
self.assertIn("Running the 'pyomo' script with no subcommand", LOG.getvalue())

def test_help_solvers(self):
with capture_output() as OUT:
help_solvers()
Expand Down