Skip to content

Commit 7205e4b

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

File tree

7 files changed

+330
-147
lines changed

7 files changed

+330
-147
lines changed

.github/workflows/checks.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Checks
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
check:
7+
name: Check ${{ matrix.env }} on Python ${{ matrix.python-version }}
8+
runs-on: ubuntu-latest
9+
10+
timeout-minutes: 10
11+
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
env:
16+
- "style"
17+
- "format"
18+
- "type"
19+
python-version:
20+
- "3.12"
21+
22+
steps:
23+
- name: Checkout sources
24+
uses: actions/checkout@v4
25+
26+
- name: Install uv
27+
uses: astral-sh/setup-uv@v4
28+
with:
29+
# Install a specific version of uv.
30+
version: "0.5.8"
31+
enable-cache: true
32+
33+
- name: Install tox
34+
run: uv tool install --python-preference only-managed --python ${{ matrix.python-version }} tox --with tox-uv --with tox-gh
35+
36+
- name: Install Python ${{ matrix.python-version }}
37+
run: uv python install --python-preference only-managed ${{ matrix.python-version }}
38+
39+
- name: Run ${{ matrix.env }}
40+
run: make tox
41+
env:
42+
TOX_GH_MAJOR_MINOR: ${{ matrix.env }}

.github/workflows/run-tests.yml

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

.github/workflows/tests.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Tests
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
test:
7+
name: Run tests with Python ${{ 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 tox
37+
run: uv tool install --python-preference only-managed --python ${{ matrix.env }} tox --with tox-uv --with tox-gh
38+
39+
- name: Install Python
40+
run: uv python install --python-preference only-managed ${{ matrix.env }}
41+
42+
- name: Run test suite
43+
run: make tox
44+
env:
45+
TOX_GH_MAJOR_MINOR: ${{ matrix.env }}

Makefile

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@
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
7+
uv sync --all-groups
108

11-
deps-genproto: ## install deps (library & development)
12-
python3 -m pip install --upgrade pip
13-
python3 -m pip install -r requirements-genproto.txt
9+
deps-genproto:
10+
uv sync --group genproto
11+
12+
deps-dev:
13+
uv sync --group dev
1414

1515
tox: ## run ALL checks for ALL available python versions
16-
python3 -m tox
16+
uv run tox
1717

1818
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]))'`
19+
uv run tox -e `python3 -c 'import platform; print("py" + "".join(platform.python_version_tuple()[:2]))'`
2020

2121
test: ## run tests ONLY for current python version
22-
python3 -m pytest
22+
uv run pytest
2323

2424
lint: ## run linters, formatters for current python versions
25-
python3 -m flake8 yandexcloud
26-
python3 -m pylint yandexcloud
27-
python3 -m mypy yandexcloud
25+
uv run flake8 yandexcloud
26+
uv run pylint yandexcloud
27+
uv run mypy yandexcloud
2828

2929
format:
30-
python3 -m isort yandexcloud tests examples
31-
python3 -m black yandexcloud tests examples
30+
uv run isort yandexcloud tests examples
31+
uv run black yandexcloud tests examples
3232

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

4040
proto: ## regenerate code from protobuf
4141
rm -rf yandex
42-
python3 -m grpc_tools.protoc \
42+
uv run -m grpc_tools.protoc \
4343
--proto_path=cloudapi \
4444
--proto_path=cloudapi/third_party/googleapis \
4545
--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: 77 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",
52+
"mypy-protobuf==3.6.0",
5353
]
54-
lint = [
54+
type = [
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,65 @@ 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+
"genproto",
160+
"dev" # without it cannot import jwt and cryptography dependencies and E0401 is raised
161+
]
162+
commands = [["mypy", "yandexcloud"]] # TODO: add `tests` directory
163+
164+
[tool.tox.env.format]
165+
description = "Format code with black and isort"
166+
skip_install = true
167+
dependency_groups = [
168+
"format",
169+
]
170+
commands = [
171+
["black", "--check", "--diff", "yandexcloud"],
172+
["isort", "--check", "--diff", "yandexcloud"],
173+
]
174+
175+
[tool.tox.env.style]
176+
description = "Check style with flake8 and pylint"
177+
skip_install = true
178+
dependency_groups = [
179+
"style",
180+
"dev" # without it cannot import yandexcloud dependencies and E0401 is raised
181+
]
182+
commands = [
183+
["flake8", "yandexcloud"],
184+
["pylint", "yandexcloud"],
185+
]
186+
187+
[tool.tox.gh.python]
188+
# uncomment when upgrade grpcio-tools, current version does not work with 3.13
189+
# "3.13" = ["3.13", "type", "format", "style"]
190+
"3.12" = ["3.12"]
191+
"3.11" = ["3.11"]
192+
"3.10" = ["3.10"]
193+
"3.9" = ["3.9"]
194+
"type" = ["type"]
195+
"format" = ["format"]
196+
"style" = ["style"]

0 commit comments

Comments
 (0)