mirror of
https://github.com/tiny-pilot/tinypilot.git
synced 2021-09-19 22:56:27 +03:00
Initial commit
This commit is contained in:
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright 2019 Michael Lynch
|
||||
Copyright 2020 Michael Lynch
|
||||
|
||||
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:
|
||||
|
||||
|
||||
26
README.md
26
README.md
@@ -1,17 +1,8 @@
|
||||
# Python3 Seed
|
||||
|
||||
[](https://circleci.com/gh/mtlynch/python3_seed)
|
||||
# PiKVM Backend
|
||||
|
||||
## Overview
|
||||
|
||||
A boilerplate Python 3 project set up for unit tests and continuous integration.
|
||||
|
||||
Specifically:
|
||||
|
||||
* Enforces Python style rules with [YAPF](https://github.com/google/yapf)
|
||||
* Enforces style rules on docstrings using [DocStringChecker](https://chromium.googlesource.com/chromiumos/chromite/+/master/cli/cros/lint.py)
|
||||
* Perfoms static analysis with [pyflakes](https://github.com/megies/pyflakes)
|
||||
* Sorts imports with [isort](https://github.com/timothycrosley/isort)
|
||||
The backend for PiKVM.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -24,19 +15,8 @@ pip install --requirement dev_requirements.txt
|
||||
hooks/enable_hooks
|
||||
```
|
||||
|
||||
## Customization
|
||||
|
||||
To customize this for your project:
|
||||
|
||||
1. Change `COPYRIGHT` to your name.
|
||||
1. Change `LICENSE` to [a license of your choosing](https://choosealicense.com/).
|
||||
1. Change the CircleCI badge in `README.md` to your own Circle CI project badge.
|
||||
1. Change the app name in `app/main.py` from `Python Seed` to your app's name.
|
||||
1. Rename `app/dummy.py` and `tests/test_dummy.py` to the module names of your choosing.
|
||||
1. Begin working.
|
||||
|
||||
## Run
|
||||
|
||||
```bash
|
||||
./app/main.py
|
||||
./serve
|
||||
```
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
"""Dummy module.
|
||||
|
||||
Dummy module to exercise unit test code. Replace this with actual application
|
||||
logic.
|
||||
"""
|
||||
|
||||
|
||||
def dummy():
|
||||
return 'dummy'
|
||||
49
app/main.py
49
app/main.py
@@ -1,32 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
import dummy
|
||||
import flask
|
||||
|
||||
root_logger = logging.getLogger()
|
||||
handler = logging.StreamHandler()
|
||||
formatter = logging.Formatter(
|
||||
'%(asctime)s %(name)-15s %(levelname)-4s %(message)s', '%Y-%m-%d %H:%M:%S')
|
||||
handler.setFormatter(formatter)
|
||||
root_logger.addHandler(flask.logging.default_handler)
|
||||
root_logger.setLevel(logging.INFO)
|
||||
|
||||
app = flask.Flask(__name__)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info('Starting app')
|
||||
|
||||
|
||||
def configure_logging():
|
||||
root_logger = logging.getLogger()
|
||||
handler = logging.StreamHandler()
|
||||
formatter = logging.Formatter(
|
||||
'%(asctime)s %(name)-15s %(levelname)-4s %(message)s',
|
||||
'%Y-%m-%d %H:%M:%S')
|
||||
handler.setFormatter(formatter)
|
||||
root_logger.addHandler(handler)
|
||||
root_logger.setLevel(logging.INFO)
|
||||
@app.route('/virtual-keyboard', methods=['OPTIONS'])
|
||||
def virtual_keyboard_options():
|
||||
response = flask.jsonify({})
|
||||
response.headers.add('Access-Control-Allow-Origin', '*')
|
||||
response.headers.add('Access-Control-Allow-Headers', 'Content-Type, Accept')
|
||||
return response
|
||||
|
||||
|
||||
def main(args):
|
||||
configure_logging()
|
||||
logger.info('Started runnning')
|
||||
print(dummy.dummy())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='Python Seed',
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
main(parser.parse_args())
|
||||
@app.route('/virtual-keyboard', methods=['POST'])
|
||||
def virtual_keyboard_post():
|
||||
payload = flask.request.json
|
||||
response = flask.jsonify(payload)
|
||||
response.headers.add('Access-Control-Allow-Origin', '*')
|
||||
return response
|
||||
7
build
7
build
@@ -12,9 +12,6 @@ set -u
|
||||
# Location of app source files.
|
||||
SOURCE_DIR=app
|
||||
|
||||
# Location of unit tests.
|
||||
TEST_DIR=tests
|
||||
|
||||
# Location of virtualenv.
|
||||
VIRTUALENV_DIR=venv
|
||||
|
||||
@@ -50,8 +47,8 @@ isort \
|
||||
--skip-glob=venv/*
|
||||
|
||||
# Run static analysis for Python bugs/cruft.
|
||||
pyflakes "${SOURCE_DIR}/" "${TEST_DIR}/"
|
||||
pyflakes "${SOURCE_DIR}/"
|
||||
|
||||
# Check docstrings for style consistency.
|
||||
PYTHONPATH="$(pwd)/third_party/docstringchecker" \
|
||||
pylint --reports=n --rcfile=.pylintrc "$SOURCE_DIR" "$TEST_DIR"
|
||||
pylint --reports=n --rcfile=.pylintrc "$SOURCE_DIR"
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Run this from the repository root to enable all git hooks for this project.
|
||||
rm -rf .git/hooks/ && ln -s -f ../hooks .git/hooks
|
||||
1
hooks/hooks
Symbolic link
1
hooks/hooks
Symbolic link
@@ -0,0 +1 @@
|
||||
../hooks
|
||||
@@ -1 +0,0 @@
|
||||
./build
|
||||
@@ -0,0 +1 @@
|
||||
Flask==1.1.1
|
||||
12
serve
Executable file
12
serve
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit build script on first failure.
|
||||
set -e
|
||||
|
||||
# Echo commands to stdout.
|
||||
set -x
|
||||
|
||||
# Exit on unset variable.
|
||||
set -u
|
||||
|
||||
FLASK_APP=app/main.py flask run -h 0.0.0.0 -p 8000
|
||||
@@ -1,10 +0,0 @@
|
||||
import unittest
|
||||
|
||||
from app import dummy
|
||||
|
||||
|
||||
class DummyTest(unittest.TestCase):
|
||||
"""Replace this with a real unit test class."""
|
||||
|
||||
def test_dummy(self):
|
||||
self.assertEqual('dummy', dummy.dummy())
|
||||
Reference in New Issue
Block a user