amuse
amuse copied to clipboard
Update amuse.units.optparse to use argparse
Out of curiosity, why is there a module amuse.units.optparse? Is this different from the standard python optparse (which is since Python 2.7 deprecated and replaced by argparse)? And why is it in amuse.units? Seems a weird place for this...
indeed Steven, the amuse.units.optparse overloads the units into the standard python package. you can read about it in the amuse book.
Groeten, Simon
----- Reply message ----- From: "Steven Rieder" [email protected] To: "amusecode/amuse" [email protected] Cc: "Subscribed" [email protected] Subject: [amusecode/amuse] amuse.units.optparse? (#172) Date: Thu, Oct 19, 2017 06:33
Out of curiosity, why is there a module amuse.units.optparse?
Is this different from the standard python optparse (which is since Python 2.7 deprecated and replaced by argparse)?
And why is it in amuse.units? Seems a weird place for this...
—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.
{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/amusecode/amuse","title":"amusecode/amuse","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/amusecode/amuse"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"amuse.units.optparse? (#172)"}],"action":{"name":"View Issue","url":"https://github.com/amusecode/amuse/issues/172"}}}
Ah, I see. Since the optparse module is deprecated, we should then aim to replace it with an argparse equivalent.
No rush though, optparse will not be removed any time soon. https://www.python.org/dev/peps/pep-0389/#deprecation-of-optparse
This should be fixed for AMUSE 13 as well.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
optparse should also move from amuse/units to amuse/support
if its just about the units the following works with argparse:
import argparse
from amuse.units import units
parser = argparse.ArgumentParser(description='do some AMUSE stuff')
parser.add_argument('--endtime', dest='endtime', action='store',
default="10", type=units.Myr, help="end time (Myr)")
args = parser.parse_args()
print(args.endtime)
the only thing is that the units.Myr(x) constructor should be changed to accept a string and convert it to float in that case...
(it accepts string, but doesn't convert...)
I'll see if I can get it to convert strings. If this works I'll update the examples to that new method and add some deprecation warning to the current optparse method.
I've tested @ipelupessy's example above with #934 and it works with that change, so I think that's the way to go.
Fixed with #934!