From 1c59f7240743ea9ca720d1795bfb2758ac4952e1 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Fri, 21 Dec 2018 12:45:00 +0100 Subject: [PATCH] fake-api: init --- LICENSE | 21 ++++++++ README.md => README.rst | 4 ++ _pbport.py | 7 --- movehub.py | 30 ----------- pblight.py | 108 ---------------------------------------- pbsensor.py | 24 --------- pybricks/__init__.py | 0 pybricks/parameters.py | 7 +++ setup.py | 33 ++++++++++++ 9 files changed, 65 insertions(+), 169 deletions(-) create mode 100644 LICENSE rename README.md => README.rst (59%) delete mode 100644 _pbport.py delete mode 100644 movehub.py delete mode 100644 pblight.py delete mode 100644 pbsensor.py create mode 100644 pybricks/__init__.py create mode 100644 pybricks/parameters.py create mode 100644 setup.py diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e9663c4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Laurens Valk and David Lechner + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.rst similarity index 59% rename from README.md rename to README.rst index 99da3ab..7c20c79 100644 --- a/README.md +++ b/README.rst @@ -4,3 +4,7 @@ Fake Pybricks This is a standard Python 3.x library that provides the Pybricks API with a totally fake implementation. It is used to provide documentation and type hints for code completion. + +Local install for developers: Navigate to this directory and then run +``python3 setup.py sdist bdist_wheel`` +``pip3 install --user -e .`` diff --git a/_pbport.py b/_pbport.py deleted file mode 100644 index da51c0e..0000000 --- a/_pbport.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Private base class for ports""" - -from enum import Enum - - -class Port(Enum): - pass diff --git a/movehub.py b/movehub.py deleted file mode 100644 index 79a8428..0000000 --- a/movehub.py +++ /dev/null @@ -1,30 +0,0 @@ -"""This module is for the LEGO BOOST Move Hub.""" - -import _pbport - -from pblight import Light -from pbsensor import TouchSensor - - -class Port(_pbport.Port): - """The ports on the LEGO BOOST Move Hub""" - HUB = -1 - """The Move Hub itself""" - - A = ord('A') - """Built-in motor 'A'""" - - B = ord('B') - """Built-in motor 'B'""" - - C = ord('C') - """I/O port 'C'""" - - D = ord('D') - """I/O port 'D'""" - -button = TouchSensor(Port.HUB) -"""The button on the Move Hub""" - -light = Light(Port.HUB) -"""The light on the Move Hub""" diff --git a/pblight.py b/pblight.py deleted file mode 100644 index 9906299..0000000 --- a/pblight.py +++ /dev/null @@ -1,108 +0,0 @@ -"""Lights can be built into programmable bricks or can be plugged into I/O -ports.""" - -from collections import namedtuple -from enum import Enum -from typing import Union - -from _pbport import Port - - -class Color(Enum): - """Color names""" - - red = 1 - """The light will be red""" - - orange = 2 - """The light will be orange""" - - yellow = 3 - """The light will be yellow""" - - green = 4 - """The light will be green""" - - blue = 5 - """The light will be blue""" - - purple = 6 - """The light will be purple""" - - white = 7 - """The light will be white""" - -RGB = namedtuple('RGB', 'r g b') -"""Red, green, blue value""" - - -class Pattern(Enum): - """Blink patterns""" - - flash = 1 - """The light will alternate between *color1* and *color2* once per - second""" - - fade = 2 - """The light will fade gradually from *color1* to *color2* and back once - per second""" - - -class Light(): - """Class representing a light""" - def __init__(self, port: Port): - """Creates a new instance - - Args: - port: the port the light is connected to - """ - self._port = port - - def on(self, color: Union[Color, RGB, None]) -> None: - """Turns the light on with the specified color - - Args: - color: the color - """ - pass - - def off(self) -> None: - pass - - def blink(self, color1: Union[Color, RGB, None], - color2: Union[Color, RGB, None], pattern: Pattern) -> None: - """Blinks the light using the specified pattern - - Args: - color1: the first color in the pattern - color2: the second color in the pattern - pattern: the pattern - """ - pass - - @property - def has_red(self) -> bool: - """Checks if the light can be red - - Returns: - ``True`` if the light can be red - """ - return False - - @property - def has_green(self) -> bool: - """Checks if the light can be green - - Returns: - ``True`` if the light can be green - """ - return False - - @property - def has_blue(self) -> bool: - """Checks if the light can be blue - - Returns: - ``True`` if the light can be blue - """ - return False diff --git a/pbsensor.py b/pbsensor.py deleted file mode 100644 index 76532a9..0000000 --- a/pbsensor.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Sensors are input devices.""" - -from _pbport import Port - - -class TouchSensor(): - """Represents a touch sensor with two states, pressed and released""" - def __init__(self, port: Port): - """Creates a new instance - - Raises: - ValueError: The *port* is not a valid port - RuntimeError: There is not a touch sensor connected to this port - """ - self._port = port - - @property - def is_pressed(self) -> bool: - """Checks if the touch sensor is pressed. - - Returns: - ``True`` if the sensor is pressed, otherwise ``False`` - """ - return False diff --git a/pybricks/__init__.py b/pybricks/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pybricks/parameters.py b/pybricks/parameters.py new file mode 100644 index 0000000..8e6f392 --- /dev/null +++ b/pybricks/parameters.py @@ -0,0 +1,7 @@ +"""Constant parameters/arguments for the Pybricks API.""" + + +class Color(): + """LED colors or detected surface colors.""" + + red = 5 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..17aa2ee --- /dev/null +++ b/setup.py @@ -0,0 +1,33 @@ +"""pypi compatible setup module. + +This setup is based on: +https://packaging.python.org/tutorials/distributing-packages/ + + +""" +from setuptools import setup +from codecs import open +from os import path + + +here = path.abspath(path.dirname(__file__)) +with open(path.join(here, 'README.rst'), encoding='utf-8') as f: + long_description = f.read() + +setup( + name='pybricks', + version='0.1', + description='Pybricks', + long_description=long_description, + url='https://github.com/pybricks', + author='Laurens Valk and David Lechner', + author_email='laurensvalk@gmail.com', + classifiers=[ + 'Development Status :: 3 - Alpha', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 3', + ], + keywords='lego mindstorms ev3', + python_requires='>=3', + packages=['pybricks'], +)