Skip to content

Make modules out of the plugins #207

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

Merged
merged 5 commits into from
Jun 4, 2020
Merged

Make modules out of the plugins #207

merged 5 commits into from
Jun 4, 2020

Conversation

JonasVautherin
Copy link
Collaborator

@JonasVautherin JonasVautherin commented Jun 3, 2020

An issue we have in the current system (where all the files are generated in mavsdk/generated) is that we don't have any namespacing between them. Therefore, from mavsdk import MissionItem could import MissionItem from Mission, or from MissionRaw. In this case, it broke the examples/mission.py example.

I therefore made a module out of each plugin, so that import mavsdk.mission is a thing, and one could from mavsdk.mission_raw import MissionItem as MissionRawItem, if needed.

I had to make a few changes for that:

  • Remove the globals() use in system.py, mainly because I did not really understand how it worked
  • Generate the files directly in mavsdk/, because I could not make the modules thing work in mavsdk/generated/ without ending up with imports of the form from mavsdk.generated.mission import .... Maybe there is a way, I just did not find it.
  • Update the scripts here and there to generate files accordingly
  • Update the examples

I tested the examples and it seems to be working for me. I would be glad if @petergerten could confirm that it fixes the mission example 😊.

I did not test against the docs generation (mainly because it's getting late), but I wanted @julianoes' opinion first.

Note: I tried to make commits that make sense for the review, so the auto-generation is isolated in two commits 😇.

Fixes #200

@JonasVautherin JonasVautherin requested a review from julianoes June 3, 2020 21:22
@@ -2,7 +2,7 @@

import asyncio

from mavsdk import (CameraError, Mode)
from mavsdk.camera import (CameraError, Mode)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would be tempted to just do:

from mavsdk import camera

and then access it using:

camera.Mode

That's possible, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes that's possible, too. Or just import mavsdk and then use mavsdk.camera.Mode. I think it's really up to the user 👍.

@JonasVautherin
Copy link
Collaborator Author

Thanks for the review! I'll try to look into the documentation side sometime next week, because I probably broke it. In the meantime I hope that @petergerten can work from this branch for the missions.

@julianoes julianoes merged commit 7abf4df into master Jun 4, 2020
@julianoes julianoes deleted the fix-200 branch June 4, 2020 13:49
@julianoes
Copy link
Collaborator

It's a bit odd. Now I need to import mavsdk.action.action to get the docs working. This seems like one nesting too much 🤔.

@JonasVautherin
Copy link
Collaborator Author

Also in the code? In my testing, in the code I could do mavsdk.action.ActionResult... Maybe the docs needs a path and not a module (because it's mavsdk/action/action.py)

@julianoes
Copy link
Collaborator

import mavsdk
help(mavsdk.action):

Help on package mavsdk.action in mavsdk:

NAME
    mavsdk.action

PACKAGE CONTENTS
    action
    action_pb2
    action_pb2_grpc

FILE
    /home/julianoes/src/MAVSDK-Python/mavsdk/action/__init__.py
help(mavsdk.action.action)

Help on module mavsdk.action.action in mavsdk.action:

NAME
    mavsdk.action.action - # -*- coding: utf-8 -*-

CLASSES
    builtins.Exception(builtins.BaseException)
        ActionError
    builtins.object
        ActionResult
    mavsdk._base.AsyncBase(builtins.object)
        Action
    
    class Action(mavsdk._base.AsyncBase)
     |  Action(async_plugin_manager)
     |  
     |  Enable simple actions such as arming, taking off, and landing.
     |  
     |  Generated by dcsdkgen - MAVSDK Action API
     |  
     |  Method resolution order:
     |      Action
     |      mavsdk._base.AsyncBase
     |      builtins.object
     |  
     |  Methods defined here:
     |  
     |  async arm(self)
     |      Send command to arm the drone.
     |      
     |      Arming a drone normally causes motors to spin at idle.
     |      Before arming take all safety precautions and stand clear of the drone!
     |      
     |      Raises
     |      ------
     |      ActionError
     |          If the request fails. The error contains the reason for the failure.
...
help(mavsdk.action.Action):

Help on class Action in module mavsdk.action.action:

class Action(mavsdk._base.AsyncBase)
 |  Action(async_plugin_manager)
 |  
 |  Enable simple actions such as arming, taking off, and landing.
 |  
 |  Generated by dcsdkgen - MAVSDK Action API
 |  
 |  Method resolution order:
 |      Action
 |      mavsdk._base.AsyncBase
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  async arm(self)
 |      Send command to arm the drone.
 |      
 |      Arming a drone normally causes motors to spin at idle.
 |      Before arming take all safety precautions and stand clear of the drone!
 |      
 |      Raises
 |      ------
 |      ActionError
 |          If the request fails. The error contains the reason for the failure.
...

@JonasVautherin
Copy link
Collaborator Author

Doesn't seem wrong to me. Is it?

mavsdk.action.Action is the class, and mavsdk.action.action is the action.py file.

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.

mission.py example broken (type object 'MissionItem' has no attribute 'CameraAction')
2 participants