Skip to content

Commit

Permalink
Fix lots of PEP8 errors and warnings
Browse files Browse the repository at this point in the history
Fix plyer/playforms/macosx/libs/osx_paths.py PEP8
Fix plyer/tools/pep8checker/pep8.py PEP8
Fix plyer/tools/pep8checker/pep8kivy.py PEP8
plyer/platforms/macosx/wifi.py PEP8
Fix plyer/platforms/linux/processors.py PEP8
Fix plyer/platforms/linux/battery.py PEP8
Fix plyer/platforms/ios/keystore.py PEP8
Fix plyer/platforms/android/humidity.py PEP8
Fix plyer/facades/keystore.py PEP8
Fix plyer/facades/__init__.py PEP8
Fix docs/source/conf.py PEP8
Fix plyer/__init__.py PEP8
Fix examples/humidity/main.py PEP8
Fix examples/accelerometer/using_graph/libs/garden/garden.graph/__init__.py PEP8
Change Exception by ImportError
Fix W503 controverse error
Fix invalid syntax at plyer/platforms/win/libs/win_api_defs.py
Fix under-indented line
Fix path var scope
Fix win_api_defs issues
  • Loading branch information
Sires0 authored and tshirtman committed Jul 2, 2018
1 parent 747b7d5 commit 401f8a3
Show file tree
Hide file tree
Showing 27 changed files with 113 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -140,7 +140,7 @@ script:

pycodestyle "$(pwd)"
--exclude=pep8.py,compat.py,utils.py
--ignore=E402;
--ignore=E402,W503;

fi;
if [ "${COVERALLS}" == "1" ] && [ "${TRAVIS_BRANCH}" == "master" ]; then
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -28,7 +28,7 @@ build_script:
cd C:\projects\plyer &
%PYTHON% -m pycodestyle "%cd%"
--exclude=pep8.py,compat.py,utils.py
--ignore=E402
--ignore=E402,W503
)

%PYTHON% C:\projects\plyer\plyer\tests\dummy_setup.py
Expand Down
12 changes: 6 additions & 6 deletions docs/source/conf.py
Expand Up @@ -94,31 +94,31 @@

# -- Options for HTML output --------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# further. For a list of options available for each theme, see the
# documentation.
# html_theme_options = {}

# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []

# The name for this set of Sphinx documents. If None, it defaults to
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
# html_title = None

# A shorter title for the navigation bar. Default is the same as html_title.
# A shorter title for the navigation bar. Default is the same as html_title.
# html_short_title = None

# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
# html_logo = None

# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
# html_favicon = None

Expand Down Expand Up @@ -161,7 +161,7 @@
# html_show_copyright = True

# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
# html_use_opensearch = ''

Expand Down
Expand Up @@ -157,16 +157,16 @@ def _get_ticks(self, major, minor, log, s_min, s_max):
# differently if the last incomplete decade has a decade
# boundary in it
if floor(s_min + n_decades) != floor(s_max):
n_decades += 1 - (10 ** (s_min + n_decades + 1) - 10 **
s_max) / 10 ** floor(s_max + 1)
n_decades += 1 - (10 ** (s_min + n_decades + 1) - 10
** s_max) / 10 ** floor(s_max + 1)
else:
n_decades += ((10 ** s_max - 10 ** (s_min + n_decades)) /
10 ** floor(s_max + 1))
n_decades += ((10 ** s_max - 10 ** (s_min + n_decades))
/ 10 ** floor(s_max + 1))
# this might be larger than what is needed, but we delete
# excess later
n_ticks_major = n_decades / float(major)
n_ticks = int(floor(n_ticks_major * (minor if minor >=
1. else 1.0))) + 2
n_ticks = int(floor(n_ticks_major * (minor if minor
>= 1. else 1.0))) + 2
# in decade multiples, e.g. 0.1 of the decade, the distance
# between ticks
decade_dist = major / float(minor if minor else 1.0)
Expand All @@ -182,8 +182,8 @@ def _get_ticks(self, major, minor, log, s_min, s_max):
# first real tick location. value is in fractions of decades
# from the start we have to use decimals here, otherwise
# floating point inaccuracies results in bad values
start_dec = ceil((10 ** Decimal(s_min - s_min_low - 1)) /
Decimal(decade_dist)) * decade_dist
start_dec = ceil((10 ** Decimal(s_min - s_min_low - 1))
/ Decimal(decade_dist)) * decade_dist
count_min = (0 if not minor else
floor(start_dec / decade_dist) % minor)
start_dec += s_min_low
Expand Down Expand Up @@ -298,8 +298,8 @@ def _update_labels(self):
ylabels[k].texture_update()
ylabels[k].size = ylabels[k].texture_size
y1 = max(y1, ylabels[k].texture_size[0])
ylabels[k].pos = (x_next, y_start + (ypoints[k] - ymin) *
ratio)
ylabels[k].pos = (x_next, y_start + (ypoints[k] - ymin)
* ratio)
if len(ylabels) > 1 and ylabels[0].top > ylabels[1].y:
y_overlap = True
else:
Expand All @@ -324,8 +324,8 @@ def _update_labels(self):
# update the size so we can center the labels on ticks
xlabels[k].texture_update()
xlabels[k].size = xlabels[k].texture_size
xlabels[k].pos = (x_next + (xpoints[k] - xmin) * ratio -
xlabels[k].texture_size[0] / 2., y_next)
xlabels[k].pos = (x_next + (xpoints[k] - xmin) * ratio
- xlabels[k].texture_size[0] / 2., y_next)
if xlabels[k].x < right:
x_overlap = True
break
Expand Down Expand Up @@ -479,8 +479,8 @@ def _redraw_all(self, *args):
self.add_widget(grids[k])

