Skip to content

Commit

Permalink
removed references of the switch mqtt API (#18)
Browse files Browse the repository at this point in the history
* removed references of the switch mqtt API as Slac will be open sourced and Switch API shall not be exposed. This also forced a redisign of the lib, namely the way we start slac

* reformatted the code

* Updated the README explaining how to run the examples and spawn a matching task process; reformatted the code

* added end of line to cs_configuration.json file

* added end of line to the Dockerfile

* solved some typos and removed more mqtt references

* added the root dir to get the cs_configuration file saved in the examples

* added full path to cs config file to the multiple slac sessions example as well

* added faster way to open the config file in the example
  • Loading branch information
tropxy authored Apr 26, 2022
1 parent 9871ade commit 94c16e9
Show file tree
Hide file tree
Showing 15 changed files with 429 additions and 599 deletions.
4 changes: 0 additions & 4 deletions .env.dev.docker
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# MQTT Settings
MQTT_HOST=mqtt
MQTT_PORT=9001

# SLAC Settings
SLAC_INIT_TIMEOUT=1000

Expand Down
5 changes: 0 additions & 5 deletions .env.dev.local
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# MQTT Settings
MQTT_HOST=localhost
MQTT_PORT=9001


# SLAC Settings
SLAC_INIT_TIMEOUT=1000

Expand Down
18 changes: 4 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Build image
FROM python:3.10.0-buster as build

ARG PYPI_USER
ARG PYPI_PASS

WORKDIR /usr/src/app

ENV PYTHONFAULTHANDLER=1 \
Expand All @@ -23,8 +20,6 @@ RUN pip install "poetry==$POETRY_VERSION"
# However, if we run poetry config virtualenvs.create false, then we dont.
# Do not create a virtual poetry env as we already are in an isolated container
RUN poetry config virtualenvs.create false
# Set the credentials
RUN poetry config http-basic.pypi-switch $PYPI_USER $PYPI_PASS
# pylintrc, coveragerc, poetry.lock and pyproject.toml shall not change very
# often, so it is a good idea to add them as soon as possible
COPY .coveragerc pyproject.toml poetry.lock ./
Expand All @@ -48,21 +43,16 @@ RUN poetry build
# Runtime image (which is smaller than the build one)
FROM python:3.10.0-buster

ARG PYPI_USER
ARG PYPI_PASS

WORKDIR /usr/src/app

# create virtualenv
RUN python -m venv /venv

COPY --from=build /usr/src/app/dist/ dist/
COPY --from=build /usr/src/app/slac/examples/cs_configuration.json .


# This will install the wheels in the venv
# We need to specify the Switch Pypis server as extra-index to look for, in
# order to install switch custom libs
RUN /venv/bin/pip install dist/*.whl --extra-index-url https://$PYPI_USER:$PYPI_PASS@pypi.switch-ev.com/simple
# This will install the wheel in the venv
RUN /venv/bin/pip install dist/*.whl

# This will run the entrypoint script defined in the pyproject.toml
CMD /venv/bin/slac
CMD /venv/bin/python3 /venv/lib/python3.10/site-packages/slac/examples/single_slac_session.py
48 changes: 16 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ help:
@echo " run-local-sudo runs the app locally using prod settings and root privileges"
@echo " poetry-update updates the dependencies in poetry.lock"
@echo " install-local installs slac into the current environment"
@echo " set-credentials sets the Switch PyPi credentials directly into pyroject.toml. Use this recipe with caution"
@echo " tests run all the tests"
@echo " reformat reformats the code, using Black"
@echo " flake8 flakes8 the code"
@echo " release version=<mj.mn.p> bumps the project version to <mj.mn.p>, using poetry;"
@echo " deploy deploys the project using Poetry (not recommended, only use if really needed)"
@echo ""
@echo "Check the Makefile to know exactly what each target is doing."

Expand All @@ -36,10 +34,6 @@ help:
# The @ is to surpress the output of the evaluation
@if [ ${IS_LINUX_OS} -eq 0 ]; then echo "This Recipe is not available in non-Linux Systems"; exit 3; fi

.check-env-vars:
@test $${PYPI_USER?Please set environment variable PYPI_USER}
@test $${PYPI_PASS?Please set environment variable PYPI_PASS}

.deps:
@if [ -z ${IS_POETRY} ]; then pip install poetry; fi
@if [ -z ${IS_TWINE} ]; then pip install twine; fi
Expand All @@ -50,39 +44,33 @@ docs:
tests: .check-os
poetry run pytest -vv tests

build: .check-env-vars
build:
docker-compose build

dev: .check-env-vars
# the dev file apply changes to the original compose file
dev:
# the dev file apply changes to the original compose file
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up

run: .check-env-vars
run:
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up

poetry-config: .check-env-vars
@# For external packages, poetry saves metadata
@# in it's cache which can raise versioning problems, if the package
@# suffered version support changes. Thus, we clean poetry cache
yes | poetry cache clear --all mqtt_api
poetry config http-basic.pypi-switch ${PYPI_USER} ${PYPI_PASS}
poetry-update:
poetry update

set-credentials: .check-env-vars
@# Due to a Keyring issue under Ubuntu systems, the password configuration does not work as expected: https://github.com/python-poetry/poetry/issues/4902
@# As so, instead we use sed to substitute the credentials.
sed -i.bkp "s@https://pypi.switch-ev.com/simple/@https://${PYPI_USER}:${PYPI_PASS}\@pypi.switch-ev.com/simple/@g" pyproject.toml
install-local:
pip install .

poetry-update: poetry-config
poetry update
run-local-single:
python slac/examples/single_slac_session.py

install-local: .check-env-vars
pip install . --extra-index-url https://${PYPI_USER}:${PYPI_PASS}@pypi.switch-ev.com/simple
run-local-multiple:
python slac/examples/multiple_slac_sessions.py

run-local:
python slac/main.py
run-local-sudo-single:
sudo $(shell which python) slac/examples/single_slac_session.py

run-local-sudo:
sudo $(shell which python) slac/main.py
run-local-sudo-multiple:
sudo $(shell which python) slac/examples/multiple_slac_sessions.py

run-ev-slac:
sudo $(shell which python) slac/examples/ev_slac_scapy.py
Expand All @@ -105,7 +93,3 @@ release: .install-poetry
@echo "Please remember to update the CHANGELOG.md, before tagging the release"
@poetry version ${version}

deploy: .check-env-vars .deps build bump-version
poetry config repo.pypi-switch https://pypi.switch-ev.com/
poetry config http-basic.pypi-switch ${PYPI_USER} ${PYPI_PASS}
poetry publish -r pypi-switch
Loading

0 comments on commit 94c16e9

Please sign in to comment.