Skip to content

Commit

Permalink
Fix flake8 errors in pgzero
Browse files Browse the repository at this point in the history
  • Loading branch information
lordmauve committed Nov 15, 2019
1 parent 92909ee commit 566c149
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 27 deletions.
6 changes: 4 additions & 2 deletions pgzero/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def in_elastic(n):
q -= 1.0
return -(pow(2, 10 * q) * sin((q - s) * (2 * pi) / p))


@tweener
def out_elastic(n):
p = .3
Expand All @@ -58,6 +59,7 @@ def out_elastic(n):
return 1.0
return pow(2, -10 * q) * sin((q - s) * (2 * pi) / p) + 1.0


@tweener
def in_out_elastic(n):
p = .3 * 1.5
Expand Down Expand Up @@ -116,9 +118,9 @@ def tween(n, start, end):

def tween_attr(n, start, end):
if isinstance(start, tuple):
return tuple(tween(n, a, b) for a,b in zip(start, end))
return tuple(tween(n, a, b) for a, b in zip(start, end))
elif isinstance(start, list):
return [tween(n, a, b) for a,b in zip(start, end)]
return [tween(n, a, b) for a, b in zip(start, end)]
else:
return tween(n, start, end)

Expand Down
10 changes: 10 additions & 0 deletions pgzero/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@
from .constants import mouse, keys, keymods

from .game import exit

__all__ = [
'Actor', 'images', # graphics
'sounds', 'music', 'tone', # sound
'clock', 'animate', # timing
'Rect', 'ZRect', # geometry
'keyboard', 'mouse', 'keys', 'keymods', # input
'storage', # persistence
'exit',
]
2 changes: 2 additions & 0 deletions pgzero/clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Event:
Events are ordered by their scheduled execution time.
"""

def __init__(self, time, cb, repeat=None):
self.time = time
self.repeat = repeat
Expand Down Expand Up @@ -82,6 +83,7 @@ class Clock:
scaling dt before passing it to tick().
"""

def __init__(self):
self.t = 0
self.fired = False
Expand Down
3 changes: 2 additions & 1 deletion pgzero/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
DEPRECATED_KEY_RE = re.compile(r'[A-Z]')
PREFIX_RE = re.compile(r'^K_(?!\d$)')


class Keyboard:
"""The current state of the keyboard.
Expand All @@ -23,7 +24,7 @@ class Keyboard:
def __getattr__(self, kname):
# return is a reserved word, so alias enter to return
if kname == 'enter':
kname = 'return'
kname = 'return'
elif DEPRECATED_KEY_RE.match(kname):
warn(
"Uppercase keyboard attributes (eg. keyboard.%s) are "
Expand Down
9 changes: 6 additions & 3 deletions pgzero/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os.path
import sys

from types import ModuleType
import pygame.image
import pygame.mixer

Expand Down Expand Up @@ -33,6 +32,7 @@ def set_root(path):
class InvalidCase(Exception):
"""Indicate case errors early so they don't bite cross-platform users."""


