Skip to content

Conversation

@ptosi
Copy link
Contributor

@ptosi ptosi commented May 14, 2019

Slight rework of adb_shell to improve readability and stability but, most importantly, to address #386.

Please note that this requires modern Py3 and should be merged post-WA3.1 (preferred) or could be modified to be Py2.7-compatible.

import zipfile

from pipes import quote
from shlex import quote
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pipes.quote is hidden and shouldn't be used; shlex.quote was added in Py3.3 for this purpose.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: we're currently still supporting Python 2.7; please add an import guard with fallback to importing from pipes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW they are indeed the same and was exposed in Python 3.3, although it has been present for a long time. It has been documented and deprecated at the same time in 2.7, so it's half-internal (that "private but documented" status does not make much sense ...): https://docs.python.org/2/library/pipes.html#pipes.quote

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, under the hood of CPython, pipes.quote is shlex.quote but it's messy even for them. Using shlex.quote is incontestably the cleanest way (as that's what the Standard says) to get the quote function (in Py3.3+) but I agree with you that using pipes.quote works (until it doesn't?).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess I was just lazy and did not introduce an except block for something that appeared to work in Python 3 as well, using shlex when available is definitely less confusing :)

if device is not None:
parts += ['-s', device]
parts += ['shell',
command if not as_root else f'su -c {quote(command)}']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

f-strings are introduced in Py3.6.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We're still aiming to be compatible with Python 2.7.

@ptosi
Copy link
Contributor Author

ptosi commented May 15, 2019

From #386 (comment):

I can't think of a reason other than that for the pipe, and would be happy to make the switching to using '-c' . Though it would be have to be thoroughly tested with WA/LISA before merging.

How should this testing be done?

@setrofim
Copy link
Collaborator

We can handle the testing for WA. For LISA, I believe there is a way to get it to point to an alternative branch/repo for devlib -- so just switch it over and make sure that everything still works. If it's been used for a while and nothing breaks, then we're probably good. Obviously, if LISA had it's own test suite, make sure that passes too.

@valschneider
Copy link
Contributor

valschneider commented May 20, 2019

Regarding LISA: I'll pick that up and feed it through our device tests. Will update you folks here.

@douglas-raillard-arm FYI.

if device is not None:
parts += ['-s', device]
parts += ['shell',
command if not as_root else f'echo {quote(command)} | su']
Copy link
Collaborator

Choose a reason for hiding this comment

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

formatted literal strings (f prefix) has been introduced in Python 3.6. AFAIK, devlib is still supporting (at least) Python 3.5. This version is needed to support Ubuntu 16.04 xenial, which is still used in quite a few places (AFAIK that's the most recent distro you can get on Travis).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was unable to find documentation stating which (sub-)version of Python 3 devlib was supporting (I might have missed a document or webpage?) so I assumed Py3.6.

You're right that devlib is still supporting Py3.5 but, now that the projects (incl. WA) are slowly moving away from Python 2, it is necessary to define a "minimum" version of Python 3 to be supported. I though Py3.6 made sense as it's fairly common, relatively stable (2.5 years old; bug-fix support already ended at the end of last year) and provides some valuable new features.

The f-strings have been removed from this PR but it is still necessary to define which version of Python 3 is/will be used by the projects; @setrofim & @marcbonnici ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

So for this release we will continue to be targeting older version of 3 as well as 2.7. However as @pietos01 mentioned for both WA and devlib, python 2.7 is now deprecated and support will be dropped in the next release. At the point we are enforcing a switch to python 3 we were also thinking of setting Python 3.6 as our new required version as this appears to have a large adoption and introduces a number of worthwhile changes.
I realise this has not been communicated properly so we will need to formalise this information and get feedback on our plans. @douglas-raillard-arm Do you foresee any issues with this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No worries, it eventually reaches involved people :)

So, in the current LISA landscape:

  • Travis' latest GNU/Linux environment is Ubuntu 16,04 xenial which ships with 3.5. Getting higher versions may be possible via some PPA. Travis can also install multiple version of python if we tell it it's a python project, but we can't use that since it also comes with its own (non-optional) virtualenv which conflicts with the one from LISA. (we could configure LISA to cooperate, but we want to check end-to-end install as well in a way that matches what users will do).
  • Some LAVA containers/Jenkins environment we use is using Ubuntu Xenial as well. That may be updated, but I would need to have a chat with the infra guys before committing on that. @ionela-voinescu any comment on that ?
  • Some people in our team may be using Ubuntu Xenial, I assume this can be extended to other teams, since it will be supported until 2021/2024.

All in all, we might be able to require Python >=3.6 but that means asking people to use PPA. Do you have some kind of informal list of things that are desirable in 3.6 and not in 3.5 ? (formatted literals are definitely desirable :-) but may not be big enough to warrant dropping native xenial support :-( ).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok thank you very much for the information, that's definitely something we'll need to take into account then.
We don't have such a list yet so we will need to evaluate this. In order to collate this information I've opened the issue #389 to discuss this further.

import zipfile

from pipes import quote
from shlex import quote
Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW they are indeed the same and was exposed in Python 3.3, although it has been present for a long time. It has been documented and deprecated at the same time in 2.7, so it's half-internal (that "private but documented" status does not make much sense ...): https://docs.python.org/2/library/pipes.html#pipes.quote

@marcbonnici
Copy link
Collaborator

@valschneider Just wondering if you'd had a chance to run this through your tests?

@valschneider
Copy link
Contributor

I think this got somewhat lost in the mayhem caused by our Travis issues, let me check with @douglas-raillard-arm.

@marcbonnici
Copy link
Collaborator

@pietos01 Would you be able to squash the relevant commits and update the commit messages to reflect it is no longer Python3 only?
We'd like to merge this shortly once @valschneider's tests are done.

Move from pipes.quote (private) to shlex.quote (Py3.3+ standard).

Make tests of inputs against None (their default value) instead of based
on their truthiness.

Improve logging through quoted commands (runnable as-is, less confusing).

Make the command-building process straightforward for readability and
maintainability.
Move from the current implementation (piping the command to su) which
has unexpected behaviours to the '-c' su flag (which then becomes
required).
@marcbonnici marcbonnici merged commit 6b414cc into ARM-software:master Jul 19, 2019
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.

6 participants