-
Notifications
You must be signed in to change notification settings - Fork 13
/
noxfile.py
102 lines (82 loc) · 3.2 KB
/
noxfile.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
from pathlib import Path
from pprint import pformat
import platform
import nox
cleaned = [
"etrago/analyze/__init__.py",
"etrago/analyze/calc_results.py",
"etrago/analyze/plot.py",
"etrago/cluster/electrical.py",
"etrago/cluster/gas.py",
"etrago/cluster/spatial.py",
"etrago/cluster/temporal.py",
"etrago/disaggregate/spatial.py",
"etrago/disaggregate/temporal.py",
"etrago/execute/__init__.py",
"etrago/execute/grid_optimization.py",
"etrago/execute/market_optimization.py",
"etrago/network.py",
"etrago/tools/extendable.py",
"etrago/tools/io.py",
"etrago/tools/utilities.py",
"noxfile.py",
"setup.py",
]
def setdefaults(session):
session.env["PYTHONUNBUFFERED"] = "yes"
@nox.session(python="3")
def check(session):
"""Run custom checks."""
setdefaults(session)
assert cleaned == sorted(set(cleaned)), (
"The list of cleaned files contains duplicates and/or isn't sorted"
" alphabetically."
f"\nExpected:\n{pformat(sorted(set(cleaned)))}"
f"\nGot:\n{pformat(cleaned)}"
)
@nox.session(python="3")
def black(session):
"""Check for happy little style accidents with `black`."""
setdefaults(session)
session.install("black")
session.run("black", "--check", "--diff", *cleaned)
@nox.session(python="3")
def isort(session):
"""Check import ordering with `isort`."""
setdefaults(session)
session.install("isort >= 5")
session.run("isort", "--check-only", "--diff", *cleaned)
@nox.session(python="3")
def flake8(session):
"""Check for happy little style accidents with `flake8`."""
setdefaults(session)
session.install("Flake8-pyproject", "flake8")
session.run("flake8", "--ignore=E722, W605, W503, E203", *cleaned)
@nox.session(python=["3", "3.9", "3.10", "3.11"])
def build(session):
"""Build the package and check for packaging errors."""
# Get the current Python version and OS
current_version = session.python if session.python else "unknown"
current_os = platform.system()
print(f"Running install on Python {current_version} and OS {current_os}")
# Check if the current session is Python 3.9 on macOS and skip
if current_version == "3.9" and current_os == "Darwin":
session.skip("Skipping tests for Python 3.9 on macOS")
setdefaults(session)
session.install("twine")
session.run("python", "setup.py", "bdist", "bdist_wheel")
session.run("twine", "check", "dist/eTraGo*")
@nox.session(python=["3", "3.9", "3.10", "3.11"])
def install(session):
"""Install the package."""
# Get the current Python version and OS
current_version = session.python if session.python else "unknown"
current_os = platform.system()
print(f"Running install on Python {current_version} and OS {current_os}")
# Check if the current session is Python 3.9 on macOS and skip
if current_version == "3.9" and current_os == "Darwin":
session.skip("Skipping tests for Python 3.9 on macOS")
setdefaults(session)
session.env["SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL"] = "False"
session.run("python", "-mpip", "install", "--upgrade", "pip")
session.run("python", "-mpip", "install", *Path("dist").glob("*.whl"))