mesh = self._mesh
n_points = (len(xpoints_major) + len(xpoints_minor) +
len(ypoints_major) + len(ypoints_minor))
n_points = (len(xpoints_major) + len(xpoints_minor)
+ len(ypoints_major) + len(ypoints_minor))
mesh.vertices = [0] * (n_points * 8)
mesh.indices = [k for k in xrange(n_points * 2)]
self._redraw_size()
Expand Down
1 change: 1 addition & 0 deletions examples/humidity/main.py
Expand Up @@ -63,5 +63,6 @@ def build(self):
def on_pause(self):
return True


if __name__ == "__main__":
HumidityApp().run()
1 change: 1 addition & 0 deletions examples/storagepath/main.py
Expand Up @@ -58,5 +58,6 @@ class StoragePathApp(App):
def build(self):
return StoragePathInterface()


if __name__ == "__main__":
StoragePathApp().run()
3 changes: 2 additions & 1 deletion plyer/__init__.py
Expand Up @@ -9,7 +9,8 @@
'compass', 'email', 'filechooser', 'flash', 'gps', 'gravity',
'gyroscope', 'irblaster', 'light', 'orientation', 'notification',
'proximity', 'sms', 'tts', 'uniqueid', 'vibrator', 'wifi',
'temperature', 'humidity', 'spatialorientation', 'brightness', 'storagepath','processors')
'temperature', 'humidity', 'spatialorientation', 'brightness',
'storagepath', 'processors')

__version__ = '1.3.1dev'

Expand Down
4 changes: 2 additions & 2 deletions plyer/facades/__init__.py
Expand Up @@ -10,8 +10,8 @@
'Compass', 'Email', 'FileChooser', 'GPS', 'Gravity', 'Gyroscope',
'IrBlaster', 'Light', 'Orientation', 'Notification', 'Proximity',
'Sms', 'TTS', 'UniqueID', 'Vibrator', 'Wifi', 'Flash',
'Temperature', 'Humidity', 'SpatialOrientation', 'Brightness','Processors',
'StoragePath', 'keystore')
'Temperature', 'Humidity', 'SpatialOrientation', 'Brightness',
'Processors', 'StoragePath', 'keystore')

from plyer.facades.accelerometer import Accelerometer
from plyer.facades.audio import Audio
Expand Down
2 changes: 1 addition & 1 deletion plyer/facades/keystore.py
Expand Up @@ -16,4 +16,4 @@ def get_key(self, servicename, key, **kwargs):
return self._get_key(servicename, key)

