Skip to content

Commit ccdfafb

Browse files
committed
Migrate to pyproject.toml
1 parent e0a0031 commit ccdfafb

File tree

6 files changed

+113
-67
lines changed

6 files changed

+113
-67
lines changed

.github/workflows/kentik-api.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,26 @@ jobs:
3939
with:
4040
python-version: ${{ matrix.python-version }}
4141
architecture: x64
42-
- name: Install requirements
42+
- name: Install dependencies
4343
working-directory: ./kentik_api_library
44-
run: pip3 install -r requirements.txt
45-
- name: PyTest
46-
working-directory: ./kentik_api_library
47-
run: python3 setup.py pytest
44+
run: |
45+
set -xe
46+
python -VV
47+
python -m site
48+
python -m pip install --upgrade -r requirements.txt
49+
python -m pip install --upgrade -r requirements-dev.txt
4850
- name: Black
49-
uses: piotrpawlaczek/python-blacken@release/stable
50-
with:
51-
path: './kentik_api_library'
52-
line-length: '120'
53-
- name: PyLint
5451
working-directory: ./kentik_api_library
55-
run: python3 setup.py pylint
52+
run: python3 setup.py black
5653
- name: Mypy
5754
working-directory: ./kentik_api_library
5855
run: python3 setup.py mypy
56+
- name: PyLint
57+
working-directory: ./kentik_api_library
58+
run: python3 setup.py pylint
59+
- name: PyTest
60+
working-directory: ./kentik_api_library
61+
run: python3 setup.py pytest
5962

6063
build:
6164
needs: python-versions-setup

kentik_api_library/pyproject.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[build-system]
2+
3+
requires = ["setuptools", "wheel", "setuptools_scm", "gitpython", "pytest-runner", "pylint-runner"]
4+
build-backend = "setuptools.build_meta"
5+
6+
[tool.black]
7+
line-length = 120
8+
target-version = ['py39']
9+
check = true
10+
fast = true
11+
12+
[tool.isort]
13+
profile = "black"
14+
known_local_folder = ["kentik_api", "examples", "tests"]
15+
line_length = 120
16+
17+
[tool.mypy]
18+
ignore_missing_imports = true
19+
exclude = "(generated|build)/"
20+
21+
[tool.pytest.ini_options]
22+
testpaths = ["tests/integration", "tests/unit"]
23+
24+
[tool.pylint]
25+
26+
[[tool.mypy.overrides]]
27+
module = "/generated/*"
28+
ignore_errors = true
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
black==21.11b1
2+
isort==5.8.0
3+
mypy-extensions==0.4.3
4+
mypy==0.902
5+
pylint==2.8.3
6+
pytest-pylint==0.18.0
7+
pytest==6.2.4
8+
types-PyYAML==5.4.1
9+
types-requests==2.26.0

kentik_api_library/requirements.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,18 @@ fastparquet==0.6.3
77
httpretty==1.1.3
88
idna==2.10
99
iniconfig==1.1.1
10-
isort==5.8.0
1110
lazy-object-proxy==1.6.0
1211
mccabe==0.6.1
13-
mypy-extensions==0.4.3
14-
mypy==0.902
1512
packaging==20.9
1613
pluggy==0.13.1
1714
py==1.10.0
18-
pylint==2.8.3
1915
pyparsing==2.4.7
20-
pytest-pylint==0.18.0
21-
pytest==6.2.4
2216
python-http-client==3.3.2
2317
requests[socks]==2.25.1
2418
six==1.16.0
2519
toml==0.10.2
2620
traitlets==5.0.5
2721
typed-ast==1.4.3
28-
types-PyYAML==5.4.1
2922
typing-extensions==3.10.0.0
3023
urllib3==1.26.4
3124
wheel==0.36.2

kentik_api_library/setup.cfg

Lines changed: 0 additions & 8 deletions
This file was deleted.

kentik_api_library/setup.py

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import distutils.cmd
2-
import distutils.log
1+
from distutils.cmd import Command
2+
from distutils import log
33
import os
44
import pathlib
55
import subprocess
@@ -25,44 +25,41 @@
2525
]
2626

2727

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):
2939
"""Custom command to run Pylint"""
3040

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 = []
3543

3644
def initialize_options(self):
37-
"""Set default values for options."""
38-
self.pylint_rcfile = ""
45+
pass
3946

4047
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
4649

4750
def run(self):
4851
"""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"]
5354
for path in paths:
5455
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)
6057

6158

62-
class MypyCmd(distutils.cmd.Command):
59+
class Mypy(Command):
6360
"""Custom command to run Mypy"""
6461

65-
description = "run Mypy on kentik_api directory"
62+
description = "run Mypy on kentik_api, tests and examples directories; read configuratin from pyproject.toml"
6663
user_options = [("packages=", None, "Packages to check with mypy")]
6764

6865
def initialize_options(self):
@@ -79,21 +76,47 @@ def run(self):
7976
cmd = ["mypy"]
8077
for package in self.packages:
8178
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)
89116

90117

91118
setup(
92119
name="kentik-api",
93-
use_scm_version={
94-
"root": "..",
95-
"relative_to": __file__,
96-
},
97120
description="SDK library for Kentik API",
98121
maintainer="Martin Machacek",
99122
maintainer_email="[email protected]",
@@ -102,15 +125,13 @@ def run(self):
102125
url="https://github.com/kentik/community_sdk_python/tree/main/kentik_api_library",
103126
license="Apache-2.0",
104127
include_package_data=True,
128+
python_requires=">=3.8, <4",
105129
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"],
107130
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"]},
111132
packages=PACKAGES,
112133
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},
114135
classifiers=[
115136
"License :: OSI Approved :: Apache Software License",
116137
],

0 commit comments

Comments
 (0)