diff --git a/.cirrus.yml b/.cirrus.yml new file mode 100644 index 0000000..925443d --- /dev/null +++ b/.cirrus.yml @@ -0,0 +1,11 @@ +task: + freebsd_instance: + matrix: + image: freebsd-12-1-release-amd64 + install_script: + - mount -t fdescfs null /dev/fd + - pkg install -y python3 + - python3 -m ensurepip + - make install-python-requirements-dev + test_script: + - pytest tests diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..eb268fb --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: python +python: + - "3.7" +sudo: false +install: + - make install-python-requirements-dev +script: + - make check +notifications: + email: false +addons: + apt: + packages: + - sqlite3 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a91d16e --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +MYPYPATH = $(shell pwd)/.travis/mypy-stubs + +PYTHON ?= python3 + +install-python-requirements: + $(PYTHON) -m ensurepip + $(PYTHON) -m pip install -U pip + $(PYTHON) -m pip install -Ur requirements.txt + +install-python-requirements-dev: install-python-requirements + $(PYTHON) -m pip install -Ur requirements-dev.txt + +check: + flake8 --version + mypy --version + flake8 --exclude=".travis,.eggs,__init__.py,docs,tests" --ignore=E203,E252,W391,D107,A001,A002,A003,A004,D412,D413,T499 + bandit --skip B404,B110 --exclude tests/ *.py jail/*.py +test: + pytest tests --zpool $(ZPOOL) + +.PHONY: docs +docs: + $(PYTHON) setup.py build_sphinx + +help: + @echo " install" + @echo " Installs libioc" + @echo " uninstall" + @echo " Removes libioc" + @echo " test" + @echo " Run unit tests with pytest" + @echo " check" + @echo " Run static linters & other static analysis tests" + @echo " install-dev" + @echo " Install dependencies needed to run `check`" diff --git a/README.md b/README.md index 7631430..b094696 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,11 @@ py-jail A native Python wrapper for FreeBSD jails using libc. +## Build Status + +| Unit Tests | [![Unit Tests](https://api.cirrus-ci.com/github/gronke/py-jail.svg)](https://cirrus-ci.com/github/gronke/py-jail) | +| Code Style | [![Code Style](https://travis-ci.org/gronke/py-jail.svg?branch=master)](https://travis-ci.org/gronke/py-jail) | + ## Usage ### jail_set diff --git a/jail/__version__.py b/jail/__version__.py index 7cd6332..4656590 100644 --- a/jail/__version__.py +++ b/jail/__version__.py @@ -1,6 +1,6 @@ # Copyright (c) 2019, Stefan Grönke # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted providing that the following conditions # are met: @@ -9,7 +9,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# +# # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE diff --git a/jail/types.py b/jail/types.py index 795b0b6..1b5eab9 100644 --- a/jail/types.py +++ b/jail/types.py @@ -1,6 +1,6 @@ # Copyright (c) 2019, Stefan Grönke # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted providing that the following conditions # are met: @@ -9,7 +9,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# +# # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -22,7 +22,6 @@ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. """Types used by jail (2).""" -import typing import ctypes import ipaddress import struct @@ -52,7 +51,7 @@ class in6_addr(ctypes.Structure): def in6_addr_U_from_ip(ip6_address: ipaddress.IPv6Address) -> in6_addr_U: - return in6_addr_U(struct.unpack( - "B"*16, - bytes.fromhex(ip6_address.exploded.replace(":","")) - )) + return in6_addr_U(struct.unpack( + "B" * 16, + bytes.fromhex(ip6_address.exploded.replace(":", "")), + )) diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..16f5c04 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,12 @@ +pytest +pytest-pep8 +pytest-mock +pytest-benchmark +flake8-docstrings +flake8-mutable +flake8-builtins +flake8-mypy +bandit==1.5.1 +bandit-high-entropy-string +sphinx-autodoc-typehints +sphinx_rtd_theme diff --git a/setup.cfg b/setup.cfg index 7cea437..0c0f1f5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,4 +2,7 @@ test = pytest [tool:pytest] -addopts = --verbose \ No newline at end of file +addopts = --verbose + +[flake8] +ignore = D101,D103 diff --git a/setup.py b/setup.py index d51287e..d29ed8d 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,6 @@ import typing import os import os.path -import sys from setuptools import find_packages, setup try: from pip._internal.req import parse_requirements @@ -34,23 +33,23 @@ def _read_requirements( about = {} with open(os.path.join(cwd, "jail", "__version__.py"), encoding="utf-8") as f: - VERSION = exec(f.read(), about) + VERSION = exec(f.read(), about) # nosec with open(os.path.join(cwd, "README.md"), encoding="utf-8") as f: long_description = f.read() setup( - name="jail", - version=about["__version__"], - description="Native FreeBSD jail bindings with libc.", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/gronke/py-jail", - author="Stefan Grönke", - author_email="stefan@gronke.net", - python_requires=">=3.6", + name="jail", + version=about["__version__"], + description="Native FreeBSD jail bindings with libc.", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/gronke/py-jail", + author="Stefan Grönke", + author_email="stefan@gronke.net", + python_requires=">=3.6", install_requires=requirements["install_requires"], dependency_links=requirements["dependency_links"], - tests_require=["pytest", "pytest-runner", "pytest-benchmark"], - packages=find_packages(exclude=("tests",)) + tests_require=["pytest", "pytest-runner", "pytest-benchmark"], + packages=find_packages(exclude=("tests",)) )