diff --git a/.travis.yml b/.travis.yml index e3ddf3535aab86881baac684f4f87fc7a6c65194..b6c9f3daed84dd6b52d73cfabac6300a99d0bbed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ install: - pip install tox script: - tox -e $TOX_ENV +before_deploy: make schema deploy: provider: pypi user: flyte diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..b4013d6879bc5b6a8987c0b83de6b6d4f25aa1b6 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +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 {} \; diff --git a/config.schema.yml b/config.schema.yml index 06ba987d81c5c6bce4c5c1ac5e885d5802e99661..8eec9d4dc8625ef884e9c94b7896d4e4306f3d35 100644 --- a/config.schema.yml +++ b/config.schema.yml @@ -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 diff --git a/pi_mqtt_gpio/__init__.py b/pi_mqtt_gpio/__init__.py index 6eef5129070ac17b4efcfb48235aaf63333f24b2..329e6d8a80b662d6db51283325db2c2e52285604 100644 --- a/pi_mqtt_gpio/__init__.py +++ b/pi_mqtt_gpio/__init__.py @@ -1,119 +1,4 @@ -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) diff --git a/pi_mqtt_gpio/__init__.py.die b/pi_mqtt_gpio/__init__.py.die new file mode 100644 index 0000000000000000000000000000000000000000..329e6d8a80b662d6db51283325db2c2e52285604 --- /dev/null +++ b/pi_mqtt_gpio/__init__.py.die @@ -0,0 +1,4 @@ +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) diff --git a/pi_mqtt_gpio/__init__.py.template b/pi_mqtt_gpio/__init__.py.template new file mode 100644 index 0000000000000000000000000000000000000000..ce1c782e538208f8ee75e2957468580f5162f7a5 --- /dev/null +++ b/pi_mqtt_gpio/__init__.py.template @@ -0,0 +1,5 @@ +import yaml + +CONFIG_SCHEMA = yaml.load(""" +$config_schema +""") diff --git a/setup.py b/setup.py index 76d8cb87c6671fca7a1a7a51fe2f1f1408db25ed..b00b93ea53bb4c76d3db700660ca465e0e0ca54f 100644 --- a/setup.py +++ b/setup.py @@ -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",