1
- import distutils .cmd
2
- import distutils . log
1
+ from distutils .cmd import Command
2
+ from distutils import log
3
3
import os
4
4
import pathlib
5
5
import subprocess
25
25
]
26
26
27
27
28
- class PylintCmd (distutils .cmd .Command ):
28
+ def run_cmd (cmd , reporter ) -> None :
29
+ """Run arbitrary command as subprocess"""
30
+ reporter ("Run command: {}" .format (str (cmd )), level = log .DEBUG )
31
+ try :
32
+ subprocess .check_call (cmd )
33
+ except subprocess .CalledProcessError as ex :
34
+ reporter (str (ex ), level = log .ERROR )
35
+ exit (1 )
36
+
37
+
38
+ class Pylint (Command ):
29
39
"""Custom command to run Pylint"""
30
40
31
- description = "run Pylint on src, tests and examples dir"
32
- user_options = [
33
- ("pylint-rcfile=" , None , "path to Pylint config file" ),
34
- ]
41
+ description = "run Pylint on kentik_api, tests and examples directories; read configuratin from pyproject.toml"
42
+ user_options = []
35
43
36
44
def initialize_options (self ):
37
- """Set default values for options."""
38
- self .pylint_rcfile = ""
45
+ pass
39
46
40
47
def finalize_options (self ):
41
- """Post-process options."""
42
- if self .pylint_rcfile :
43
- assert os .path .exists (self .pylint_rcfile ), "Pylint config file {} does not exist." .format (
44
- self .pylint_rcfile
45
- )
48
+ pass
46
49
47
50
def run (self ):
48
51
"""Run command."""
49
- cmd = ["pylint" ]
50
- paths = ["./kentik_api" , "./tests" , "./examples" ]
51
- if self .pylint_rcfile :
52
- cmd .append ("--rcfile={}" .format (self .pylint_rcfile ))
52
+ cmd = ["pylint" , "--exit-zero" ]
53
+ paths = ["kentik_api" , "tests" , "examples" ]
53
54
for path in paths :
54
55
cmd .append (path )
55
- self .announce ("Running command: %s" % str (cmd ), level = distutils .log .INFO )
56
- try :
57
- subprocess .check_call (cmd )
58
- except subprocess .CalledProcessError :
59
- pass
56
+ run_cmd (cmd , self .announce )
60
57
61
58
62
- class MypyCmd ( distutils . cmd . Command ):
59
+ class Mypy ( Command ):
63
60
"""Custom command to run Mypy"""
64
61
65
- description = "run Mypy on kentik_api directory "
62
+ description = "run Mypy on kentik_api, tests and examples directories; read configuratin from pyproject.toml "
66
63
user_options = [("packages=" , None , "Packages to check with mypy" )]
67
64
68
65
def initialize_options (self ):
@@ -79,21 +76,47 @@ def run(self):
79
76
cmd = ["mypy" ]
80
77
for package in self .packages :
81
78
cmd .append (package )
82
- self .announce ("Run command: {}" .format (str (cmd )), level = distutils .log .INFO )
83
- try :
84
- subprocess .check_call (cmd )
85
- except subprocess .CalledProcessError :
86
- self .announce (
87
- "Command: {} returned error. Check if tests are not failing." .format (str (cmd )), level = distutils .log .INFO
88
- )
79
+ run_cmd (cmd , self .announce )
80
+
81
+
82
+ class Black (Command ):
83
+ """Custom command to run black"""
84
+
85
+ description = "run black on all relevant code; read configuratin from pyproject.toml"
86
+ user_options = []
87
+
88
+ def initialize_options (self ) -> None :
89
+ pass
90
+
91
+ def finalize_options (self ):
92
+ pass
93
+
94
+ def run (self ):
95
+ """Run command"""
96
+ cmd = ["black" , "." ]
97
+ run_cmd (cmd , self .announce )
98
+
99
+
100
+ class PytestCmd (Command ):
101
+ """Custom command to run pytest"""
102
+
103
+ description = "run pytest on all relevant code; read configuratin from pyproject.toml"
104
+ user_options = []
105
+
106
+ def initialize_options (self ) -> None :
107
+ pass
108
+
109
+ def finalize_options (self ):
110
+ pass
111
+
112
+ def run (self ):
113
+ """Run command"""
114
+ cmd = ["pytest" ]
115
+ run_cmd (cmd , self .announce )
89
116
90
117
91
118
setup (
92
119
name = "kentik-api" ,
93
- use_scm_version = {
94
- "root" : ".." ,
95
- "relative_to" : __file__ ,
96
- },
97
120
description = "SDK library for Kentik API" ,
98
121
maintainer = "Martin Machacek" ,
99
122
maintainer_email = "[email protected] " ,
@@ -102,15 +125,13 @@ def run(self):
102
125
url = "https://github.com/kentik/community_sdk_python/tree/main/kentik_api_library" ,
103
126
license = "Apache-2.0" ,
104
127
include_package_data = True ,
128
+ python_requires = ">=3.8, <4" ,
105
129
install_requires = ["dacite>=1.6.0" , "requests[socks]>=2.25.0" , "typing-extensions>=3.7.4.3" , "urllib3>=1.26.0" ],
106
- setup_requires = ["pytest-runner" , "pylint-runner" , "setuptools_scm" , "wheel" ],
107
130
tests_require = ["httpretty" , "pytest" , "pylint" ],
108
- extras_require = {
109
- "analytics" : ["pandas>=1.2.4" , "pyyaml>=5.4.1" , "fastparquet>=0.6.3" ],
110
- },
131
+ extras_require = {"analytics" : ["pandas>=1.2.4" , "pyyaml>=5.4.1" , "fastparquet>=0.6.3" ]},
111
132
packages = PACKAGES ,
112
133
package_dir = {pkg : os .path .join (* pkg .split ("." )) for pkg in PACKAGES },
113
- cmdclass = {"pylint" : PylintCmd , "mypy" : MypyCmd },
134
+ cmdclass = {"pylint" : Pylint , "mypy" : Mypy , "black" : Black , "pytest" : PytestCmd },
114
135
classifiers = [
115
136
"License :: OSI Approved :: Apache Software License" ,
116
137
],
0 commit comments