def _get_key(self, servicename, key, **kwargs):
raise NotImplementedError()
raise NotImplementedError()
2 changes: 1 addition & 1 deletion plyer/facades/storagepath.py
Expand Up @@ -94,7 +94,7 @@ def get_application_dir(self):
'''
return self._get_application_dir()

#private
# private

def _get_home_dir(self):
raise NotImplementedError()
Expand Down
4 changes: 2 additions & 2 deletions plyer/platforms/android/battery.py
Expand Up @@ -17,8 +17,8 @@ def _get_state(self):
activity.registerReceiver(None, ifilter))

query = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1)
isCharging = (query == BatteryManager.BATTERY_STATUS_CHARGING or
query == BatteryManager.BATTERY_STATUS_FULL)
isCharging = (query == BatteryManager.BATTERY_STATUS_CHARGING
or query == BatteryManager.BATTERY_STATUS_FULL)

level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
Expand Down
8 changes: 4 additions & 4 deletions plyer/platforms/android/humidity.py
Expand Up @@ -26,7 +26,7 @@ def __init__(self):

def enable(self):
self.SensorManager.registerListener(self, self.sensor,
SensorManager.SENSOR_DELAY_NORMAL)
SensorManager.SENSOR_DELAY_NORMAL)

def disable(self):
self.SensorManager.unregisterListener(self, self.sensor)
Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(self):

def enable(self):
self.SensorManager.registerListener(self, self.sensor,
SensorManager.SENSOR_DELAY_NORMAL)
SensorManager.SENSOR_DELAY_NORMAL)

def disable(self):
self.SensorManager.unregisterListener(self, self.sensor)
Expand Down Expand Up @@ -82,8 +82,8 @@ def _get_humidity(self):
Tc = self.listener_a.value
A = 6.112
K = 273.15
humidity = (Ta * (Rh / 100) * A * exp(m * Tc / (Tn + Tc)) /
(K + Tc))
humidity = (Ta * (Rh / 100) * A * exp(m * Tc / (Tn + Tc))
/ (K + Tc))
return humidity

def _enable(self):
Expand Down
5 changes: 3 additions & 2 deletions plyer/platforms/android/irblaster.py
Expand Up @@ -20,8 +20,9 @@ def _exists(self):
def multiply_pulse(self):
'''Android 4.4.3+ uses microseconds instead of period counts
'''
return not (SDK_INT == 19 and
int(str(ANDROID_VERSION.RELEASE).rsplit('.', 1)[-1]) < 3)
return not (SDK_INT == 19
and int(str(ANDROID_VERSION.RELEASE).rsplit('.', 1)[-1])
< 3)

def _get_frequencies(self):
if not ir_manager:
Expand Down
6 changes: 3 additions & 3 deletions plyer/platforms/android/tts.py
Expand Up @@ -12,9 +12,9 @@ def _speak(self, **kwargs):
tts = TextToSpeech(activity, None)
tts.setLanguage(Locale.US) # TODO: locale specification as option
retries = 0 # First try rarely succeeds due to some timing issue
while (retries < 100 and
tts.speak(kwargs.get('message').encode('utf-8'),
TextToSpeech.QUEUE_FLUSH, None) == -1):
while (retries < 100
and tts.speak(kwargs.get('message').encode('utf-8'),
TextToSpeech.QUEUE_FLUSH, None) == -1):
# -1 indicates error. Let's wait and then try again
sleep(0.1)
retries += 1
Expand Down
3 changes: 2 additions & 1 deletion plyer/platforms/ios/keystore.py
Expand Up @@ -16,7 +16,8 @@ def _get_key(self, servicename, key, **kwargs):
if ret is not None:
return ret.UTF8String()
else:
return ret
return ret


def instance():
return IosKeystore()
4 changes: 3 additions & 1 deletion plyer/platforms/linux/battery.py
Expand Up @@ -4,6 +4,7 @@

from os import environ


class LinuxBattery(Battery):
def _get_state(self):
old_lang = environ.get('LANG')
Expand All @@ -15,7 +16,7 @@ def _get_state(self):
["upower", "-d", dev],
stdout=PIPE
)
output = upower_process.communicate()[0].decode()
output = upower_process.communicate()[0].decode()
environ['LANG'] = old_lang
if not output:
return status
Expand All @@ -30,6 +31,7 @@ def _get_state(self):
status['percentage'] = percentage
return status


def instance():
import sys
if whereis_exe('upower'):
Expand Down
4 changes: 2 additions & 2 deletions plyer/platforms/linux/filechooser.py
Expand Up @@ -226,8 +226,8 @@ class LinuxFileChooser(FileChooser):
'''

