Skip to content

one line import #420#447

Merged
dwalton76 merged 2 commits intoev3dev:developfrom
dwalton76:one-line-import
Feb 1, 2018
Merged

one line import #420#447
dwalton76 merged 2 commits intoev3dev:developfrom
dwalton76:one-line-import

Conversation

@dwalton76
Copy link
Copy Markdown
Collaborator

Example:

import ev3dev2.auto as ev3

ts = ev3.TouchSensor(ev3.INPUT_1)

Example:

    import ev3dev2.auto as ev3

    ts = ev3.TouchSensor(ev3.INPUT_1)
@dwalton76
Copy link
Copy Markdown
Collaborator Author

I am not married to this approach, this is just the first way to solve this that popped in my head.

@dwalton76
Copy link
Copy Markdown
Collaborator Author

@WasabiFan do you know of a way to make the CI tests run again? It failed for some non-obvious reason.

@ddemidov
Copy link
Copy Markdown
Member

It looks like the problem with tests was on Travis-CI side. I've restarted the build and it passed this time.

Copy link
Copy Markdown
Member

@ddemidov ddemidov left a comment

Choose a reason for hiding this comment

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

I like this. Also, it is optional, so if someone does not like the approach (for example, because it loads modules that are unnecessary for the current robot), there is always an option to do it manually instead.

@dwalton76
Copy link
Copy Markdown
Collaborator Author

Thanks Denis

yeah seems like this makes it about as easy as it can get but with the penalty of slower startup times due to import every module. Will leave this open for a day so folks have a chance to look at it and then will merge.

@WasabiFan
Copy link
Copy Markdown
Member

This seems reasonable to me. We need to figure out whether we want to recommend the "auto" module or individual imports in e.g. the README (in my WIP PR it uses the individual ones). Also, one of the first things on my to-do list is properly supporting Micropython; I'll need to modify this to exclude some modules in that environment, I think.

@dwalton76
Copy link
Copy Markdown
Collaborator Author

My preference would be to steer folks towards explicitly importing only what they need, that is more of standard python best practice and it makes it more obvious as to where to look to find the code you are using.

Something I need to test is how long importing everything takes with and without from ev3dev2.control.webserver import *. My memory is that the from http.server import BaseHTTPRequestHandler, HTTPServer that webserver.py does is very slow, we may need to exclude from ev3dev2.control.webserver import * from auto.py. The majority of folks won't use this anyway.

@WasabiFan
Copy link
Copy Markdown
Member

Agreed. In fact, I'd say the same about GyroBalancer and rc_tank.

@dwalton76
Copy link
Copy Markdown
Collaborator Author

k I am going to drop the from ev3dev2.control imports and then merge

Example:

    import ev3dev2.auto as ev3

    ts = ev3.TouchSensor(ev3.INPUT_1)
@dwalton76 dwalton76 merged commit b8026b5 into ev3dev:develop Feb 1, 2018
@dwalton76 dwalton76 deleted the one-line-import branch February 1, 2018 02:22
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.

3 participants