openatx / uiautomator2

Android Uiautomator2 Python Wrapper
MIT License
6.59k stars 1.41k forks source link

[feature] console_scripts entry point :: init() #237

Closed gamesguru closed 6 months ago

gamesguru commented 6 years ago

The idea

Within setup.py we should have a console script such as uia2init.

It would be cooler and easier to type. It could receive args, by default init all devices, or accept an argument --serial <serial> to single out a particular device.

Notes

Support for python3 -m uiautomator2 init could be maintained. Other arguments could be supplied too.

Possibly have a 2nd console_script to list off alive devices, that are init'd ?

gamesguru commented 5 years ago
  1. init all
  2. health check all
  3. all_devices.service('uiautomator').stop()

Agreed these are good to give unique script names, or more suggestions? before I start pull request i wanted to ask. @mingyuan-xia @codeskyblue

mingyuan-xia commented 5 years ago

not sure how well setup.py works across OS platforms. Why do you need to stop all devices' uiautomator in that?

gamesguru commented 5 years ago

Why

If I want to run uiautomatorviewer, or manual adb shell commands... it is faster when uia2 daemon is stopped. Otherwise lags. And is (would be) quite helpful when tracking and resolving issues across 1 computer with 20 android devices.

This feature would allow users to perform common commands, like python3 -m uiautomator2 init and a proposed stopall, while typing only short, easy to remember commands, e.g. u2init and u2kill

Then we can design arguments, e.g. --serial, or --model with rough match via regex.

How

Difference between entry_points/console_scripts and scripts in setup.py, is that scripts only works on mac/Linux. But console_scripts also generates binary "uia2init.exe" file which can be called on Windows' cmd line.

You can try that with pip3 install nutri and then see nutri -h is working across all OS platforms. See setup.py file for example on how to do this.

    entry_points={
        'console_scripts': [
            'nutri=libnutri.nutri:main',
        ],
    },

nutri is what you type into command line, libnutri is target folder, nutri.py is main python file therewithin, and main is target function to call out.

With uiautomator2 project, the init function nested under MyFire object, it is possibly correct: 'u2init=__main__.MyFire.init',

But someone should test this, who has push access to the PyPI page.

mingyuan-xia commented 5 years ago

ok stopall makes sense. About retrofitting --serial, right now there is an ugly workaround as Fire might interpret args as a float: https://github.com/openatx/uiautomator2/blob/master/uiautomator2/__main__.py#L334 As we are working to change that, we might also wipe out this stupid thing as well. Need to get to know nutri first.

gamesguru commented 5 years ago

nutri is a work in progress, the argument parsing logic is one of the few complete features.

I was the one who suggested the ugly workaround. https://github.com/openatx/uiautomator2/pull/216/commits

It is due to the way Fire parses command line arguments.

bash and cmd.exe interpreters (which are used in nutri) do not interpret as floats. But this transition from Fire to shell, it would require many changes.

mingyuan-xia commented 5 years ago

ok I only had some experience with click and the basic argparser, none with fire and nutri. I am open to a more intuitive and clear cmdline parser.

codeskyblue commented 5 years ago

actually there is an entry script named u2cli, sometimes it works sometimes not

gamesguru commented 5 years ago

so should we do the entry point, or no?? I can start it

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.