1616
1717
1818from __future__ import absolute_import
19+
1920import os
21+
2022import nox
2123
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" ]
2329
24- if os .path .exists ("samples" ):
25- BLACK_PATHS .append ("samples" )
30+ TEST_PYTHON_VERSIONS = ["3.8" , "3.9" , "3.10" , "3.11" ]
2631
2732
2833@nox .session
@@ -31,22 +36,63 @@ def lint(session):
3136 Returns a failure if the linters find linting errors or sufficiently
3237 serious code quality issues.
3338 """
34- session .install ("-r" , "requirements-test.txt" )
3539 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 )
3858 session .run (
3959 "flake8" ,
40- "--import-order-style=google" ,
41- "--application-import-names=google,tests" ,
4260 "google" ,
4361 "tests" ,
4462 )
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+ )
4671 session .run ("python" , "setup.py" , "sdist" )
4772 session .run ("twine" , "check" , "dist/*" )
4873
4974
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+
5096def default (session , path ):
5197 # Install all test dependencies, then install this package in-place.
5298 session .install ("-r" , "requirements-test.txt" )
@@ -55,7 +101,7 @@ def default(session, path):
55101 # Run py.test against the unit tests.
56102 session .run (
57103 "pytest" ,
58- "--cov=google/ cloud/ sql/ connector" ,
104+ "--cov=google. cloud. sql. connector" ,
59105 "-v" ,
60106 "--cov-config=.coveragerc" ,
61107 "--cov-report=" ,
@@ -66,17 +112,17 @@ def default(session, path):
66112 )
67113
68114
69- @nox .session (python = [ "3.8" , "3.9" , "3.10" , "3.11" ] )
115+ @nox .session (python = TEST_PYTHON_VERSIONS )
70116def unit (session ):
71117 default (session , os .path .join ("tests" , "unit" ))
72118
73119
74- @nox .session (python = [ "3.8" , "3.9" , "3.10" , "3.11" ] )
120+ @nox .session (python = TEST_PYTHON_VERSIONS )
75121def system (session ):
76122 default (session , os .path .join ("tests" , "system" ))
77123
78124
79- @nox .session (python = [ "3.8" , "3.9" , "3.10" , "3.11" ] )
125+ @nox .session (python = TEST_PYTHON_VERSIONS )
80126def test (session ):
81127 default (session , os .path .join ("tests" , "unit" ))
82128 default (session , os .path .join ("tests" , "system" ))
0 commit comments