Skip to content
Snippets Groups Projects
Commit cc8805f1 authored by Ellis Percival's avatar Ellis Percival
Browse files

Add code to insert the config schema before building.

parent 0beff71a
Branches
Tags
No related merge requests found
......@@ -8,6 +8,7 @@ install:
- pip install tox
script:
- tox -e $TOX_ENV
before_deploy: make schema
deploy:
provider: pypi
user: flyte
......
Makefile 0 → 100644
schema:
python setup.py insert_schema
packages: schema sdist wheel2 wheel3 clean
sdist: schema
python setup.py sdist
wheel2: schema
python2 setup.py bdist_wheel
wheel3: schema
python3 setup.py bdist_wheel
clean:
cp pi_mqtt_gpio/__init__.py.die pi_mqtt_gpio/__init__.py
rm -rf .cache .eggs build *.egg-info
find pi_mqtt_gpio -type d -name __pycache__ -exec rm -rf {} \;
......@@ -35,6 +35,22 @@ mqtt:
allowed:
- "3.1"
- "3.1.1"
status_topic:
type: string
required: no
default: status
status_payload_running:
type: string
required: no
default: running
status_payload_stopped:
type: string
required: no
default: stopped
status_payload_dead:
type: string
required: no
default: dead
gpio_modules:
type: list
......
import yaml
CONFIG_SCHEMA = yaml.load("""
mqtt:
type: dict
required: yes
schema:
host:
type: string
empty: no
required: no
default: localhost
port:
type: integer
min: 1
max: 65535
required: no
default: 1883
user:
type: string
required: no
default: ""
password:
type: string
required: no
default: ""
topic_prefix:
type: string
required: no
default: ""
coerce: rstrip_slash
protocol:
type: string
required: no
empty: no
coerce: tostring
default: "3.1.1"
allowed:
- "3.1"
- "3.1.1"
gpio_modules:
type: list
required: yes
schema:
type: dict
allow_unknown: yes
schema:
name:
type: string
required: yes
empty: no
module:
type: string
required: yes
empty: no
digital_inputs:
type: list
required: no
default: []
schema:
type: dict
schema:
name:
type: string
required: yes
empty: no
module:
type: string
required: yes
empty: no
pin:
type: integer
required: yes
min: 0
on_payload:
type: string
required: yes
empty: no
off_payload:
type: string
required: yes
empty: no
pullup:
type: boolean
required: no
default: no
pulldown:
type: boolean
required: no
default: no
digital_outputs:
type: list
required: no
default: []
schema:
type: dict
schema:
name:
type: string
required: yes
module:
type: string
required: yes
pin:
type: integer
required: yes
min: 0
on_payload:
type: string
required: no
empty: no
off_payload:
type: string
required: no
empty: no
""")
import sys
print("FATAL ERROR: The file at pi_mqtt_gpio/__init__.py should be replaced us"
"ing 'make schema' before packaging.")
sys.exit(1)
import sys
print("FATAL ERROR: The file at pi_mqtt_gpio/__init__.py should be replaced us"
"ing 'make schema' before packaging.")
sys.exit(1)
import yaml
CONFIG_SCHEMA = yaml.load("""
$config_schema
""")
......@@ -5,13 +5,18 @@ Setuptools script for the pi-mqtt-gpio project.
import os
from textwrap import fill, dedent
from string import Template
from distutils.core import Command
try:
from setuptools import setup, find_packages
from setuptools.command.build_py import build_py
except ImportError:
from ez_setup import use_setuptools
use_setuptools()
from setuptools import setup, find_packages
from setuptools.command.build_py import build_py
def required(fname):
......@@ -22,9 +27,31 @@ def required(fname):
).read().split('\n')
class SchemaCommand(Command):
user_options = []
def run(self):
if self.dry_run:
return
with open("pi_mqtt_gpio/__init__.py.template") as f_templ:
templ = Template(f_templ.read())
with open("config.schema.yml") as f_schema:
with open("pi_mqtt_gpio/__init__.py", "w") as f_out:
f_out.write(templ.substitute(config_schema=f_schema.read()))
f_out.flush()
def initialize_options(self):
pass
def finalize_options(self):
pass
setup(
name="pi_mqtt_gpio",
version="0.0.12",
cmdclass={"insert_schema": SchemaCommand},
packages=find_packages(
exclude=[
"*.tests",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment