Skip to content

Commit be6b47c

Browse files
author
Islam Alibekov
committed
setup new workflow for checks using tox and uv
1 parent 07ce4b2 commit be6b47c

File tree

6 files changed

+327
-149
lines changed

6 files changed

+327
-149
lines changed

.github/workflows/check.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Checks
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
test:
7+
name: Run tests with ${{ matrix.env }} on ${{ matrix.os }}
8+
runs-on: ${{ matrix.os }}
9+
timeout-minutes: 10
10+
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
env:
15+
# uncomment when upgrade grpcio-tools, current version does not work with 3.13
16+
# - "3.13"
17+
- "3.12"
18+
- "3.11"
19+
- "3.10"
20+
- "3.9"
21+
os:
22+
- ubuntu-latest
23+
# - macos-latest
24+
25+
steps:
26+
- name: Checkout sources
27+
uses: actions/checkout@v4
28+
29+
- name: Install uv
30+
uses: astral-sh/setup-uv@v4
31+
with:
32+
# Install a specific version of uv.
33+
version: "0.5.8"
34+
enable-cache: true
35+
36+
# - name: Install Python
37+
# run: uv python install --python-preference only-managed ${{ matrix.env }}
38+
39+
# - name: Install dependencies
40+
# run: uv sync --all-groups
41+
42+
- name: Install tox
43+
run: uv tool install --python-preference only-managed --python ${{ matrix.env }} tox --with tox-uv --with tox-gh
44+
45+
- name: Install Python
46+
run: uv python install --python-preference only-managed ${{ matrix.env }}
47+
48+
- name: Run test suite
49+
run: uv run tox
50+
env:
51+
TOX_GH_MAJOR_MINOR: ${{ matrix.env }}
52+
53+
check:
54+
name: Run ${{ matrix.env }} checks on ${{ matrix.python-version }}
55+
runs-on: ubuntu-latest
56+
57+
timeout-minutes: 10
58+
59+
strategy:
60+
fail-fast: false
61+
matrix:
62+
env:
63+
- "lint"
64+
- "format"
65+
- "type"
66+
python-version:
67+
- "3.12"
68+
69+
steps:
70+
- name: Checkout sources
71+
uses: actions/checkout@v4
72+
73+
- name: Install uv
74+
uses: astral-sh/setup-uv@v4
75+
with:
76+
# Install a specific version of uv.
77+
version: "0.5.8"
78+
enable-cache: true
79+
80+
# - name: Install Python
81+
# run: uv python install --python-preference only-managed ${{ matrix.env }}
82+
- name: Install tox
83+
run: uv tool install --python-preference only-managed --python ${{ matrix.python-version }} tox --with tox-uv --with tox-gh
84+
85+
- name: Install Python ${{ matrix.python-version }}
86+
run: uv python install --python-preference only-managed ${{ matrix.python-version }}
87+
88+
- name: Run ${{ matrix.env }}
89+
run: uv run tox
90+
env:
91+
TOX_GH_MAJOR_MINOR: ${{ matrix.env }}

.github/workflows/run-tests.yml

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

Makefile

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,25 @@
44
REPO_ROOT:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
55

66
deps: ## install deps (library & development)
7-
python3 -m pip install --upgrade pip
8-
python3 -m pip install -r requirements-dev.txt
9-
python3 -m pip install setuptools wheel
10-
11-
deps-genproto: ## install deps (library & development)
12-
python3 -m pip install --upgrade pip
13-
python3 -m pip install -r requirements-genproto.txt
7+
uv sync --all-groups
148

159
tox: ## run ALL checks for ALL available python versions
16-
python3 -m tox
10+
uv run tox
1711

1812
tox-current: ## run ALL checks ONLY for current python version
19-
python3 -m tox -e `python3 -c 'import platform; print("py" + "".join(platform.python_version_tuple()[:2]))'`
13+
uv run tox -e `python3 -c 'import platform; print("py" + "".join(platform.python_version_tuple()[:2]))'`
2014

2115
test: ## run tests ONLY for current python version
22-
python3 -m pytest
16+
uv run pytest
2317

2418
lint: ## run linters, formatters for current python versions
25-
python3 -m flake8 yandexcloud
26-
python3 -m pylint yandexcloud
27-
python3 -m mypy yandexcloud
19+
uv run flake8 yandexcloud
20+
uv run pylint yandexcloud
21+
uv run mypy yandexcloud
2822

2923
format:
30-
python3 -m isort yandexcloud tests examples
31-
python3 -m black yandexcloud tests examples
24+
uv run isort yandexcloud tests examples
25+
uv run black yandexcloud tests examples
3226

3327
test-all-versions: ## run test for multiple python versions using docker
3428
# python 3.12 and 3.13 are not provided in image so we skip them
@@ -39,7 +33,7 @@ submodule: ## update submodules
3933

4034
proto: ## regenerate code from protobuf
4135
rm -rf yandex
42-
python3 -m grpc_tools.protoc \
36+
uv run -m grpc_tools.protoc \
4337
--proto_path=cloudapi \
4438
--proto_path=cloudapi/third_party/googleapis \
4539
--python_out=. \

README.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[license-image]: https://img.shields.io/github/license/yandex-cloud/python-sdk.svg
1212
[license-url]: https://github.com/yandex-cloud/python-sdk/blob/master/LICENSE
1313

14-
# Yandex.Cloud SDK (Python)
14+
# Yandex.Cloud SDK (Python)
1515

1616
Need to automate your infrastructure or use services provided by Yandex.Cloud? We've got you covered.
1717

@@ -42,7 +42,7 @@ sdk = yandexcloud.SDK()
4242
### Service Account Keys
4343

4444
```python
45-
# you can store and read it from JSON file
45+
# you can store and read it from JSON file
4646
sa_key = {
4747
"id": "...",
4848
"service_account_id": "...",
@@ -150,18 +150,33 @@ Notice: if both overrides are used for same endpoint, override by client has pri
150150
```python
151151
from yandexcloud import SDK, set_up_yc_api_endpoint
152152
kz_region_endpoint = "api.yandexcloud.kz"
153-
# this will make SDK list endpoints from KZ yc installation
153+
# this will make SDK list endpoints from KZ yc installation
154154
sdk = SDK(iam_token="t1.9eu...", endpoint="api.yandexcloud.kz")
155155
# or you can use global function
156156
set_up_yc_api_endpoint(kz_region_endpoint)
157157
```
158158

159159
## Contributing
160160
### Dependencies
161+
We use [uv](https://docs.astral.sh/uv) to manage dependencies.
162+
Install it with official standalone installer:
163+
`curl -LsSf https://astral.sh/uv/install.sh | sh`
164+
165+
#### Installing dependencies
161166
Use `make deps` command to install library, its production and development dependencies.
162167

168+
#### Adding new project dependency with uv
169+
`uv add cryptography`
170+
171+
#### Adding new optional dependency with uv
172+
add to `dev` extras section
173+
`uv add pre-commit --group dev`
174+
175+
add to `genproto` extras section
176+
`uv add grpcio-tools --group genproto`
177+
163178
### Formatting
164-
Use `make format` to autoformat code with black tool.
179+
Use `make format` to autoformat code with black tool.
165180

166181
### Tests
167182
- `make test` to run tests for current python version
@@ -172,8 +187,8 @@ Use `make format` to autoformat code with black tool.
172187

173188

174189
### Maintaining
175-
If pull request consists of several meaningful commits, that should be preserved,
176-
then use "Rebase and merge" option. Otherwise use "Squash and merge".
190+
If pull request consists of several meaningful commits, that should be preserved,
191+
then use "Rebase and merge" option. Otherwise use "Squash and merge".
177192

178-
New release (changelog, tag and pypi upload) will be automatically created
193+
New release (changelog, tag and pypi upload) will be automatically created
179194
on each push to master via Github Actions workflow.

pyproject.toml

Lines changed: 76 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,32 @@ content-type = "text/markdown"
3535
[project.urls]
3636
Homepage = "https://github.com/yandex-cloud/python-sdk"
3737

