-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup.py
156 lines (126 loc) · 4.73 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import glob
import os
import shutil
import sys
from pathlib import Path
from setuptools import setup, find_packages, Command
README = (Path(__file__).parent / "README.md").read_text(encoding="UTF-8")
HERE = Path(os.path.dirname(__file__)).absolute()
# get __version__ from timeeval/_version.py
with open(Path("timeeval") / "_version.py") as f:
exec(f.read())
VERSION: str = __version__ # noqa
def load_dependencies():
try:
import yaml
except ImportError:
import pip
pip.main(["install", "pyyaml"])
import yaml
EXCLUDES = ["python", "pip"]
with open(HERE / "environment.yml", "r", encoding="UTF-8") as f:
env = yaml.safe_load(f)
def split_deps(deps):
pip_deps = list(filter(lambda x: isinstance(x, dict), deps))
if len(pip_deps) == 1:
pip_deps = pip_deps[0].get("pip", []) or []
conda = list(filter(lambda x: not isinstance(x, dict), deps))
conda = list(map(lambda x: x.split("::")[-1], conda))
return pip_deps, conda
def to_pip(dep):
if "<" in dep or ">" in dep:
return dep
else:
return dep.replace("=", "==")
def excluded(name):
return any([excl in name for excl in EXCLUDES])
pip_deps, conda_deps = split_deps(env.get("dependencies", []))
conda_deps = [to_pip(dep) for dep in conda_deps if not excluded(dep)]
return conda_deps + pip_deps
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=timeeval", "--cov=timeeval_experiments.generator", "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 TimeEval; 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", "timeeval", "timeeval_experiments", "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
if __name__ == "__main__":
setup(
name="TimeEval",
version=VERSION,
description="Evaluation Tool for Time Series Anomaly Detection Methods",
long_description=README,
long_description_content_type="text/markdown",
author="Phillip Wenig and Sebastian Schmidl",
author_email="[email protected]",
url="https://github.com/TimeEval/TimeEval",
license="MIT",
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9"
],
packages=find_packages(exclude=("tests", "tests.*")),
package_data={"timeeval": ["py.typed"], "timeeval_experiments": ["py.typed"]},
install_requires=load_dependencies(),
python_requires=">=3.7, <3.10",
test_suite="tests",
cmdclass={
"test": PyTestCommand,
"typecheck": MyPyCheckCommand,
"clean": CleanCommand
},
zip_safe=False
)