From f50826a54c844e8c3b2d58b4bf885268f15b0878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Wed, 22 Apr 2020 11:34:12 +0200 Subject: [PATCH 1/6] add cirrus.yml & Makefile & requirements-dev.txt from libioc and start fixing issues --- .cirrus.yml | 12 ++++++++++++ .travis.yml | 14 ++++++++++++++ Makefile | 35 +++++++++++++++++++++++++++++++++++ jail/__version__.py | 4 ++-- jail/types.py | 13 ++++++------- requirements-dev.txt | 12 ++++++++++++ setup.py | 25 ++++++++++++------------- 7 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 .cirrus.yml create mode 100644 .travis.yml create mode 100644 Makefile create mode 100644 requirements-dev.txt diff --git a/.cirrus.yml b/.cirrus.yml new file mode 100644 index 0000000..be33a7d --- /dev/null +++ b/.cirrus.yml @@ -0,0 +1,12 @@ +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 + - pip install -r requirements-dev.txt + - pip install -r requirements.txt + test_script: + - pytest tests diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b67e49d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: python +python: + - "3.7" +sudo: false +install: + - make install-travis +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/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..51c5967 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,12 @@ +pytest +pytest-cov +pytest-pep8 +pytest-mock +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.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",)) ) From b4b9bc88495d242bb23c62088509db44c6d2ed05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Gr=C3=B6nke?= Date: Thu, 23 Apr 2020 22:47:01 +0200 Subject: [PATCH 2/6] correct CI install make task --- .cirrus.yml | 3 +-- .travis.yml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index be33a7d..925443d 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -6,7 +6,6 @@ task: - mount -t fdescfs null /dev/fd - pkg install -y python3 - python3 -m ensurepip - - pip install -r requirements-dev.txt - - pip install -r requirements.txt + - make install-python-requirements-dev test_script: - pytest tests diff --git a/.travis.yml b/.travis.yml index b67e49d..eb268fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ python: - "3.7" sudo: false install: - - make install-travis + - make install-python-requirements-dev script: - make check notifications: From 0c7a8cfb3b54c53fc6f8ee4f4333705c1a7a84d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Gr=C3=B6nke?= Date: Thu, 23 Apr 2020 23:03:12 +0200 Subject: [PATCH 3/6] chore: remove pytest-cov dependency pytest-cov depends on SQLite3, which is not required at all, considering the size of this project --- requirements-dev.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 51c5967..8f342d1 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,4 @@ pytest -pytest-cov pytest-pep8 pytest-mock flake8-docstrings From 272e9bb79ecd1c63460a90ff00f179ef91401f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Gr=C3=B6nke?= Date: Thu, 23 Apr 2020 23:16:13 +0200 Subject: [PATCH 4/6] chore: add pytest-benchmark dev dependency --- requirements-dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index 8f342d1..16f5c04 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,7 @@ pytest pytest-pep8 pytest-mock +pytest-benchmark flake8-docstrings flake8-mutable flake8-builtins From 9be3ca8835bdfbef14d33e90d7e0bf086e4cb113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Gr=C3=B6nke?= Date: Thu, 23 Apr 2020 23:34:17 +0200 Subject: [PATCH 5/6] chore: ignore D101,D103 typing issues in flake8 checks --- setup.cfg | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 From 89f951cd62df1727771f6bd4dec72e40815da517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Gr=C3=B6nke?= Date: Tue, 18 Aug 2020 22:06:54 +0200 Subject: [PATCH 6/6] add build status to readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) 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