77import urllib .request
88import os
99import stat
10- import sys
10+ import platform
1111import subprocess
1212
1313
@@ -50,9 +50,10 @@ class custom_build(build):
5050 @property
5151 def platform_suffix (self ):
5252 """
53- Trying to detect the platform to know which `mavsdk_server` executable to download
53+ Trying to detect the platform to know which `mavsdk_server` executable
54+ to download
5455 """
55- if sys . platform .startswith ( 'linux' ) and 'MAVSDK_SERVER_ARCH' in os .environ :
56+ if platform .system () == 'Linux' and 'MAVSDK_SERVER_ARCH' in os .environ :
5657 if os .environ ['MAVSDK_SERVER_ARCH' ] == "armv6l" :
5758 return 'linux-armv6-musl'
5859 elif os .environ ['MAVSDK_SERVER_ARCH' ] == "armv7l" :
@@ -61,24 +62,34 @@ def platform_suffix(self):
6162 return 'linux-arm64-musl'
6263 else :
6364 raise NotImplementedError (
64- f"Error: unknown MAVSDK_SERVER_ARCH: { os .environ ['MAVSDK_SERVER_ARCH' ]} " )
65- elif sys .platform .startswith ('linux' ):
65+ "Error: unknown MAVSDK_SERVER_ARCH: "
66+ f"{ os .environ ['MAVSDK_SERVER_ARCH' ]} " )
67+ elif platform .system () == 'Linux' :
6668 return 'musl_x86_64'
67- elif sys .platform .startswith ('darwin' ):
68- return 'macos'
69- elif sys .platform .startswith ('win' ):
69+ elif platform .system () == 'Darwin' :
70+ if platform .processor () == 'i386' :
71+ return 'macos_x64'
72+ elif platform .processor () == 'arm' :
73+ return 'macos_arm64'
74+ raise NotImplementedError (
75+ f"Error: unknown macOS processor: { platform .processor ()} " )
76+ elif platform .system () == 'Windows' \
77+ and platform .processor ().startswith ('AMD64' ):
7078 return 'win32.exe'
7179 else :
7280 raise NotImplementedError (
73- f"Error: mavsdk_server is not distributed for platform { sys .platform } (yet)! You should set the 'MAVSDK_BUILD_PURE=ON' environment variable and get mavsdk_server manually." )
81+ "Error: mavsdk_server is not distributed for platform "
82+ f"{ platform .system ()} ({ platform .processor ()} ) (yet)!\n \n "
83+ "You should set the 'MAVSDK_BUILD_PURE=ON' environment "
84+ "variable and get mavsdk_server manually." )
7485
7586 @property
7687 def mavsdk_server_filepath (self ):
7788 """
7889 The location of the downloaded `mavsdk_server` binary
7990 For Windows this needs to be a .exe file
8091 """
81- if sys . platform .startswith ( 'win' ) :
92+ if platform .system () == 'Windows' :
8293 return 'mavsdk/bin/mavsdk_server.exe'
8394 else :
8495 return 'mavsdk/bin/mavsdk_server'
@@ -97,7 +108,8 @@ def mavsdk_server_url(self):
97108 """
98109 Build the url of the `mavsdk_server` binary
99110 """
100- return f"https://github.com/mavlink/MAVSDK/releases/download/{ self .mavsdk_server_tag } /mavsdk_server_{ self .platform_suffix } "
111+ return "https://github.com/mavlink/MAVSDK/releases/download/" \
112+ f"{ self .mavsdk_server_tag } /mavsdk_server_{ self .platform_suffix } "
101113
102114 def run (self ):
103115 if 'MAVSDK_BUILD_PURE' not in os .environ :
@@ -107,7 +119,8 @@ def run(self):
107119
108120 def download_mavsdk_server (self ):
109121 print (
110- f"downloading { self .mavsdk_server_url } into { self .mavsdk_server_filepath } " )
122+ f"downloading { self .mavsdk_server_url } into "
123+ f"{ self .mavsdk_server_filepath } " )
111124 urllib .request .urlretrieve (
112125 self .mavsdk_server_url ,
113126 filename = self .mavsdk_server_filepath )
0 commit comments