Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[take over] riotnode: node abstraction package #13612

Next Next commit
riotnode: add an empty package directory for 'riotnode'
It is a python directory to start developing the package.
I include all files around for testing and integrating in RIOT.

Test dependencies in tox are already ready for testing with pytest.

* sitecustomize.py: allow implementing 'riotnode' in a subdirectory
* setup.py implement a releasable package
* requirements.txt: uses 'setup.py' could then be used by our standard
  way of installing
* tox.ini: run the test suite with 'tox'
* setup.cfg/.coveragerc: test suites configuration
  • Loading branch information
cladmi authored and leandrolanzieri committed Mar 11, 2020
commit d6699481e6baab1e42137a3d3894038ec81df21f
2 changes: 2 additions & 0 deletions dist/pythonlibs/riotnode/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = riotnode/tests/*
112 changes: 112 additions & 0 deletions dist/pythonlibs/riotnode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Manually added:
# All xml reports
*.xml

#### joe made this: http://goel.io/joe

#####=== Python ===#####

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# 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/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# 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/
28 changes: 28 additions & 0 deletions dist/pythonlibs/riotnode/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
RIOT Node abstraction
=====================

This provides python object abstraction of a node.
The first goal is to be the starting point for the serial abstraction and
build on top of that to provide higher level abstraction like over the shell.

It could provide an RPC interface to a node in Python over the serial port
and maybe also over network.

The goal is here to be test environment agnostic and be usable in any test
framework and also without it.


Testing
-------

Run `tox` to run the whole test suite:

::

tox
...
________________________________ summary ________________________________
test: commands succeeded
lint: commands succeeded
flake8: commands succeeded
congratulations :)
2 changes: 2 additions & 0 deletions dist/pythonlibs/riotnode/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Use the current setup.py for requirements
.
11 changes: 11 additions & 0 deletions dist/pythonlibs/riotnode/riotnode/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""RIOT Node abstraction.

This prodives python object abstraction of a node.
The first goal is to be the starting point for the serial abstraction and
build on top of that to provide higher level abstraction like over the shell.

It could provide an RPC interface to a node in Python over the serial port
and maybe also over network.
"""

__version__ = '0.1.0'
1 change: 1 addition & 0 deletions dist/pythonlibs/riotnode/riotnode/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""riotnode.tests directory."""
10 changes: 10 additions & 0 deletions dist/pythonlibs/riotnode/riotnode/tests/riotnode_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""riotnode.__init__ tests"""
import riotnode


def test_version():
"""Test there is an `__version__` attriubte.

Goal is to have a test to run the test environment.
"""
assert getattr(riotnode, '__version__', None) is not None
15 changes: 15 additions & 0 deletions dist/pythonlibs/riotnode/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool:pytest]
addopts = -v --junit-xml=test-report.xml
--doctest-modules
--cov=riotnode --cov-branch
--cov-report=term --cov-report=xml --cov-report=html
testpaths = riotnode

[lint]
lint-reports = no
lint-disable = locally-disabled,star-args
lint-msg-template = {path}:{line}: [{msg_id}({symbol}), {obj}] {msg}

[flake8]
exclude = .tox,dist,doc,build,*.egg
max-complexity = 10
48 changes: 48 additions & 0 deletions dist/pythonlibs/riotnode/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#! /usr/bin/env python3

import os
from setuptools import setup, find_packages

PACKAGE = 'riotnode'
LICENSE = 'LGPLv2.1'
URL = 'https://github.com/RIOT-OS/RIOT'


def get_version(package):
""" Extract package version without importing file
Importing cause issues with coverage,
(modules can be removed from sys.modules to prevent this)
Importing __init__.py triggers importing rest and then requests too

Inspired from pep8 setup.py
"""
with open(os.path.join(package, '__init__.py')) as init_fd:
for line in init_fd:
if line.startswith('__version__'):
return eval(line.split('=')[-1]) # pylint:disable=eval-used
return None


setup(
name=PACKAGE,
version=get_version(PACKAGE),
description='RIOTNode python abstraction',
long_description=open('README.rst').read(),
author='Gaëtan Harter',
author_email='gaetan.harter@fu-berlin.de',
url=URL,
license=LICENSE,
download_url=URL,
packages=find_packages(),
classifiers=['Development Status :: 2 - Pre-Alpha',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Intended Audience :: End Users/Desktop',
'Environment :: Console',
'Topic :: Utilities', ],
install_requires=[],
python_requires='>=3.5',
)
32 changes: 32 additions & 0 deletions dist/pythonlibs/riotnode/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[tox]
envlist = test,lint,flake8

[testenv]
basepython = python3
passenv = RIOTBASE
setenv =
RIOTBASE = {toxinidir}/../../..
package = riotnode
commands =
test: {[testenv:test]commands}
lint: {[testenv:lint]commands}
flake8: {[testenv:flake8]commands}

[testenv:test]
deps =
pytest
pytest-cov
commands =
pytest

[testenv:lint]
deps =
pylint
pytest
commands =
pylint {envsitepackagesdir}/{env:package}

[testenv:flake8]
deps = flake8
commands =
flake8
7 changes: 7 additions & 0 deletions dist/pythonlibs/sitecustomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os
import sys

# Allow importing packages implemented in sub directories
# Prepend as the directory has the same name as the package

sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'riotnode'))