From a809cfc398cf8d80776ea664f8307ae0266e366f Mon Sep 17 00:00:00 2001 From: Simon van der Veldt Date: Tue, 8 Oct 2019 21:09:03 +0200 Subject: [PATCH] Restructure to normal python package --- .gitignore | 8 ++-- README.md | 73 ++++++++++++------------------ download.py | 5 +- requirements.txt | 5 -- setup.py | 40 ++++++++++++++++ setup.sh | 7 --- crowlib.py => src/druid/crowlib.py | 11 ++--- druid.py => src/druid/main.py | 25 +++++----- upload.py | 7 +-- 9 files changed, 96 insertions(+), 85 deletions(-) mode change 100644 => 100755 download.py delete mode 100644 requirements.txt create mode 100644 setup.py delete mode 100644 setup.sh rename crowlib.py => src/druid/crowlib.py (97%) rename druid.py => src/druid/main.py (92%) mode change 100755 => 100644 mode change 100644 => 100755 upload.py diff --git a/.gitignore b/.gitignore index 5347481..37ad17e 100644 --- a/.gitignore +++ b/.gitignore @@ -51,10 +51,8 @@ Module.symvers Mkfile.old dkms.conf -Lib/ -Scripts/ +build/ +dist/ __pycache__/ *.log -pip-selfcheck.json -pyvenv.cfg -*~ \ No newline at end of file +*~ diff --git a/README.md b/README.md index ded8ff6..0648603 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,31 @@ # druid -a basic repl for crow with some utilities +A basic REPL for crow with some utilities -## setup +## Setup -- requires python 3.5+ - - windows & osx: https://www.python.org/downloads/ - - linux: `sudo apt-get install python3 python3-pip` -- requires pyserial, asyncio, and prompt_toolkit. install & run with: +Requirements: +- Python 3.5+ + - Windows & OS X: https://www.python.org/downloads/ + - Linux: `sudo apt-get install python3 python3-pip` or equivalent +- `pip` and `setuptools` +- `pyserial` and `prompt_toolkit` -note: you might want `python` and `pip` instead of `python3` and `pip3` -depending on your platform. if `python3` is not found, check that you have -python >= 3.5 with`python --version`. +Note: you might need to use `python` and `pip` instead of `python3` and `pip3` depending on your platform. If `python3` is not found, check that you have python >= 3.5 with `python --version`. -install and run: +Install and run: ```bash -pip3 install -r requirements.txt -python3 druid.py +# Ensure setuptools is up to date +pip3 install --upgrade setuptools +# Install druid +pip3 install monome-druid +# Run druid :) +druid ``` -to avoid conflicts with other python applications on your system, -you can run in a virtualenv instead of installing dependencies -globally: -```bash -python3 -m venv . - -# windows -source Scripts/activate # need to do this each time you run a new shell - -# other -source bin/activate # need to do this each time you run a new shell - -pip install -r requirements.txt -python druid.py -``` - -## druid +## Druid -``` -python3 druid.py -``` +Start by running `druid` - type q (enter) to quit. - type h (enter) for a list of special commands. @@ -48,10 +34,10 @@ python3 druid.py - will reconnect to crow after a disconnect / restart - scrollable console history -example: +Example: ``` -t@nav: ~/druid $ python3 druid.py +druid //// druid. q to quit. h for help > x=6 @@ -64,36 +50,37 @@ t@nav: ~/druid $ python3 druid.py > q ``` -execute a lua script and enter the REPL from the command line: +Execute a lua script and enter the REPL from the command line: ``` -python3 druid.py examples/test-2.lua +druid examples/test-2.lua ``` -diagnostic logs are written to druid.log +Diagnostic logs are written to `druid.log`. -## upload +## Upload ``` python3 upload.py examples/test-2.lua ``` -uploads the provided lua file to crow & stores it in flash to be executed on boot. +Uploads the provided lua file to crow & stores it in flash to be executed on boot. -## download +## Download ``` python3 download.py ``` -prints to screen. copy to file by: +Prints to screen. +Copy to file by running: ``` python3 download.py > feathers.lua ``` -## examples +## Examples -druid comes with a bunch of example scripts to help introduce crow's syntax, and spur your imagination with some zany ideas. Here's the list with a brief description of each (most scripts have a longer description including the assignment of ins and outs at the top of the script): +Druid comes with a bunch of example scripts to help introduce crow's syntax, and spur your imagination with some zany ideas. Here's the list with a brief description of each (most scripts have a longer description including the assignment of ins and outs at the top of the script): - `boids.lua`: four simulated birds that fly around your input - `booleanlogic.lua`: logic gates determined by two input gates diff --git a/download.py b/download.py old mode 100644 new mode 100755 index f0455cb..682a62b --- a/download.py +++ b/download.py @@ -1,4 +1,6 @@ -import crowlib +#!/usr/bin/env python3 + +from druid import crowlib def main(): @@ -14,5 +16,4 @@ def main(): crow.close() exit() - main() diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 20df53b..0000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -asyncio==3.4.3 -prompt-toolkit==2.0.10 -pyserial==3.4 -six==1.12.0 -wcwidth==0.1.7 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..f10c17d --- /dev/null +++ b/setup.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +from setuptools import setup, find_namespace_packages + +# Read the contents of the readme to publish it to PyPI +with open("README.md") as readme: + long_description = readme.read() + +setup( + name="monome-druid", + version="0.1.1", + description="Terminal interface for crow", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/monome/druid", + author="monome", + author_email="bcrabtree@monome.org", + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Operating System :: OS Independent", + ], + packages=find_namespace_packages("src"), + package_dir={"": "src"}, + include_package_data=True, + python_requires=">=3.5", + install_requires=[ + "prompt-toolkit>=2.0.10", + "pyserial>=3.4", + ], + extras_require={ + "test": [ + "pylint", + ] + }, + entry_points={ + "console_scripts": [ + "druid=druid.main:main", + ], + }, +) diff --git a/setup.sh b/setup.sh deleted file mode 100644 index 4898d03..0000000 --- a/setup.sh +++ /dev/null @@ -1,7 +0,0 @@ -set -ex -python -m venv . -pip install -r requirements.txt -set +x -echo "ready. run:" -echo " source Scripts/activate" -echo "in this folder before running druid when you've opened a new shell" diff --git a/crowlib.py b/src/druid/crowlib.py similarity index 97% rename from crowlib.py rename to src/druid/crowlib.py index c3606a8..53bbdb0 100644 --- a/crowlib.py +++ b/src/druid/crowlib.py @@ -1,10 +1,11 @@ import logging +import time + import serial import serial.tools.list_ports -import time -logger = logging.getLogger(__name__) +logger = logging.getLogger(__name__) def connect(): port = "" @@ -22,7 +23,6 @@ def connect(): logger.error("could not open comport {}".format(port), e) raise ValueError("can't open serial port") - def reconnect(): try: c = crow_connect() @@ -31,7 +31,6 @@ def reconnect(): except ValueError as err: myprint(" ") - def writelines(writer, file): with open(file) as d: lua = d.readlines() @@ -47,7 +46,6 @@ def upload(writer, printer, file): time.sleep(0.1) # wait for upload to complete writer(bytes("^^w", 'utf-8')) - def execute(writer, printer, file): printer(" running "+file+"\n\r") writer(bytes("^^s", 'utf-8')) @@ -56,7 +54,6 @@ def execute(writer, printer, file): time.sleep(0.01) writer(bytes("^^e", 'utf-8')) - # leaving this here for 'run a code chunk' #def execute( writer, printer, file ): # printer(" running "+file+"\n\r") @@ -65,4 +62,4 @@ def execute(writer, printer, file): # time.sleep(0.1) # writer(bytes("```", 'utf-8')) # time.sleep(0.1) -# writer(bytes("init()\n\r", 'utf-8')) \ No newline at end of file +# writer(bytes("init()\n\r", 'utf-8')) diff --git a/druid.py b/src/druid/main.py old mode 100755 new mode 100644 similarity index 92% rename from druid.py rename to src/druid/main.py index b896e9c..5588492 --- a/druid.py +++ b/src/druid/main.py @@ -1,10 +1,5 @@ -#!/usr/bin/env python3 - -from __future__ import unicode_literals - -import logging.config import asyncio -import crowlib +import logging.config import os import sys @@ -24,6 +19,8 @@ from prompt_toolkit.widgets import TextArea from prompt_toolkit.layout.controls import FormattedTextControl +from druid import crowlib + # monkey patch to fix https://github.com/monome/druid/issues/8 Char.display_mappings['\t'] = ' ' @@ -98,12 +95,14 @@ def crowparser(text): async def shell(): global crow - input_field = TextArea(height=1, prompt='> ', style='class:input-field', multiline=False, wrap_lines=False - ) + input_field = TextArea(height=1, prompt='> ', style='class:input-field', multiline=False, + wrap_lines=False) captures = VSplit([capture1, capture2]) - container = HSplit([captures, output_field, Window(height=1, char='/', style='class:line', content=FormattedTextControl(text='druid////'), align=WindowAlign.RIGHT - ), input_field - ]) + container = HSplit([captures, output_field, + Window(height=1, char='/', style='class:line', + content=FormattedTextControl(text='druid////'), + align=WindowAlign.RIGHT), + input_field]) def cwrite(xs): global crow @@ -133,7 +132,7 @@ def _(event): ('capture-field', '#747369'), ('output-field', '#d3d0c8'), ('input-field', '#f2f0ec'), - ('line', '#747369'), + ('line', '#747369'), ]) application = Application( @@ -188,7 +187,7 @@ def main(): 'detailed': { 'class': 'logging.Formatter', 'format': '%(asctime)s %(name)-15s %(levelname)-8s' - '%(processName)-10s %(message)s' + '%(processName)-10s %(message)s' }, }, 'handlers': { diff --git a/upload.py b/upload.py old mode 100644 new mode 100755 index ef00b5a..e0254f0 --- a/upload.py +++ b/upload.py @@ -1,12 +1,14 @@ +#!/usr/bin/env python3 + import sys -import crowlib import time +from druid import crowlib + def myprint(st): print(st) - def main(): try: crow = crowlib.connect() @@ -28,5 +30,4 @@ def main(): crow.close() exit() - main()