Skip to content

Commit 4fadaec

Browse files
committed
💚 Fix CI failures
Resolve flake8 failures introduced in #836 by wrapping long lines, fixing continuation indentation, restoring expected module spacing, and removing unused global declarations. Update the macOS devicename test to mock the new NSHost-based implementation instead of socket.gethostname(), matching the code path now used by the platform implementation.
1 parent 91b2770 commit 4fadaec

10 files changed

Lines changed: 71 additions & 33 deletions

File tree

plyer/facades/orientation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Orientation:
4242

4343
def get_orientation(self) -> str:
4444
'''
45-
Return current screen rotation (landscape, landscape-reversed, portrait, portrait-reversed, unknown)
45+
Return current screen rotation.
4646
'''
4747
return self._get_landscape()
4848

plyer/platforms/android/devicename.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def _get_device_name(self):
2727
SettingsGlobal = autoclass('android.provider.Settings$Global')
2828

2929
context = PythonActivity.mActivity
30-
name = SettingsGlobal.getString(context.getContentResolver(), SettingsGlobal.DEVICE_NAME)
30+
name = SettingsGlobal.getString(
31+
context.getContentResolver(), SettingsGlobal.DEVICE_NAME
32+
)
3133

3234
if not name:
3335
name = Build.MODEL

plyer/platforms/android/keystore.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,32 @@ def decrypt_value(self, servicename, data):
6565
def get_secret_key(servicename):
6666
KeyProperties = autoclass('android.security.keystore.KeyProperties')
6767
KeyGenerator = autoclass('javax.crypto.KeyGenerator')
68-
KeyGenParameterSpec = autoclass('android.security.keystore.KeyGenParameterSpec$Builder')
68+
KeyGenParameterSpec = autoclass(
69+
'android.security.keystore.KeyGenParameterSpec$Builder'
70+
)
6971
KeyStore = autoclass('java.security.KeyStore')
7072

7173
key_store = KeyStore.getInstance("AndroidKeyStore")
7274
key_store.load(None)
7375

7476
if not key_store.containsAlias(servicename):
75-
builder = KeyGenParameterSpec(servicename,
76-
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
77-
builder.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
78-
builder.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
79-
key_gen = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore")
80-
key_gen.init(builder.build())
81-
key_gen.generateKey()
82-
83-
return key_store.getKey(servicename, None)
84-
85-
def instance():
86-
return AndroidKeystore()
77+
purpose = (
78+
KeyProperties.PURPOSE_ENCRYPT |
79+
KeyProperties.PURPOSE_DECRYPT
80+
)
81+
builder = KeyGenParameterSpec(servicename, purpose)
82+
builder.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
83+
builder.setEncryptionPaddings(
84+
KeyProperties.ENCRYPTION_PADDING_NONE
85+
)
86+
key_gen = KeyGenerator.getInstance(
87+
KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore"
88+
)
89+
key_gen.init(builder.build())
90+
key_gen.generateKey()
91+
92+
return key_store.getKey(servicename, None)
93+
94+
95+
def instance():
96+
return AndroidKeystore()

plyer/platforms/android/orientation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def _get_orientation(self):
4747
Surface.ROTATION_270: 'landscape-reversed',
4848
}
4949

50-
rotation = activity.getWindowManager().getDefaultDisplay().getRotation()
50+
rotation = (
51+
activity.getWindowManager().getDefaultDisplay().getRotation()
52+
)
5153

5254
return orientations.get(rotation, 'unknown')
5355

plyer/platforms/linux/orientation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ def _get_orientation(self, **kwargs):
3030
self.screen = self.screen.decode('utf-8').split('\n')[0]
3131

3232
try:
33+
command = (
34+
f"xrandr -q --verbose | grep {self.screen} | "
35+
"sed 's/primary //' | awk '{print $5}'"
36+
)
3337
orientation = sb.check_output(
34-
f"xrandr -q --verbose | grep {self.screen} | sed 's/primary //' | awk '{{print $5}}'",
38+
command,
3539
shell=True
3640
).decode('utf-8').strip()
3741
except Exception:

plyer/platforms/linux/wifi.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ def _connected_ssid(self, interface=None):
120120
self._enable()
121121

122122
ssid = None
123-
ssid_proc = Popen(['nmcli', '-t', '-f', 'ACTIVE,NAME', 'connection'], stdout=PIPE)
123+
ssid_proc = Popen(
124+
['nmcli', '-t', '-f', 'ACTIVE,NAME', 'connection'],
125+
stdout=PIPE
126+
)
124127
ssid_lines = ssid_proc.communicate()[0].decode('utf-8').splitlines()
125128
for ssid_line in ssid_lines:
126129
active, ssid_value = ssid_line.split(':')
@@ -379,7 +382,10 @@ def _connected_ssid(self, interface=None):
379382
self._enable()
380383

381384
ssid = None
382-
ssid_proc = Popen(['nmcli', '-t', '-f', 'ACTIVE,NAME', 'connection'], stdout=PIPE)
385+
ssid_proc = Popen(
386+
['nmcli', '-t', '-f', 'ACTIVE,NAME', 'connection'],
387+
stdout=PIPE
388+
)
383389
ssid_lines = ssid_proc.communicate()[0].decode('utf-8').splitlines()
384390
for ssid_line in ssid_lines:
385391
active, ssid_value = ssid_line.split(':')

plyer/platforms/macosx/gps.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,26 @@ def _run_loop(self):
4040
while self._run_loop_thread_allow:
4141
if self._is_running:
4242
next_date = NSDate.dateWithTimeIntervalSinceNow_(0.01)
43-
self._run_loop.runMode_beforeDate_('NSDefaultRunLoopMode', next_date)
43+
self._run_loop.runMode_beforeDate_(
44+
'NSDefaultRunLoopMode', next_date
45+
)
4446
time.sleep(0.1)
4547

4648
def _start(self, **kwargs):
4749
if not hasattr(self, '_location_manager'):
48-
self.on_status('provider-disabled', 'standard-macos-provider: denied')
50+
self.on_status(
51+
'provider-disabled', 'standard-macos-provider: denied'
52+
)
4953
return
5054

5155
min_distance = kwargs.get('minDistance')
5256
self._location_manager.distanceFilter = min_distance
5357

5458
if self._location_manager.authorizationStatus == 2:
5559
if self.on_status:
56-
self.on_status('provider-disabled', 'standard-macos-provider: denied')
60+
self.on_status(
61+
'provider-disabled', 'standard-macos-provider: denied'
62+
)
5763

5864
self._location_manager.startUpdatingLocation()
5965
self._is_running = True

plyer/platforms/macosx/wifi.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ def _start_scanning(self, interface=None):
110110
for i in range(cnt):
111111
if scan.allObjects().objectAtIndex_(i).ssid is not None:
112112
try:
113+
network = scan.allObjects().objectAtIndex_(i)
113114
self.names[
114-
scan.allObjects().objectAtIndex_(i).ssid.UTF8String()
115-
] = scan.allObjects().objectAtIndex_(i)
115+
network.ssid.UTF8String()
116+
] = network
116117
except Exception:
117118
pass
118119
else:

plyer/platforms/win/libs/wifi_defs.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ def _connect(network, parameters):
290290
'''
291291
Attempts to connect to a specific network.
292292
'''
293-
global _dict
294293
wireless_interface = _dict[network]
295294

296295
wcp = WLAN_CONNECTION_PARAMETERS()
@@ -480,9 +479,6 @@ def _get_network_info(name):
480479
'''
481480
returns the list of the network selected in a dict.
482481
'''
483-
global available
484-
global _dict
485-
486482
net = _dict[name]
487483
dot11BssType = net.dot11BssType
488484
dot11DefaultAuthAlgorithm = net.dot11DefaultAuthAlgorithm
@@ -505,7 +501,6 @@ def _make_dict():
505501
'''
506502
Prepares a dict so it could store network information.
507503
'''
508-
global available
509504
global _dict
510505
_dict = {}
511506
for network in available:
@@ -516,7 +511,6 @@ def _get_available_wifi():
516511
'''
517512
returns the available wifi networks.
518513
'''
519-
global _dict
520514
return _dict
521515

522516

plyer/tests/test_devicename.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,22 @@ def test_devicename_macosx(self):
6565
)
6666
devicename_instance = devicename.instance()
6767

68-
with patch.object(socket,
69-
'gethostname',
70-
return_value='mocked_macosx_hostname'
68+
class LocalizedName:
69+
@staticmethod
70+
def UTF8String():
71+
return 'mocked_macosx_hostname'
72+
73+
class CurrentHost:
74+
localizedName = LocalizedName()
75+
76+
class NSHost:
77+
@staticmethod
78+
def currentHost():
79+
return CurrentHost()
80+
81+
with patch.object(devicename,
82+
'autoclass',
83+
return_value=NSHost
7184
) as _:
7285

7386
evaluated_device_name = devicename_instance.device_name

0 commit comments

Comments
 (0)