try:
import win32api
except ImportError:
Expand Down Expand Up @@ -86,6 +86,7 @@ class ResourceLoader:
Dotted paths can be used to traverse directories.
"""

def __init__(self, subpath):
self._subpath = subpath
self._cache = {}
Expand Down Expand Up @@ -162,13 +163,14 @@ def __getattr__(self, name):

def __dir__(self):
standard_attributes = [key for key in self.__dict__.keys()
if not key.startswith("_")]
if not key.startswith("_")]
resources = os.listdir(self._root())
resource_names = [os.path.splitext(r) for r in resources]
loadable_names = [name for name, ext in resource_names
if name.isidentifier() and ext[1:] in self.EXTNS]
if name.isidentifier() and ext[1:] in self.EXTNS]
return standard_attributes + loadable_names


class ImageLoader(ResourceLoader):
EXTNS = ['png', 'gif', 'jpg', 'jpeg', 'bmp']
TYPE = 'image'
Expand Down Expand Up @@ -232,6 +234,7 @@ def _load(self, path, fontsize=None):
sounds = SoundLoader('sounds')
fonts = FontLoader('fonts')


def getfont(
fontname=None,
fontsize=None,
Expand Down
1 change: 1 addition & 0 deletions pgzero/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class _MusicLoader(ResourceLoader):
def _load(self, path):
return path


_loader = _MusicLoader('music')


Expand Down
4 changes: 4 additions & 0 deletions pgzero/ptext.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def wrap(text, fontname=None, fontsize=None, sysfontname=None,
lines.append(line)
return lines


_fit_cache = {}


Expand Down Expand Up @@ -199,6 +200,7 @@ def _resolveangle(angle):
angle %= 360
return int(round(angle / ANGLE_RESOLUTION_DEGREES)) * ANGLE_RESOLUTION_DEGREES


# Return the set of points in the circle radius r, using Bresenham's
# circle algorithm
_circle_cache = {}
Expand All @@ -224,6 +226,7 @@ def _circlepoints(r):
points.sort()
return points


_surf_cache = {}
_surf_tick_usage = {}
_surf_size_total = 0
Expand Down Expand Up @@ -370,6 +373,7 @@ def getsurf(text, fontname=None, fontsize=None, sysfontname=None, bold=None, ita
_tick += 1
return surf


_default_surf_sentinel = ()


Expand Down
18 changes: 18 additions & 0 deletions pgzero/rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,60 +187,70 @@ def __contains__(self, other):

def _get_width(self):
return self.w

def _set_width(self, width):
self.w = width
width = property(_get_width, _set_width)

def _get_height(self):
return self.h

def _set_height(self, height):
self.h = height
height = property(_get_height, _set_height)

def _get_top(self):
return self.y

def _set_top(self, top):
self.y = top
top = property(_get_top, _set_top)

def _get_left(self):
return self.x

def _set_left(self, left):
self.x = left
left = property(_get_left, _set_left)

def _get_right(self):
return self.x + self.w

def _set_right(self, right):
self.x = right - self.w
right = property(_get_right, _set_right)

def _get_bottom(self):
return self.y + self.h

def _set_bottom(self, bottom):
self.y = bottom - self.h
bottom = property(_get_bottom, _set_bottom)

def _get_centerx(self):
return self.x + (self.w / 2)

def _set_centerx(self, centerx):
self.x = centerx - (self.w / 2)
centerx = property(_get_centerx, _set_centerx)

def _get_centery(self):
return self.y + (self.h / 2)

def _set_centery(self, centery):
self.y = centery - (self.h / 2)
centery = property(_get_centery, _set_centery)

def _get_topleft(self):
return self.x, self.y

def _set_topleft(self, topleft):
self.x, self.y = topleft
topleft = property(_get_topleft, _set_topleft)

def _get_topright(self):
return self.x + self.w, self.y

def _set_topright(self, topright):
x, y = topright
self.x = x - self.w
Expand All @@ -249,6 +259,7 @@ def _set_topright(self, topright):

def _get_bottomleft(self):
return self.x, self.y + self.h

def _set_bottomleft(self, bottomleft):
x, y = bottomleft
self.x = x
Expand All @@ -257,6 +268,7 @@ def _set_bottomleft(self, bottomleft):

def _get_bottomright(self):
return self.x + self.w, self.y + self.h

def _set_bottomright(self, bottomright):
x, y = bottomright
self.x = x - self.w
Expand All @@ -265,6 +277,7 @@ def _set_bottomright(self, bottomright):

def _get_midtop(self):
return self.x + self.w / 2, self.y

def _set_midtop(self, midtop):
x, y = midtop
self.x = x - self.w / 2
Expand All @@ -273,6 +286,7 @@ def _set_midtop(self, midtop):

def _get_midleft(self):
return self.x, self.y + self.h / 2

def _set_midleft(self, midleft):
x, y = midleft
self.x = x
Expand All @@ -281,6 +295,7 @@ def _set_midleft(self, midleft):

def _get_midbottom(self):
return self.x + self.w / 2, self.y + self.h

def _set_midbottom(self, midbottom):
x, y = midbottom
self.x = x - self.w / 2
Expand All @@ -289,6 +304,7 @@ def _set_midbottom(self, midbottom):

def _get_midright(self):
return self.x + self.w, self.y + self.h / 2

def _set_midright(self, midright):
x, y = midright
self.x = x - self.w
Expand All @@ -297,6 +313,7 @@ def _set_midright(self, midright):

def _get_center(self):
return self.x + self.w / 2, self.y + self.h / 2

def _set_center(self, center):
x, y = center
self.x = x - self.w / 2
Expand All @@ -305,6 +322,7 @@ def _set_center(self, center):

def _get_size(self):
return self.w, self.h

def _set_size(self, size):
self.w, self.h = size
size = property(_get_size, _set_size)
Expand Down
25 changes: 10 additions & 15 deletions pgzero/runner.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
from . import storage
from . import clock
from . import loaders
from .game import PGZeroGame, DISPLAY_FLAGS
from types import ModuleType
import argparse
import warnings
import sys
import os
import pygame
pygame.mixer.pre_init(frequency=22050, size=-16, channels=2)
pygame.init()


import os
import sys
import warnings
import argparse
from types import ModuleType

from .game import PGZeroGame, DISPLAY_FLAGS
from . import loaders
from . import clock
from . import builtins
from . import storage


# The base URL for Pygame Zero documentation
DOCS_URL = 'http://pygame-zero.readthedocs.io/en/stable'

Expand Down Expand Up @@ -63,15 +59,14 @@ def _substitute_full_framework_python():
os.execv(framework_python, ['python', '-m', 'pgzero'] + sys.argv[1:])



def main():
# Pygame won't run from a normal virtualenv copy of Python on a Mac
if not _check_python_ok_for_pygame():
_substitute_full_framework_python()

parser = argparse.ArgumentParser()
try:
import ptpython
import ptpython # noqa: checking if this is importable
except ImportError:
replhelp = argparse.SUPPRESS
have_repl = False
Expand Down
5 changes: 3 additions & 2 deletions pgzero/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,18 @@ def filled_rect(self, rect, color):

def text(self, *args, **kwargs):
"""Draw text to the screen."""
#FIXME: expose ptext parameters, for autocompletion and autodoc
# FIXME: expose ptext parameters, for autocompletion and autodoc
ptext.draw(*args, surf=self._surf, **kwargs)

def textbox(self, *args, **kwargs):
"""Draw text to the screen, wrapped to fit a box"""
#FIXME: expose ptext parameters, for autocompletion and autodoc
# FIXME: expose ptext parameters, for autocompletion and autodoc
ptext.drawbox(*args, surf=self._surf, **kwargs)


class Screen:
"""Interface to the screen."""

def __init__(self, surface):
self.surface = surface
self.width, self.height = surface.get_size()
Expand Down
1 change: 1 addition & 0 deletions pgzero/soundfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

class MagicReader:
"""Interface to reading the magic numbers in a file's header."""

def __init__(self, path):
with open(path, 'rb') as f:
self.bytes = f.read(64 * 1024)
Expand Down
2 changes: 1 addition & 1 deletion pgzero/spellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def warn_event_handlers(self, typos, missing):
for found, suggestion in typos:
print(" {found} (did you mean {suggestion}?)".format(
found=found, suggestion=suggestion))
for f in missing_hooks:
for f in missing:
print(" ", f)

def error(self, msg, found, suggestion):
Expand Down

0 comments on commit 566c149

Please sign in to comment.