This repository has been archived by the owner on Aug 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
executable file
·179 lines (146 loc) · 4.52 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# -*- coding: utf-8 -*-
from os import path
import os
import nox
def is_win() -> bool:
"""Determine if current operating system is windows
Returns:
True if on a windows machine; False otherwise
"""
return os.name == "nt"
nox.options.envdir = ".nox_win" if is_win() else ".nox"
IS_GITLAB_CI = "GITLAB_CI" in os.environ
PWD = path.abspath(path.dirname(__file__))
JSONBOURNE_PKG_DIRPATH = path.join(PWD, "jsonbourne")
TESTS_DIRPATH = path.join(PWD, "tests")
VENV_BACKEND = None if is_win() else "conda"
REUSE_TEST_ENVS = IS_GITLAB_CI or True
#############
### UTILS ###
#############
def latest_wheel():
wheels = sorted([el for el in os.listdir("dist") if el.endswith(".whl")])
latest = wheels[-1]
return latest
def _get_session_python_site_packages_dir(session):
try:
site_packages_dir = session._runner._site_packages_dir
except AttributeError:
old_install_only_value = session._runner.global_config.install_only
try:
# Force install only to be false for the following chunk of code
# For additional information as to why see:
# https://github.com/theacodes/nox/pull/181
session._runner.global_config.install_only = False
site_packages_dir = session.run(
"python",
"-c"
"import sys; "
"from distutils.sysconfig import get_python_lib; "
"sys.stdout.write(get_python_lib())",
silent=True,
log=False,
)
session._runner._site_packages_dir = site_packages_dir
finally:
session._runner.global_config.install_only = old_install_only_value
return site_packages_dir
def _get_dgpy_site_packages_jsonbourne_location(session):
return path.join(_get_session_python_site_packages_dir(session), "jsonbourne")
def _get_jsonbourne_version() -> str:
_filepath = path.join(PWD, "pyproject.toml")
version = (
[l for l in open(_filepath).read().split("\n") if "version" in l][0]
.replace("version = ", "")
.strip('"')
)
return version
################
##### DGPY #####
################
@nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
def flake(session):
session.install("flake8")
session.install("flake8-print")
session.install("flake8-eradicate")
session.run("flake8", JSONBOURNE_PKG_DIRPATH)
# @nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
# def flake_tests(session):
# session.install("flake8")
# session.run("flake8", TESTS_DIRPATH)
@nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
def base_test(session):
session.install("pytest")
session.run(
"pytest",
"-m",
"not optdeps",
TESTS_DIRPATH,
)
@nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
def pydantic_test(session):
session.install("pytest")
session.install("pydantic")
session.install("orjson")
session.run(
"pytest",
"-m",
"basic or pydantic",
"--doctest-modules",
TESTS_DIRPATH,
JSONBOURNE_PKG_DIRPATH,
)
@nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
def attrs_test(session):
session.install("pytest")
session.install("attrs")
session.run(
"pytest",
"-m",
"basic or attrs",
TESTS_DIRPATH,
)
@nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
def jsonlibs_test(session):
session.install("pytest")
session.install("orjson")
session.install("python-rapidjson")
session.run(
"pytest",
"-m",
"jsonlibs",
TESTS_DIRPATH,
)
@nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
def orjson_test(session):
session.install("pytest")
session.install("orjson")
session.run(
"pytest",
"-m",
"basic or orjson",
TESTS_DIRPATH,
)
@nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
def rapidjson_test(session):
session.install("pytest")
session.install("python-rapidjson")
session.run(
"pytest",
"-m",
"rapidjson or basic",
TESTS_DIRPATH,
)
### TODO: add orjson (maybe)
# @nox.session(venv_backend=VENV_BACKEND, reuse_venv=True)
# def orjson_test(session):
# session.install("pytest")
# session.install("orjson")
# session.run(
# "pytest",
# "-m",
# "orjson or basic",
# "--doctest-modules",
# TESTS_DIRPATH,
# JSONBOURNE_PKG_DIRPATH,
# )