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

arg less main() for pip install -e #5

Closed
yunjunz opened this issue Nov 28, 2021 · 2 comments · Fixed by insarlab/MintPy#714
Closed

arg less main() for pip install -e #5

yunjunz opened this issue Nov 28, 2021 · 2 comments · Fixed by insarlab/MintPy#714
Labels
bug Something isn't working

Comments

@yunjunz
Copy link
Owner

yunjunz commented Nov 28, 2021

It seems when installing mintpy using pip install -e MintPy, the command-line options are not working:

(insar) kyushu:~/data/offset4motion/SaltonSeaSenDT173/merged/test/20191220_20201220>$ view.py off3_snr.bip -v 0 100 --flip-lr
Traceback (most recent call last):
  File "/home/zyunjun/tools/miniconda3/envs/insar/bin/view.py", line 33, in <module>
    sys.exit(load_entry_point('mintpy', 'console_scripts', 'view.py')())
  File "/home/zyunjun/tools/MintPy/mintpy/view.py", line 1663, in main
    obj.configure()
  File "/home/zyunjun/tools/MintPy/mintpy/view.py", line 1538, in configure
    inps = cmd_line_parse(self.iargs)
  File "/home/zyunjun/tools/MintPy/mintpy/view.py", line 175, in cmd_line_parse
    geo_opt_names = list(set(geo_opt_names) & set(iargs))
TypeError: 'NoneType' object is not iterable

The solution could be using the sys.argv all the time as suggested in insarlab#652. view.py has the most complicated usage of iargs. If the following 3 scenarios works, then it should be safe to translate the rest of mintpy to arg less main() style:

  1. view.py velocity.h5 -v 0 3 --flip-lr # command line in terminal
  2. view.main('velocity.h5 -v 0 3 --flip-lr'.split()) # main function call in python
  3. view and tsview interactive jupyter notebook: https://github.com/insarlab/MintPy-tutorial/tree/main/visualization
@yunjunz yunjunz added the bug Something isn't working label Nov 29, 2021
@jhkennedy
Copy link

@yunjunz this issues is caused by trying to convert iargs to s set when it's value is None here:
https://github.com/yunjunz/MintPy/blob/main/mintpy/view.py#L175

>>> set(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable

You'll likewise have problems trying to join(None) here:
https://github.com/yunjunz/MintPy/blob/main/mintpy/view.py#L185

>>> ' '.join(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only join an iterable

In the old install, you set iargs=sys.argv[1:]:
https://github.com/yunjunz/MintPy/blob/main/mintpy/view.py#L1677

So if you wanted to have the old behavior, you could do the same with a:

if iargs is None:
    iargs = sys.argv[1:]

This will have issues, however, where sys.argv is related to how the interpreter was launched. So you'd probably actually just want:

if iargs is None:
    iargs = []

which will look like the old case where the script was invoked without any arguments.


In general, I'd caution against doing operations against sys.argv and instead would suggest the logic would be better done looking at your parsed args (inps) as argparse handles a lot of gotchas with sys.argv.
https://github.com/yunjunz/MintPy/blob/main/mintpy/view.py#L141

@yunjunz
Copy link
Owner Author

yunjunz commented Dec 21, 2021

Thank you @jhkennedy for the diagnose. The following modification seems to work in all three scenarios for versions installed via pip or path setup. I have issued a PR for it.

# save argv (to check the manually specified arguments)
# use iargs        for python call
# use sys.argv[1:] for command line call
inps.argv = iargs if iargs else sys.argv[1:]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants