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

grass.script: Pass encoding to Popen parameters #1914

Merged
merged 3 commits into from
Nov 24, 2021
Merged

grass.script: Pass encoding to Popen parameters #1914

merged 3 commits into from
Nov 24, 2021

Conversation

albertoparadisllop
Copy link
Contributor

@albertoparadisllop albertoparadisllop commented Oct 2, 2021

#1521

Added comment on why encoding kwarg is popped in start_command, it's that the rest of the kwargs will be used to construct the call to Popen.

I simply didnt assign it to any variable. It could also have been done with the del keyword.

A different approach could have been to, instead of popping "encoding", do the following:

@@ -464,18 +464,12 @@ def start_command(
 
     :return: Popen object
     """
-    # If encoding is in kwargs, remove it,
-    # as we dont want it to be used on the
-    # call to make_command
-    if "encoding" in kwargs:
-        kwargs.pop("encoding")
-
     options = {}
     popts = {}
     for opt, val in kwargs.items():
         if opt in _popen_args:
             popts[opt] = val
-        else:
+        elif opt != "encoding":
             options[opt] = val
 
     args = make_command(prog, flags, overwrite, quiet, verbose, **options)

Done as part of Hacktoberfest

Added comment on why encoding kwarg is popped
in start_command, it's that the rest of the kwargs will
be used to construct the call to Popen.
@petrasovaa petrasovaa requested a review from wenzeslaus October 2, 2021 09:09
Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albertoparadisllop removing from make_command parameters makes sense.

@petrasovaa Popen has an encoding parameter. Do we want to pass it to Popen? For that, it seems that adding it to _popen_args would be the right solution. ...unless we want to ignore it.

@albertoparadisllop
Copy link
Contributor Author

albertoparadisllop commented Oct 2, 2021

I just thought about it, and it might make more sense to pass it to Popen parameters, as the encoding kwarg is used by other methods to decode the Popen object stdout and stderr (using _make_unicode).

In other words, if I understand correctly, the methods that use Popen object outputs expect them to be encoded using that specific encoding, so it should be passed to Popen.

I'll wait for confirmation before jumping to conclusions though.

@petrasovaa
Copy link
Contributor

I just thought about it, and it might make more sense to pass it to Popen parameters, as the encoding kwarg is used by other methods to decode the Popen object stdout and stderr (using _make_unicode).

In other words, if I understand correctly, the methods that use Popen object outputs expect them to be encoded using that specific encoding, so it should be passed to Popen.

I'll wait for confirmation before jumping to conclusions though.

I agree. If the encoding is specified, stdin/out/err will be unicode, so _make_unicode won't do anything, but that's fine I guess.

albertoparadisllop and others added 2 commits November 18, 2021 23:12
Removed encoding pop and added it to Popen parameters on start_command.
@petrasovaa petrasovaa merged commit 11327ed into OSGeo:main Nov 24, 2021
@neteler neteler added this to the 8.0.0 milestone Dec 9, 2021
@wenzeslaus wenzeslaus changed the title libpython: start_command added comment on why encoding is popped grass.script: Pass encoding to Popen parameters Apr 27, 2022
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants