-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
101 lines (80 loc) · 2.6 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import glob
import os
import shutil
from setuptools import setup, find_packages, Command
import sys
class PyTestCommand(Command):
description = "run PyTest for TimeEval"
user_options = []
def initialize_options(self) -> None:
pass
def finalize_options(self) -> None:
pass
def run(self) -> None:
import pytest
from pytest import ExitCode
exit_code = pytest.main(
[
"--cov-report=term",
"--cov-report=xml:coverage.xml",
"--cov=tidewater",
"tests",
]
)
if exit_code == ExitCode.TESTS_FAILED:
raise ValueError("Tests failed!")
elif exit_code == ExitCode.INTERRUPTED:
raise ValueError("pytest was interrupted!")
elif exit_code == ExitCode.INTERNAL_ERROR:
raise ValueError("pytest internal error!")
elif exit_code == ExitCode.USAGE_ERROR:
raise ValueError("Pytest was not correctly used!")
elif exit_code == ExitCode.NO_TESTS_COLLECTED:
raise ValueError("No tests found!")
# else: everything is fine
class MyPyCheckCommand(Command):
description = "run MyPy for Tidewater; performs static type checking"
user_options = []
def initialize_options(self) -> None:
pass
def finalize_options(self) -> None:
pass
def run(self) -> None:
from mypy.main import main as mypy
args = ["--pretty", "tidewater", "tests"]
mypy(None, stdout=sys.stdout, stderr=sys.stderr, args=args)
class CleanCommand(Command):
description = "Remove build artifacts from the source tree"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
files = [".coverage*", "coverage.xml"]
dirs = [
"build",
"dist",
"*.egg-info",
"**/__pycache__",
".mypy_cache",
".pytest_cache",
"**/.ipynb_checkpoints",
]
for d in dirs:
for filename in glob.glob(d):
shutil.rmtree(filename, ignore_errors=True)
for f in files:
for filename in glob.glob(f):
try:
os.remove(filename)
except OSError:
pass
setup(
name="tidewater",
version="0.1.0",
packages=find_packages(exclude=["tests", "experiments"]),
python_requires=">=3.8",
test_suite="tests",
cmdclass={"test": PyTestCommand, "typecheck": MyPyCheckCommand, "clean": CleanCommand},
)