Skip to content

Commit

Permalink
Restructure to normal python package
Browse files Browse the repository at this point in the history
  • Loading branch information
simonvanderveldt committed Oct 9, 2019
1 parent c05f409 commit a809cfc
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 85 deletions.
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ Module.symvers
Mkfile.old
dkms.conf

Lib/
Scripts/
build/
dist/
__pycache__/
*.log
pip-selfcheck.json
pyvenv.cfg
*~
*~
73 changes: 30 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions download.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import crowlib
#!/usr/bin/env python3

from druid import crowlib


def main():
Expand All @@ -14,5 +16,4 @@ def main():
crow.close()
exit()


main()
5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

40 changes: 40 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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",
],
},
)
7 changes: 0 additions & 7 deletions setup.sh

This file was deleted.

11 changes: 4 additions & 7 deletions crowlib.py → src/druid/crowlib.py
Original file line number Diff line number Diff line change
@@ -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 = ""
Expand All @@ -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()
Expand All @@ -31,7 +31,6 @@ def reconnect():
except ValueError as err:
myprint(" <lost connection>")


def writelines(writer, file):
with open(file) as d:
lua = d.readlines()
Expand All @@ -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'))
Expand All @@ -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")
Expand All @@ -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'))
# writer(bytes("init()\n\r", 'utf-8'))
25 changes: 12 additions & 13 deletions druid.py → src/druid/main.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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'] = ' '
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -133,7 +132,7 @@ def _(event):
('capture-field', '#747369'),
('output-field', '#d3d0c8'),
('input-field', '#f2f0ec'),
('line', '#747369'),
('line', '#747369'),
])

application = Application(
Expand Down Expand Up @@ -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': {
Expand Down
7 changes: 4 additions & 3 deletions upload.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -28,5 +30,4 @@ def main():
crow.close()
exit()


main()

0 comments on commit a809cfc

Please sign in to comment.