Skip to content

Commit

Permalink
Initial commit: extracted slac code from switch/josev and adapted Doc…
Browse files Browse the repository at this point in the history
…kerfile to install correctly the project .whl
  • Loading branch information
tropxy committed Nov 20, 2021
0 parents commit 0077a95
Show file tree
Hide file tree
Showing 112 changed files with 9,588 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[run]
omit =
tests*
examples*
setup.py
56 changes: 56 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[flake8]
max-line-length = 88
inline-quotes = "
ignore = D204
ignore-decorators=property
rst-roles =
class,
func,
ref,
rst-directives =
envvar,
exception,
extend-ignore =
ANN101,ANN102,
D100, D101, D104,
# See https://github.com/PyCQA/pycodestyle/issues/373
E203,E231,
W503,
# Google Python style is not RST until after processed by Napoleon
# See https://github.com/peterjc/flake8-rst-docstrings/issues/17
RST201,RST203,RST301,RST210
P101,
N812,
WPS110,WPS111,WPS114,
WPS201,WPS202,WPS210,WPS211,WPS214,WPS221,WPS226,WPS229,WPS232,WPS300,WPS305
WPS306,WPS323,WPS326,WPS332,WPS337,
WPS402,WPS412,
WPS437,
WPS600,WPS602
# Trailing comma check is incompatible with black
# since flake8 applies it to single-line cases as well
C812,
max-arguments = 6
per-file-ignores =
# Allow the following in tests:
# - asserts (S101)
# - shadowing variables, which would object to Pytest fixtures (WPS442)
# - arbitrarily long function names (WPS118)
# - more than seven test functions per file (WPS202)
# - Missing docstring in public module (D100)
# - Missing docstring in public function (D103)
# - Overused expression: 8 > 7 (WPS204)
# - Found too many arguments: 6 > 5 (WPS211)
# - Found too many `assert` statements: 6 > 5 (WPS218)
# - Calling "private" methods, for testing purposes (WPS437)
tests/*:S101,WPS442,WPS118,WPS202,D100, D103, WPS211, WPS218
test_*:S101,WPS442,WPS118,WPS202,WPS204,WPS211,WPS218,WPS437,D100,D103
# Allow the following in __init__ files:
# Unused imports, since this is to enable their use elsewhere (F401)
__init__.py: F401
tests/*:ANN201,D100,D102,D103,S101,WPS114,WPS115,WPS118,WPS202,WPS204,WPS210,WPS218,WPS221,WPS232,WPS407,WPS420,WPS421,WPS430,WPS432,WPS437,WPS442,WPS501,WPS600,WPS609
9 changes: 9 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# lines starting with a `#` will be ignored.
# Each line is a file pattern followed by one or more owners.

# For more info about the structure and rules, check:
# https://docs.gitlab.com/ee/user/project/code_owners.html

@tropxy


120 changes: 120 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
.pytest_cache/
# C extensions
*.so
# .bkp files
*.bkp
# Dockerfiles inside evcc and secc
iso15118/evcc/Dockerfile
iso15118/secc/Dockerfile
iso15118/iso15118/evcc/Dockerfile
iso15118/iso15118/secc/Dockerfile
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
AUTHORS
ChangeLog
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
.static_storage/
.media/
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.idea/*

# Generated X.509 certificates, private keys, and PKCS12 container files
*.pem
*.der
*.key
*.p12
iso15118/shared/pki/csrs
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Change log

## Empty for now, but this is the generic template of the changelog

## Unreleased

### Improvements

### Bug fixes

## 0.1.0 (2021-11-20)

- Initial release.
100 changes: 100 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Build image
FROM python:3.10.0-buster as build

ARG PYPI_USER
ARG PYPI_PASS

WORKDIR /usr/src/app

ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.1.11 \
VIRTUALENV_PIP=21.2.1


# create virtualenv
RUN python -m venv /venv
# Make sure we use the virtualenv:
ENV PATH="/venv/bin:$PATH"

# This is needed if we use pip wheel
RUN pip install wheel

RUN pip install "poetry==$POETRY_VERSION"
# Due to an issue with Python 3.10 and poetry, if we use a poetry virtual env,
# we need to disable the option: poetry config experimental.new-installer false
# check https://github.com/python-poetry/poetry/issues/4210
# 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 ./
# Update the dependencies and install them in the env
RUN poetry update

# Copy the project to the system and install all dependencies
COPY . ./
RUN poetry install --no-interaction --no-ansi
# Run the tests and linting for slac (as we are not using poetry venv, we are
# not running it with RUN poetry run pytest...)
RUN pytest -vv --cov-config .coveragerc --cov-report term-missing --durations=3 --cov=.
RUN flake8 --config .flake8 slac tests



# NOTE: Building the .whl with poetry at this stage and installing it in the next
# stage env, works if we install the mqtt-api explicitly, otherwise the poetry
# install dist/ fails. This seems to be a bug in `poetry build` command:
# https://github.com/python-poetry/poetry/issues/2831
# The alternative was to generate the requirements without-hashes as mqtt-api has no
# hashes and generate the wheels for the requirements

# ALTERNATIVE TO BE USED
# RUN poetry install --no-interaction --no-ansi --no-dev

# Exports no-dev dependencies
RUN poetry export -f requirements.txt --without-hashes --with-credentials > requirements.txt
# Generate the wheel to be used by next stage
RUN poetry build -f wheel
RUN pip wheel -w dist -r requirements.txt
# Unfortunately, couldnt find a way to generate only compatible wheels with this
# platform, so I had to remove the MacOS .whl for the dir
RUN rm dist/*macosx*

# ALTERNATIVE TO BE USED
# 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

# ALTERNATIVE TO BE USED
# copy dependencies and wheel from the build stage
# COPY --from=build /venv /venv
# COPY --from=build /usr/src/app ./


COPY --from=build /usr/src/app/dist/ dist/
# mqtt dependency is not part of the iso15118 .whl, so it is not ideal, but the
# solution is to explicitly install the package
# RUN /venv/bin/pip install --index-url https://$PYPI_USER:$PYPI_PASS@pypi.switch-ev.com/simple mqtt_api

#This will install the wheels 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
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# all the recipes are phony (no files to check).
.PHONY: .check-env-vars deps docs test build dev run update install-local run-local deploy


export PATH := ${HOME}/.local/bin:$(PATH)

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

deps:
pip install poetry

docs:
# poetry run sphinx-build -b html docs/source docs/build

test:
#poetry run flake8 pytest -vv tests
poetry run pytest -vv tests

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

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

run: build
docker-compose 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-config
poetry update --require-hashes

poetry-install: poetry-update
poetry install

run-local:
python slac/main.py

mypy:
mypy --config-file mypy.ini slac tests

reformat:
isort slac tests && black --line-length=88 slac tests

black:
black --check --diff --line-length=88 slac tests

flake8:
flake8 --config .flake8 slac tests

code-quality: reformat mypy black flake8

deploy: deps build
# twine upload dist/*.tar.gz
Loading

0 comments on commit 0077a95

Please sign in to comment.