amuse icon indicating copy to clipboard operation
amuse copied to clipboard

Update amuse.units.optparse to use argparse

Open rieder opened this issue 7 years ago • 8 comments

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...

rieder avatar Oct 19 '17 04:10 rieder

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"}}}

spzwart avatar Oct 19 '17 06:10 spzwart

Ah, I see. Since the optparse module is deprecated, we should then aim to replace it with an argparse equivalent.

rieder avatar Oct 19 '17 06:10 rieder

No rush though, optparse will not be removed any time soon. https://www.python.org/dev/peps/pep-0389/#deprecation-of-optparse

rieder avatar Oct 19 '17 06:10 rieder

This should be fixed for AMUSE 13 as well.

rieder avatar Jul 16 '19 13:07 rieder

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.

stale[bot] avatar Mar 04 '22 15:03 stale[bot]

optparse should also move from amuse/units to amuse/support

ipelupessy avatar Jun 29 '22 15:06 ipelupessy

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...

ipelupessy avatar Jun 29 '22 16:06 ipelupessy

(it accepts string, but doesn't convert...)

ipelupessy avatar Jun 29 '22 16:06 ipelupessy

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.

rieder avatar Mar 06 '23 08:03 rieder

I've tested @ipelupessy's example above with #934 and it works with that change, so I think that's the way to go.

rieder avatar Mar 06 '23 22:03 rieder

Fixed with #934!

rieder avatar Mar 14 '23 16:03 rieder