-
Notifications
You must be signed in to change notification settings - Fork 297
Single entrypoint with sub-commands #823
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
Conversation
1050d73 to
ef8f413
Compare
yunjunz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @avalentino very much for the PR!
I like the idea of grouping the scripts into different categories. I am wondering that is it possible, while running mintpy -h, to show the sub-commands in groups? We have that in view.py, which helps a lot when the sub-commands/options are long.
Indeed that was the original idea. Another option would be to have 2 levels of sub-commands:
E.g. python3 -m mintpy -h
usage: mintpy [-h] [--version]
{proessing,pre-processing,display,...}
...
Command line interface for MintPy. The Miami INsar Time-series software in PYthon
(MintPy as /mint pai/) is an open-source package for Interferometric Synthetic
Aperture Radar (InSAR) time series analysis. It reads the stack of interferograms
(coregistered and unwrapped) in ISCE, ARIA, FRInGE, HyP3, GMTSAR, SNAP, GAMMA or
ROI_PAC format, and produces three dimensional (2D in space and 1D in time) ground
surface displacement in line-of-sight direction. It includes a routine time series
analysis (`smallbaselineApp.py`) and some independent toolbox. This is research
code provided to you "as is" with NO WARRANTIES OF CORRECTNESS. Use at your own
risk.
options:
-h, --help show this help message and exit
--version show program's version number and exit
sub-commands:
{proessing,pre-processing,display,...}
processing description
pre-processing description
display description
...this solution could be more problematic for users if one does not already know in which category is the subcommand he is interested in, because one do not have a full list of sib-commands in the first level help. [1] https://stackoverflow.com/questions/32017020/grouping-argparse-subparser-arguments |
|
Thank you for the exploration and explanation @avalentino. I agree with you: none of the existing approaches are desired. It's perfectly fine with me to go ahead with the current single group sub-parser design. |
|
Please note that the single-entripoint script ( A solution for this issue could be to move the definition of the argument parser and the main function of all sub-commands in a separate file (one for each sub-command), maybe in a dedicated @yunjunz If you think that the change is not too invasive I could implement it in a separate PR. |
I noticed this slow startup time as well. The FYI, I plan to cut for a new release (v1.4.0) after this PR is merged (for the upcoming UNAVCO training short course), will try this PR ASAP and merge it. |
|
There was a strange error as below while testing the (insar) yunjunz:~/data/test/FernandinaSenDT128/mintpy>$ mintpy timeseries2velocity timeseries_SET_ERA5_ramp_demErr.h5
open timeseries file: timeseries_SET_ERA5_ramp_demErr.h5
--------------------------------------------------
dates from input file: 36
['20141213', '20141225', '20150307', '20150319', '20150331', '20150412', '20150424', '20150506', '20150518', '20150530', '20150611', '20150623', '20150717', '20150729', '20150822', '20150903', '20150915', '20150927', '20151009', '20151021', '20151102', '20151114', '20151126', '20151208', '20151220', '20160101', '20160113', '20160125', '20160206', '20160218', '20160301', '20160406', '20160418', '20160430', '20160512', '20160524']
--------------------------------------------------
using all dates to calculate the time function
--------------------------------------------------
2022-08-03 21:47:42,715 CRITICAL -- unexpected exception caught: 'TypeError' 'float' object is not iterable
(insar) yunjunz:~/data/test/FernandinaSenDT128/mintpy>$ mintpy timeseries2velocity timeseries_SET_ERA5_ramp_demErr.h5
> /Users/yunjunz/tools/MintPy/mintpy/timeseries2velocity.py(150)cmd_line_parse()
-> if inps.template_file:
(Pdb) inps
Namespace(bootstrapCount=400, endDate=None, excludeDate=[], exp=[], file_type='timeseries', log=[], maxMemory=4.0, outfile=None, periodic=[], polynomial=1, ref_date=None, ref_lalo=None, ref_yx=None, res_file='timeseriesResidual.h5', save_res=False, startDate=None, template_file=None, timeSeriesCovFile=None, timeseries_file='timeseries_SET_ERA5_ramp_demErr.h5', uncertaintyQuantification='residue', update_mode=False)
(Pdb) inps.step
0.00011111111111111112 |
|
@avalentino one last comment: each sub-command is currently accessed in cmd without |
|
For subcommands, I would personally expect to not have the |
IMHO the fact that a sub command is implemented in a specific python module is an implementation detail and it should be decoupled from the CLI design. In general I would say that programs using sub-command based CLIs, like e.g. git or docker, use sub-commands names without any file extensions. I don't thin that he Personally I would stay with the current single-entrypoint implementation, but I'm open to change if you prefer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @avalentino and @jhkennedy for your inputs. Sub-command without .py is clearly your preference with good reasons. Going forward with the current design sounds great to me.
All looks great to me now. Thank you very much @avalentino for the useful PR!
|
Thanks @yunjunz |
Description of proposed changes
Implementation of a single entry-point script with multiple sub-commands as proposed in #810.
Reminders