38-
[project.optional-dependencies]
38+
[dependency-groups]
3939
dev = [
40+
"pre-commit>=4.0.1",
4041
"python-semantic-release>=v9.8.8",
41-
"tox-gh-actions>=3.2.0",
42+
"tox-gh>=1.3.1",
4243
"tox>=4.14.2",
43-
"yandexcloud[format,genproto,lint,test]",
44-
"pre-commit>=4.0.1",
44+
"yandexcloud"
4545
]
4646
format = [
4747
"black>=24.4.2",
4848
"isort>=5.13.2",
4949
]
5050
genproto = [
51-
"grpcio-tools>=1.59.3",
52-
"mypy-protobuf>=3.6.0",
51+
"grpcio-tools==1.59.3",
5352
]
54-
lint = [
53+
type = [
54+
"mypy-protobuf==3.6.0",
55+
"mypy==1.10",
56+
"grpc-stubs>=1.53.0.5",
57+
"types-requests>=2.32.0.20241016",
58+
"types-six>=1.17.0.20241205",
59+
]
60+
style = [
5561
"flake8>=7.0.0",
56-
"mypy>=1.10",
57-
"pylint>=3.1.0",
62+
"flake8-pyproject>=1.2.3",
63+
"pylint==3.1.0",
5864
]
5965
test = [
6066
"pytest>=8.1.1",
@@ -126,27 +132,64 @@ module = [
126132
ignore_missing_imports = true
127133

128134
[tool.tox]
129-
legacy_tox_ini = """
130-
[gh-actions]
131-
python =
132-
3.9: py39
133-
3.10: py310
134-
3.11: py311
135-
3.12: py312
136-
3.13: py313
137-
138-
[tox]
139-
envlist = py{39,310,311,312,313}
140-
141-
[testenv]
142-
deps = -rrequirements-dev.txt
143-
commands =
144-
pytest tests
145-
flake8 yandexcloud
146-
pylint yandexcloud
147-
mypy yandexcloud
148-
isort --diff yandexcloud setup.py
149-
isort --check yandexcloud setup.py
150-
black --diff yandexcloud setup.py
151-
black --check yandexcloud setup.py
152-
"""
135+
env_list = [
136+
"3.9",
137+
"3.10",
138+
"3.11",
139+
"3.12",
140+
# "3.13",
141+
"type",
142+
"format",
143+
"style",
144+
]
145+
skip_missing_interpreters = true
146+
147+
[tool.tox.env_run_base]
148+
description = "Run tests under {base_python}"
149+
dependency_groups = [
150+
"test",
151+
]
152+
commands = [["pytest"]]
153+
154+
[tool.tox.env.type]
155+
description = "Check types with mypy"
156+
skip_install = true
157+
dependency_groups = [
158+
"type",
159+
"dev" # without it cannot import jwt and cryptography dependencies and E0401 is raised
160+
]
161+
commands = [["mypy", "yandexcloud"]] # TODO: add `tests` directory
162+
163+
[tool.tox.env.format]
164+
description = "Format code with black and isort"
165+
skip_install = true
166+
dependency_groups = [
167+
"format",
168+
]
169+
commands = [
170+
["black", "--check", "--diff", "yandexcloud"],
171+
["isort", "--check", "--diff", "yandexcloud"],
172+
]
173+
174+
[tool.tox.env.style]
175+
description = "Check style with flake8 and pylint"
176+
skip_install = true
177+
dependency_groups = [
178+
"style",
179+
"dev" # without it cannot import yandexcloud dependencies and E0401 is raised
180+
]
181+
commands = [
182+
["flake8", "yandexcloud"],
183+
["pylint", "yandexcloud"],
184+
]
185+
186+
[tool.tox.gh.python]
187+
# uncomment when upgrade grpcio-tools, current version does not work with 3.13
188+
# "3.13" = ["3.13", "type", "format", "style"]
189+
"3.12" = ["3.12"]
190+
"3.11" = ["3.11"]
191+
"3.10" = ["3.10"]
192+
"3.9" = ["3.9"]
193+
"type" = ["type"]
194+
"format" = ["format"]
195+
"style" = ["style"]

0 commit comments

Comments
 (0)