Skip to content

Commit

Permalink
A big repo cleanup (#182)
Browse files Browse the repository at this point in the history
* a big repo cleanup

* fix permissions

* try to fix osx

* fix syntax, add doc

* fix test

* fix formatting

* fix formatting

* fix crash

* trying to fix travis issues

* fix tests, more cleanup, fix other builds

* replace all server starting with multiprocess

* fix containers

Co-authored-by: Gijs Molenaar <[email protected]>
  • Loading branch information
gijzelaerr and Gijs Molenaar authored Jul 29, 2020
1 parent 8a30a90 commit 302233b
Show file tree
Hide file tree
Showing 40 changed files with 1,129 additions and 694 deletions.
1 change: 1 addition & 0 deletions .dockerignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ doc/_build/
.virtualenv3/
.venv/
.venv3/
venv/
62 changes: 35 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
language: python
matrix:
include:
- os: linux
sudo: required
python: 3.6
- os: linux
sudo: required
python: 3.6
- os: linux
sudo: required
python: 3.7
- os: linux
sudo: required
python: 3.8
- os: osx
language: generic
env: PYENV=3
include:
- os: linux
env: TARGET=ubuntu1804
services: [docker]
sudo: true
- os: linux
env: TARGET=ubuntu2004
services: [docker]
sudo: true
- os: linux
env:
- TARGET=mypy
- NOSCRIPT=true
services: [docker]
sudo: true
- os: linux
env:
- TARGET=pycodestyle
- NOSCRIPT=true
services: [docker]
sudo: true
- os: linux
env:
- TARGET=doc
- NOSCRIPT=true
services: [docker]
sudo: true
- os: osx
osx_image: xcode12


before_install:
- .travis/before_install.sh

install:
- python${PYENV} setup.py install
- .travis/install.sh

script:
- .travis/script.sh
after_success:
- codecov
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/aacaa796672a51d47850
on_success: change
on_failure: always
on_start: false

deploy:
provider: pypi
user: gijzelaerr
Expand Down
15 changes: 4 additions & 11 deletions .travis/before_install.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
#!/bin/bash
#!/usr/bin/env bash

set -x
set -v
set -e

if [ "$TRAVIS_OS_NAME" = "osx" ]; then
brew install snap7
pip install nose mock coverage
pip3 install nose mock coverage
fi

if [ "$TRAVIS_OS_NAME" = "linux" ]; then
sudo apt-get update -qq
sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:gijzelaar/snap7
sudo apt-get update -qq
sudo apt-get install -y libsnap7-dev libsnap71
echo "nothing"
fi

pip${PYENV} install -r test/requirements.txt
12 changes: 12 additions & 0 deletions .travis/doc.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ubuntu:20.04

RUN apt-get update -qq
RUN apt-get install -y software-properties-common
RUN add-apt-repository -y ppa:gijzelaar/snap7
RUN apt-get update -qq
RUN apt-get install -y libsnap7-dev libsnap7-1 python3-venv make
ADD . /code
WORKDIR /code
ENV PATH="/code/venv/bin:$PATH"
RUN make doc

15 changes: 15 additions & 0 deletions .travis/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -v
set -e


if [ "$TRAVIS_OS_NAME" = "osx" ]; then
make setup
fi

if [ "$TRAVIS_OS_NAME" = "linux" ]; then
docker build . -f .travis/${TARGET}.docker -t python-snap7/${TARGET}
fi


10 changes: 10 additions & 0 deletions .travis/mypy.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ubuntu:20.04

RUN apt-get update -qq
RUN apt-get install -y software-properties-common
RUN add-apt-repository -y ppa:gijzelaar/snap7
RUN apt-get update -qq
RUN apt-get install -y libsnap7-dev libsnap7-1 python3-venv make
ADD . /code
WORKDIR /code
RUN make mypy
10 changes: 10 additions & 0 deletions .travis/pycodestyle.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ubuntu:20.04

RUN apt-get update -qq
RUN apt-get install -y software-properties-common
RUN add-apt-repository -y ppa:gijzelaar/snap7
RUN apt-get update -qq
RUN apt-get install -y libsnap7-dev libsnap7-1 python3-venv make
ADD . /code
WORKDIR /code
RUN make pycodestyle
22 changes: 9 additions & 13 deletions .travis/script.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#!/bin/bash
#!/usr/bin/env bash

set -x
set -v
set -e

if [ "$TRAVIS_OS_NAME" = "linux" ]; then
NOSETESTS=${VIRTUAL_ENV}/bin/nosetests
else
NOSETESTS="python${PYENV} -m nose"
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
source venv/bin/activate
make test
fi

PYTHONPATH=.

${NOSETESTS} --with-coverage test/test_server.py
${NOSETESTS} --with-coverage test/test_client.py
${NOSETESTS} --with-coverage test/test_client_async.py
${NOSETESTS} --with-coverage test/test_util.py
sudo ${NOSETESTS} --with-coverage test/test_partner.py
if [ "$TRAVIS_OS_NAME" = "linux" ] && [ "$NOSCRIPT" != "true" ]; then
docker run python-snap7/${TARGET} make test
fi
10 changes: 10 additions & 0 deletions .travis/ubuntu1804.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ubuntu:18.04

RUN apt-get update -qq
RUN apt-get install -y software-properties-common
RUN add-apt-repository -y ppa:gijzelaar/snap7
RUN apt-get update -qq
RUN apt-get install -y libsnap7-dev libsnap7-1 python3-venv make sudo
ADD . /code
WORKDIR /code
RUN make test
10 changes: 10 additions & 0 deletions .travis/ubuntu2004.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ubuntu:20.04

RUN apt-get update -qq
RUN apt-get install -y software-properties-common
RUN add-apt-repository -y ppa:gijzelaar/snap7
RUN apt-get update -qq
RUN apt-get install -y libsnap7-dev libsnap7-1 python3-venv make sudo
ADD . /code
WORKDIR /code
RUN make test
51 changes: 51 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# developer file, not intented for installing python-snap7

.PHONY: test

allll: test

venv/:
python3 -m venv venv
venv/bin/pip install --upgrade pip wheel

venv/installed: venv/
venv/bin/pip install -e .
touch venv/installed

setup: venv/installed

venv/bin/pytest: venv/
venv/bin/pip install -e ".[test]"

venv/bin/sphinx-build: venv/
venv/bin/pip install -e ".[doc]"

doc: venv/bin/sphinx-build
cd doc && make html

pycodestyle: venv/bin/pytest
venv/bin/pycodestyle snap7 test

mypy: venv/bin/pytest
venv/bin/mypy snap7 test

test: venv/bin/pytest
venv/bin/pytest test/test_server.py test/test_client.py test/test_util.py
sudo venv/bin/pytest test/test_partner.py # run this as last to prevent pytest cache dir creates as root

docker-doc:
docker build . -f .travis/doc.docker -t doc

docker-mypy:
docker build . -f .travis/mypy.docker -t mypy

docker-pycodestyle:
docker build . -f .travis/pycodestyle.docker -t pycodestyle

docker-ubuntu1804:
docker build . -f .travis/ubuntu1804.docker -t ubuntu1804

docker-ubuntu2004:
docker build . -f .travis/ubuntu2004.docker -t ubuntu2004

dockers: docker-doc docker-mypy docker-pycodestyle docker-ubuntu1804 docker-ubuntu2004
5 changes: 0 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ with Siemens S7 PLCs.

python-snap7 is tested with Python 3.6+, on Windows, Linux and OS X.

**Since 17.07.2020 the Support for Python <3.6 is dropped!**

.. image:: https://travis-ci.org/gijzelaerr/python-snap7.png?branch=master
:target: https://travis-ci.org/gijzelaerr/python-snap7

.. image:: http://codecov.io/github/gijzelaerr/python-snap7/coverage.svg?branch=master
:target: http://codecov.io/github/gijzelaerr/python-snap7?branch=master

The full documentation is available on `Read The Docs <http://python-snap7.readthedocs.org/en/latest/>`_.

see `python-snap7 in action <http://youtu.be/G-Gj_r2BQBk/>`_.

Installation
============
Expand Down
2 changes: 1 addition & 1 deletion example/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# then you can specify an area to read from:
# https://github.com/gijzelaerr/python-snap7/blob/master/snap7/snap7types.py

from snap7.snap7types import area
from snap7.types import area

# play with these functions.
plc.read_area(area['MK'], dbnumber, start, size)
Expand Down
4 changes: 2 additions & 2 deletions example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_db_row(db, start, size):
start (int): The index of where to start in db data
size (int): The size of the db data to read
"""
type_ = snap7.snap7types.wordlen_to_ctypes[snap7.snap7types.S7WLByte]
type_ = snap7.types.wordlen_to_ctypes[snap7.types.S7WLByte]
data = client.db_read(db, start, type_, size)
# print_row(data[:60])
return data
Expand Down Expand Up @@ -155,7 +155,7 @@ def set_part_db(start, size, _bytearray):


def write_data_db(dbnumber, all_data, size):
area = snap7.snap7types.S7AreaDB
area = snap7.types.S7AreaDB
dbnumber = 1
client.write_area(area, dbnumber, 0, size, all_data)

Expand Down
2 changes: 1 addition & 1 deletion example/read_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import snap7
from snap7.common import check_error
from snap7.snap7types import S7DataItem, S7AreaDB, S7WLByte
from snap7.types import S7DataItem, S7AreaDB, S7WLByte


client = snap7.client.Client()
Expand Down
11 changes: 5 additions & 6 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/bin/sh
#!/usr/bin/env bash

set -v
set -e

export PYTHONPATH=.
echo "Running test_partner.py ----------------------------------------------\n\n"
sudo nosetests test/test_partner.py
echo "Running test_server.py ----------------------------------------------\n\n"
sudo venv/bin/nosetests test/test_partner.py
nosetests test/test_server.py
echo "Running test_client.py ----------------------------------------------\n\n"
nosetests test/test_client.py
echo "Running test_util.py ----------------------------------------------\n\n"
nosetests test/test_util.py

2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pycodestyle]
ignore = E501,E402,W391,W292,W503
Loading

0 comments on commit 302233b

Please sign in to comment.