Skip to content

Commit

Permalink
Update tests and licensing
Browse files Browse the repository at this point in the history
  • Loading branch information
parafoxia committed Nov 4, 2021
1 parent d0c8bf6 commit 3254c28
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 13 deletions.
107 changes: 103 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
# Copyright (c) 2021, Ethan Henderson, Jonxslays
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 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.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import os
import typing as t
from pathlib import Path

import nox

PROJECT_NAME = "len8"
LIB_DIR = Path(__file__).parent / PROJECT_NAME
TEST_DIR = Path(__file__).parent / "tests"


def parse_requirements(path: str) -> t.List[str]:
with open(path, mode="r", encoding="utf-8") as f:
Expand All @@ -10,18 +44,44 @@ def parse_requirements(path: str) -> t.List[str]:


DEPS = {
dep.split("==")[0]: dep
dep.split("~=")[0]: dep
for dep in [
*parse_requirements("./requirements-dev.txt"),
*parse_requirements("./requirements-test.txt"),
*parse_requirements("./requirements-nox.txt"),
]
}


@nox.session(reuse_venv=True)
def tests(session: nox.Session) -> None:
session.install("-U", "-r", "./requirements-test.txt")
session.run("pytest", "-s", "--verbose", "--log-level=INFO")
session.install("-U", "-r", "./requirements-nox.txt")
session.run(
"coverage",
"run",
"--omit",
"tests/*",
"-m",
"pytest",
"--testdox",
"--log-level=INFO",
)


@nox.session(reuse_venv=True)
def check_coverage(session: nox.Session) -> None:
session.install("-U", DEPS["coverage"])

if not os.path.isfile(Path(__file__).parent / ".coverage"):
session.skip("No coverage to check")

session.run("coverage", "report", "-m")


# @nox.session(reuse_venv=True)
# def check_docs_build(session: nox.Session) -> None:
# session.install("-U", DEPS["sphinx"], DEPS["furo"], ".")
# session.cd("./docs")
# session.run("make", "html")


@nox.session(reuse_venv=True)
Expand All @@ -30,7 +90,46 @@ def check_formatting(session: nox.Session) -> None:
session.run("black", ".", "--check")


@nox.session(reuse_venv=True)
def check_imports(session: nox.Session) -> None:
session.install("-U", DEPS["flake8"], DEPS["isort"])
# flake8 doesn't use the gitignore so we have to be explicit.
session.run(
"flake8",
PROJECT_NAME,
"tests",
"--select",
"F4",
"--extend-ignore",
"E,F,W",
"--extend-exclude",
"__init__.py",
)
session.run("isort", ".", "-cq", "--profile", "black")


@nox.session(reuse_venv=True)
def check_typing(session: nox.Session) -> None:
session.install("-U", DEPS["pyright"])
session.run("pyright")


@nox.session(reuse_venv=True)
def check_licensing(session: nox.Session) -> None:
missing: list[Path] = []

for p in [
*LIB_DIR.rglob("*.py"),
*TEST_DIR.glob("*.py"),
Path(__file__),
Path(__file__).parent / "setup.py",
]:
with open(p) as f:
if not f.read().startswith("# Copyright (c)"):
missing.append(p)

if missing:
session.error(
f"\n{len(missing):,} file(s) are missing their licenses:\n"
+ "\n".join(f" - {file}" for file in missing)
)
40 changes: 32 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# Copyright (c) 2021, Ethan Henderson, Jonxslays
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 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.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import sys
import typing as t

Expand All @@ -12,12 +40,12 @@


def parse_requirements(path: str) -> t.List[str]:
with open(path, mode="r", encoding="utf-8") as f:
with open(path) as f:
deps = (d.strip() for d in f.readlines())
return [d for d in deps if not d.startswith(("#", "-r"))]


with open("len8/__init__.py", mode="r", encoding="utf-8") as f:
with open("./len8/__init__.py") as f:
(
productname,
version,
Expand All @@ -29,7 +57,7 @@ def parse_requirements(path: str) -> t.List[str]:
bug_tracker,
) = [l.split('"')[1] for l in f.readlines()[28:36]]

with open("./README.md", mode="r", encoding="utf-8") as f:
with open("./README.md") as f:
long_description = f.read()

setuptools.setup(
Expand Down Expand Up @@ -71,11 +99,7 @@ def parse_requirements(path: str) -> t.List[str]:
"Source": url,
"Bug Tracker": bug_tracker,
},
# install_requires=parse_requirements("./requirements.txt"),
# extras_require={
# "dev": parse_requirements("./requirements-dev.txt"),
# },
entry_points={"console_scripts": ["len8 = len8.__main__:main"]},
python_requires=">=3.6.0",
python_requires=">=3.6.0,<3.12",
packages=setuptools.find_packages(include=["len8*"]),
)
30 changes: 29 additions & 1 deletion tests/test_checker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
import pytest
# Copyright (c) 2021, Ethan Henderson, Jonxslays
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 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.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import pytest # type: ignore

import len8

Expand Down

0 comments on commit 3254c28

Please sign in to comment.