Skip to content

Commit 8222193

Browse files
committed
Server refactor, add tests and coverage
1 parent 520d5b9 commit 8222193

File tree

23 files changed

+415
-11
lines changed

23 files changed

+415
-11
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.py[cod]
2+
.venv
23

34
# C extensions
45
*.so
@@ -34,3 +35,6 @@ nosetests.xml
3435
.mr.developer.cfg
3536
.project
3637
.pydevproject
38+
39+
# IDE files
40+
.idea

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ Server for GPIO Controller phone applications
44

55
## Directions
66

7-
1. Copy the Python files (.py) to your Raspberry Pi
8-
2. Ensure your Raspberry Pi distro is up to date (# yum/apt-get upgrade)
9-
3. Install python3, python3-flask, and flask-cors
10-
4. As root, run the command "python PiServer.py"
11-
5. Use `curl` commands to test the server until the phone applications are updated to use the new implementation. Example: `curl -X GET http://localhost:5000/get-pin-value/7` or `curl -X POST http://localhost:5000/set-pin-value/7/1`
7+
1. Clone this repository into your Raspberry Pi
8+
2. Create a virtualenv environment and install the dependencies
9+
3. As root (because of Pin permissions), start the server
10+
4. Have fun!
1211

13-
## New to Version 2
14-
15-
* Server now implements a Flask server instead of a raw socket connection
16-
* This breaks the related phone applications until they are updated with the new interface
17-
* Networking and Pi functionality are separated for better modularity
18-
* Removing PWM functionality to favor logical HIGH and LOW outputs
12+
## Version 3
13+
This is the third rewrite of this server, but this should be the easiest to interact with.
14+
Main features for this version are:
15+
* FastAPI usage instead of Flask
16+
* This allows for OpenAPI clients to interact with the server
17+
* Cleaner code

pyproject.toml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "pi-phone-server"
7+
version = "3.0.0"
8+
dependencies = [
9+
"fastapi",
10+
"uvicorn"
11+
]
12+
requires-python = ">=3.10"
13+
authors = [
14+
{name = "Peter Muller"}
15+
]
16+
description = "REST server for interacting with Raspberry Pi GPIO pins"
17+
readme = "README.md"
18+
license = {file = "LICENSE"}
19+
keywords = ["raspberrypi", "raspberry", "pi", "server"]
20+
21+
[project.optional-dependencies]
22+
test = [
23+
"coverage",
24+
"pytest"
25+
]
26+
raspi = [
27+
"RPi.GPIO"
28+
]
29+
30+
[project.urls]
31+
Repository = "https://github.com/petermuller/pi-phone-server"
32+
33+
[tool.pytest.ini_options]
34+
addopts = "--junitxml=build/test_report.xml"
35+
36+
[tool.coverage.run]
37+
branch = true
38+
command_line = "-m pytest"
39+
source_pkgs = [
40+
"pi_phone_server"
41+
]
42+
omit = [
43+
"test/*"
44+
]
45+
46+
[tool.coverage.report]
47+
ignore_errors = false
48+
fail_under = 50
49+
format = "markdown"
50+
51+
[tool.coverage.xml]
52+
output = "build/coverage.xml"
53+
54+
[tool.coverage.html]
55+
directory = "build/coverage_html_report"

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fastapi
2+
uvicorn

setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/user/bin/env python
2+
3+
import setuptools
4+
5+
if __name__ == "__main__":
6+
setuptools.setup()

src/pi_phone_server/__init__.py

Whitespace-only changes.

src/pi_phone_server/exception/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class InvalidOperationError(RuntimeError):
2+
pass
3+
4+
5+
class InvalidPinError(RuntimeError):
6+
pass

src/pi_phone_server/model/__init__.py

Whitespace-only changes.

src/pi_phone_server/model/api/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)