desktop = None
if (str(os.environ.get("XDG_CURRENT_DESKTOP")).lower() == "kde" and
which("kdialog")):
if (str(os.environ.get("XDG_CURRENT_DESKTOP")).lower() == "kde"
and which("kdialog")):
desktop = "kde"
elif which("yad"):
desktop = "yad"
Expand Down
2 changes: 1 addition & 1 deletion plyer/platforms/linux/keystore.py
@@ -1,6 +1,6 @@
try:
import keyring
except:
except ImportError:
raise NotImplemented()
from plyer.facades import Keystore

Expand Down
4 changes: 2 additions & 2 deletions plyer/platforms/linux/processors.py
Expand Up @@ -12,7 +12,7 @@ def _get_state(self):

status = {"Number_of_Processors": None}

dev = "--all"
dev = "--all"
nproc_process = Popen(
["nproc", dev],
stdout=PIPE
Expand All @@ -23,7 +23,7 @@ def _get_state(self):

if not output:
return status

status['Number_of_Processors'] = output.rstrip()

return status
Expand Down
2 changes: 1 addition & 1 deletion plyer/platforms/macosx/keystore.py
@@ -1,6 +1,6 @@
try:
import keyring
except:
except ImportError:
raise NotImplemented()
from plyer.facades import Keystore

Expand Down
10 changes: 6 additions & 4 deletions plyer/platforms/macosx/libs/osx_paths.py
Expand Up @@ -3,9 +3,11 @@


def NSIterateSearchPaths(directory):
CoreFoundation = ctypes.cdll.LoadLibrary("/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation")
NSStartSearchPathEnumeration = CoreFoundation.NSStartSearchPathEnumeration
NSGetNextSearchPathEnumeration = CoreFoundation.NSGetNextSearchPathEnumeration
LibraryPath = ("/System/Library/Frameworks/CoreFoundation.framework/"
"Versions/A/CoreFoundation")
CoreFound = ctypes.cdll.LoadLibrary(LibraryPath)
NSStartSearchPathEnumeration = CoreFound.NSStartSearchPathEnumeration
NSGetNextSearchPathEnumeration = CoreFound.NSGetNextSearchPathEnumeration
PATH_MAX = os.pathconf('/', os.pathconf_names['PC_PATH_MAX'])
PATH_ENCODING = 'utf8'
path_buffer = ctypes.create_string_buffer(PATH_MAX)
Expand All @@ -16,4 +18,4 @@ def NSIterateSearchPaths(directory):
if state == 0:
break
path = os.path.expanduser(path_buffer.value.decode(PATH_ENCODING))
return path
return path
4 changes: 2 additions & 2 deletions plyer/platforms/macosx/wifi.py
Expand Up @@ -68,13 +68,13 @@ def ns(x):
'hessid': hessid,
'ibss': ibss,
'isAdditionalStepRequiredForAccess':
isAdditionalStepRequiredForAccess,
isAdditionalStepRequiredForAccess,
'isCarPlayNetwork': isCarPlayNetwork,
'isEmergencyServicesReachable': isEmergencyServicesReachable,
'isPasspoint': isPasspoint,
'isPersonalHotspot': isPersonalHotspot,
'isUnauthenticatedEmergencyServiceAccessible':
isUnauthenticatedEmergencyServiceAccessible,
isUnauthenticatedEmergencyServiceAccessible,
'noiseMeasurement': noiseMeasurement,
'physicalLayerMode': physicalLayerMode,
'rssiValue': rssiValue,
Expand Down
4 changes: 2 additions & 2 deletions plyer/platforms/win/filechooser.py
Expand Up @@ -64,8 +64,8 @@ def run(self):
filters += f[0] + "\x00" + ";".join(f[1:]) + "\x00"
args["Filter"] = filters

flags = (win32con.OFN_EXTENSIONDIFFERENT |
win32con.OFN_OVERWRITEPROMPT)
flags = (win32con.OFN_EXTENSIONDIFFERENT
| win32con.OFN_OVERWRITEPROMPT)
if self.multiple:
flags |= win32con.OFN_ALLOWmultiple | win32con.OFN_EXPLORER
if self.show_hidden:
Expand Down
2 changes: 1 addition & 1 deletion plyer/platforms/win/keystore.py
@@ -1,6 +1,6 @@
try:
import keyring
except:
except Exception:
raise NotImplemented()
from plyer.facades import Keystore

Expand Down

0 comments on commit 401f8a3

Please sign in to comment.