16
16
17
17
18
18
from __future__ import absolute_import
19
+
19
20
import os
21
+
20
22
import nox
21
23
22
- BLACK_PATHS = ["google" , "tests" ]
24
+ BLACK_VERSION = "black==23.12.1"
25
+ ISORT_VERSION = "isort==5.13.2"
26
+ MYPY_VERSION = "mypy==0.982"
27
+
28
+ LINT_PATHS = ["google" , "tests" , "noxfile.py" , "setup.py" ]
23
29
24
- if os .path .exists ("samples" ):
25
- BLACK_PATHS .append ("samples" )
30
+ TEST_PYTHON_VERSIONS = ["3.8" , "3.9" , "3.10" , "3.11" ]
26
31
27
32
28
33
@nox .session
@@ -31,22 +36,63 @@ def lint(session):
31
36
Returns a failure if the linters find linting errors or sufficiently
32
37
serious code quality issues.
33
38
"""
34
- session .install ("-r" , "requirements-test.txt" )
35
39
session .install ("-r" , "requirements.txt" )
36
- session .install ("flake8-import-order" )
37
- session .run ("black" , "--check" , * BLACK_PATHS )
40
+ session .install (
41
+ "flake8" ,
42
+ "flake8-annotations" ,
43
+ MYPY_VERSION ,
44
+ BLACK_VERSION ,
45
+ ISORT_VERSION ,
46
+ "types-setuptools" ,
47
+ "twine" ,
48
+ )
49
+ session .run (
50
+ "isort" ,
51
+ "--fss" ,
52
+ "--check-only" ,
53
+ "--diff" ,
54
+ "--profile=google" ,
55
+ * LINT_PATHS ,
56
+ )
57
+ session .run ("black" , "--check" , "--diff" , * LINT_PATHS )
38
58
session .run (
39
59
"flake8" ,
40
- "--import-order-style=google" ,
41
- "--application-import-names=google,tests" ,
42
60
"google" ,
43
61
"tests" ,
44
62
)
45
- session .run ("mypy" , "-p" , "google" , "--show-traceback" )
63
+ session .run (
64
+ "mypy" ,
65
+ "-p" ,
66
+ "google" ,
67
+ "--install-types" ,
68
+ "--non-interactive" ,
69
+ "--show-traceback" ,
70
+ )
46
71
session .run ("python" , "setup.py" , "sdist" )
47
72
session .run ("twine" , "check" , "dist/*" )
48
73
49
74
75
+ @nox .session ()
76
+ def format (session ):
77
+ """
78
+ Run isort to sort imports. Then run black
79
+ to format code to uniform standard.
80
+ """
81
+ session .install (BLACK_VERSION , ISORT_VERSION )
82
+ # Use the --fss option to sort imports using strict alphabetical order.
83
+ # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sectionss
84
+ session .run (
85
+ "isort" ,
86
+ "--fss" ,
87
+ "--profile=google" ,
88
+ * LINT_PATHS ,
89
+ )
90
+ session .run (
91
+ "black" ,
92
+ * LINT_PATHS ,
93
+ )
94
+
95
+
50
96
def default (session , path ):
51
97
# Install all test dependencies, then install this package in-place.
52
98
session .install ("-r" , "requirements-test.txt" )
@@ -55,7 +101,7 @@ def default(session, path):
55
101
# Run py.test against the unit tests.
56
102
session .run (
57
103
"pytest" ,
58
- "--cov=google/ cloud/ sql/ connector" ,
104
+ "--cov=google. cloud. sql. connector" ,
59
105
"-v" ,
60
106
"--cov-config=.coveragerc" ,
61
107
"--cov-report=" ,
@@ -66,17 +112,17 @@ def default(session, path):
66
112
)
67
113
68
114
69
- @nox .session (python = [ "3.8" , "3.9" , "3.10" , "3.11" ] )
115
+ @nox .session (python = TEST_PYTHON_VERSIONS )
70
116
def unit (session ):
71
117
default (session , os .path .join ("tests" , "unit" ))
72
118
73
119
74
- @nox .session (python = [ "3.8" , "3.9" , "3.10" , "3.11" ] )
120
+ @nox .session (python = TEST_PYTHON_VERSIONS )
75
121
def system (session ):
76
122
default (session , os .path .join ("tests" , "system" ))
77
123
78
124
79
- @nox .session (python = [ "3.8" , "3.9" , "3.10" , "3.11" ] )
125
+ @nox .session (python = TEST_PYTHON_VERSIONS )
80
126
def test (session ):
81
127
default (session , os .path .join ("tests" , "unit" ))
82
128
default (session , os .path .join ("tests" , "system" ))
0 commit comments