-
-
Notifications
You must be signed in to change notification settings - Fork 323
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
grass.script: Split the command string using shell-like syntax on the win32 platform same as on POSIX-compliant platforms #1908
Conversation
issue confirmed |
But why is cat > 10 working without escaping? |
Yes you are right, because Example how
|
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.
Simpler code, aligned behavior across platforms (GUI Console is not system terminal), so I general yes.
I would appreciate more explanatory description (that is the final commit message and possibly also the PR description). Although I think I got the idea, I don't really get from the description what are the desired, current, and failing cases.
… Windows Same as on POSIX-compliant platforms. * e.g. run 'd.vect map=census where="cat > 10 AND cat < 20"' with where parameter from Command Prompt CMD/emulator terminal: non-POSIX platform ``` >>> import shlex >>> shlex.split('where="cat > 10 AND cat < 20"', posix=False) ['where="cat', '>', '10', 'AND', 'cat', '<', '20"'] ``` POSIX-compliant platform ``` >>> import shlex >>> shlex.split('where="cat > 10 AND cat < 20"', posix=True) ['where=cat > 10 AND cat < 20'] ``` Under OS MS Windows 'd.vect map=census where="cat > 10 AND cat < 20"' command runned from Command Prompt CMD require use ^ carret symbol for escaping special characters < > ( ) & | , ; ". e.g. 'd.vect map=census where="cat ^> 10 AND cat ^< 20"'
0772c39
to
ef4fa22
Compare
Rebase 0772c39. This is a significant fix and should be merged. |
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.
I'm for merging this, but I'm still not quite able to put all the pieces together.
When it happens and how the carret fits into this? The issue happens when using d.mon in terminal. What happens with d.vect in Console in GUI? Where is this function used and what strings it processes?
Is the function documentation still valid? The PR title would suggest it is not. The implementation has slightly different behavior for Windows but without explanation.
A test would at least clarify the intended behavior which would help clarifying the intention further.
I'm sorry for all the questions, but I guess insufficient documentation is what lead to the bad usage of this function in the first place.
A test for this could go into python/grass/script/tests and it is a great candidate for using pytest. |
First read issue #1063 carefully please. MS Windows platform Command Prompt CMD: Display some vector map e.g. census and use A. Default behavior: I did not find anywhere in the Without carret symbol (d.vect module fail with error message):
With carret char (d.vect module fail again with error message):
Internaly is commandline parsed in Python with following function (under OS MS Windows is used parameter grass/python/grass/script/utils.py Lines 308 to 310 in 5deae3a
parsed result list: ['d.vect', 'map="census"', 'layer="1"', 'display="shape"', 'type="point,line,area,face"', 'where="cat', '<', '10"', 'color="0:29:57"', 'fill_color="0:103:204"', 'width=0', 'width_scale=1', 'icon="basic/x"', 'size=5', 'icon_area="legend/area"', 'icon_line="legend/line"', 'label_layer="1"', 'label_color="red"', 'label_bgcolor="none"', 'label_bcolor="none"', 'label_size=8', 'xref="left"', 'yref="center"'] Look at how is parsed If function Expected behavior (solved with this PR):
MS Windows platform wxGUI console is not affected with changes in this PR and reported issue. Is such an explanation sufficient to understand the problem and solve it?
Yes I agree func doc is not valid and explanation on MS Windows platform is needed too.
if possible, I will add a test. |
Thank you so much. With your new description, it is clear to me now. I see that the caret symbol is really a side issue here as the issue is always passing display commands as posix somewhere in d.mon the rendering machinery while expecting them as platform specific. In this context, I'm now curious why the backslashes need to be doubled on Windows but don't on Linux. You comment also clarifies why the split is not relevant to v.extract. I agree with the addition of discussion of the caret symbol into the documentation of d.vect. It applies to v.extract as well as anything else, though, because it is a CMD thing, right? But that's an issue for later. |
During my current testing, on the MS Windows 11, I found that this is not necessary, but I don't know reason why I added it (PR is from 2021). Originally I tested PR on MS Windows 10.
v.extract module doesn't use Python |
Co-authored-by: Anna Petrasova <kratochanna@gmail.com>
Just to give an overview where this is used:
|
…ith-where-param-on-ms-win-command-prompt
I am able to reproduce this issue on Windows in wxGUI Python tab: from grass.script.utils import split
split('d.vect census where="cat < 10"')
['d.vect', 'census', 'where="cat', '<', '10"']
import shlex
shlex.split('d.vect census where="cat < 10"')
['d.vect', 'census', 'where=cat < 10'] |
… on the win32 platform same as on POSIX-compliant platforms (OSGeo#1908) e.g. run 'd.vect map=census where="cat > 10 AND cat < 20"' with where parameter from Command Prompt CMD/emulator terminal: non-POSIX platform ``` >>> import shlex >>> shlex.split('where="cat > 10 AND cat < 20"', posix=False) ['where="cat', '>', '10', 'AND', 'cat', '<', '20"'] ``` POSIX-compliant platform ``` >>> import shlex >>> shlex.split('where="cat > 10 AND cat < 20"', posix=True) ['where=cat > 10 AND cat < 20'] ``` Under OS MS Windows 'd.vect map=census where="cat > 10 AND cat < 20"' command runned from Command Prompt CMD require use ^ carret symbol for escaping special characters < > ( ) & | , ; ". e.g. 'd.vect map=census where="cat ^> 10 AND cat ^< 20"' --------- Co-authored-by: Anna Petrasova <kratochanna@gmail.com>
… on the win32 platform same as on POSIX-compliant platforms (OSGeo#1908) e.g. run 'd.vect map=census where="cat > 10 AND cat < 20"' with where parameter from Command Prompt CMD/emulator terminal: non-POSIX platform ``` >>> import shlex >>> shlex.split('where="cat > 10 AND cat < 20"', posix=False) ['where="cat', '>', '10', 'AND', 'cat', '<', '20"'] ``` POSIX-compliant platform ``` >>> import shlex >>> shlex.split('where="cat > 10 AND cat < 20"', posix=True) ['where=cat > 10 AND cat < 20'] ``` Under OS MS Windows 'd.vect map=census where="cat > 10 AND cat < 20"' command runned from Command Prompt CMD require use ^ carret symbol for escaping special characters < > ( ) & | , ; ". e.g. 'd.vect map=census where="cat ^> 10 AND cat ^< 20"' --------- Co-authored-by: Anna Petrasova <kratochanna@gmail.com>
Closes #1063.
To Reproduce
Steps to reproduce the behavior:
d.mon start=wx0
< > ( ) & | , ; "
with^
carret symbol please, e.g.d.vect map=census where="cat ^> 10 AND cat ^< 20"
Additional context
More info is in commit message.