Skip to content

Commit

Permalink
add new argparse/deprecate optparse
Browse files Browse the repository at this point in the history
  • Loading branch information
rieder committed Nov 27, 2023
1 parent 72c4a3c commit d8b9b3a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
68 changes: 68 additions & 0 deletions src/amuse/support/argparse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import argparse


def new_argument_parser(
**kwargs
):
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
add_amuse_arguments(parser, **kwargs)
return parser


def add_amuse_arguments(
parser,
literature=True,
units=False,
):
if literature:
# Note: at the moment these are dummy arguments, with
# amuse.support.literature parsing sys.argv on its own.
# They are therefore usable as command line arguments, but the values
# here are not used further.
parser.add_argument(
'--no-report-references',
dest='no_report_references',
action='store_true',
default=False,
help="don't report literature references to stdout",
)
parser.add_argument(
'--bibtex',
dest='create_bibtex',
action='store_true',
default=False,
help="create bibtex literature file",
)
if units:
# These need to be parsed to be usable.
parser.add_argument(
'--length',
dest='unit_length',
type=str,
default='parsec',
help="length unit",
)
parser.add_argument(
'--mass',
dest='unit_mass',
type=str,
default='MSun',
help="mass unit",
)
parser.add_argument(
'--time',
dest='unit_time',
type=str,
default='Myr',
help="time unit",
)
parser.add_argument(
'--speed',
dest='unit_speed',
type=str,
default='kms',
help="speed unit",
)
return parser
7 changes: 5 additions & 2 deletions src/amuse/units/optparse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

print(
"warning: amuse.units.optparse is deprecated, please use "
"amuse.support.argparse instead (see "
"https://github.com/amusecode/amuse/...)"
)

import optparse
import textwrap
Expand Down Expand Up @@ -111,7 +115,6 @@ def __init__(self,
prog=None,
epilog=None):


if formatter is None:
formatter = IndentedHelpFormatter()

Expand Down

0 comments on commit d8b9b3a

Please sign in to comment.