Skip to content

Commit 94cd53c

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

File tree

6 files changed

+308
-140
lines changed

6 files changed

+308
-140
lines changed

.github/workflows/check.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Checks
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
test:
7+
name: test 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+
# - "3.13"
16+
- "3.12"
17+
# - "3.11"
18+
# - "3.10"
19+
# - "3.9"
20+
os:
21+
- ubuntu-latest
22+
# - macos-latest
23+
24+
steps:
25+
- name: Checkout sources
26+
uses: actions/checkout@v4
27+
28+
- name: Install uv
29+
uses: astral-sh/setup-uv@v4
30+
with:
31+
# Install a specific version of uv.
32+
version: "0.5.8"
33+
enable-cache: true
34+
35+
# - name: Install dependencies
36+
# run: make deps
37+
38+
# - name: Install tox
39+
# run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv --with tox-gh
40+
41+
- name: Install Python
42+
# Python 3.13 was installed above already
43+
# if: matrix.env != '3.13'
44+
run: uv python install --python-preference only-managed ${{ matrix.env }}
45+
46+
- name: Install dependencies
47+
run: make deps
48+
49+
- name: Run test suite
50+
run: uv run tox
51+
env:
52+
TOX_GH_MAJOR_MINOR: ${{ matrix.env }}

.github/workflows/run-tests.yml

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
1-
name: Tests
1+
# name: Tests
22

3-
on: [pull_request]
3+
# on: [pull_request]
44

5-
jobs:
6-
build:
7-
runs-on: ubuntu-latest
8-
timeout-minutes: 10
5+
# jobs:
6+
# build:
7+
# runs-on: ubuntu-latest
8+
# timeout-minutes: 10
99

10-
strategy:
11-
fail-fast: false
12-
matrix:
13-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
10+
# strategy:
11+
# fail-fast: false
12+
# matrix:
13+
# python-version:
14+
# - "3.9"
15+
# - "3.10"
16+
# - "3.11"
17+
# - "3.12"
18+
# - "3.13"
1419

15-
steps:
16-
- name: Checkout sources
17-
uses: actions/checkout@v4
20+
# steps:
21+
# - name: Checkout sources
22+
# uses: actions/checkout@v4
1823

19-
- name: Set up Python
20-
uses: actions/setup-python@v5
21-
with:
22-
python-version: ${{ matrix.python-version }}
24+
# - name: Install uv
25+
# uses: astral-sh/setup-uv@v4
26+
# with:
27+
# # Install a specific version of uv.
28+
# version: "0.5.8"
2329

24-
- name: Install dependencies
25-
run: make deps
30+
# - name: Set up Python
31+
# uses: actions/setup-python@v5
32+
# with:
33+
# python-version: ${{ matrix.python-version }}
2634

27-
- name: Run checks
28-
run: make tox
35+
# - name: Install dependencies
36+
# run: make deps
37+
38+
# - name: Run checks
39+
# run: make tox

Makefile

Lines changed: 9 additions & 15 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
1913
python3 -m 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: 68 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,31 @@ 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[format,genproto,style,test]",
45+
"yandexcloud"
4546
]
4647
format = [
4748
"black>=24.4.2",
4849
"isort>=5.13.2",
4950
]
5051
genproto = [
51-
"grpcio-tools>=1.59.3",
52-
"mypy-protobuf>=3.6.0",
52+
"grpcio-tools==1.59.3",
53+
"mypy-protobuf==3.6.0",
54+
"mypy==1.10",
55+
"grpc-stubs>=1.53.0.5",
56+
"types-requests>=2.32.0.20241016",
57+
"types-six>=1.17.0.20241205",
5358
]
54-
lint = [
59+
style = [
5560
"flake8>=7.0.0",
56-
"mypy>=1.10",
57-
"pylint>=3.1.0",
61+
"flake8-pyproject>=1.2.3",
62+
"pylint==3.1.0",
5863
]
5964
test = [
6065
"pytest>=8.1.1",
@@ -126,27 +131,57 @@ module = [
126131
ignore_missing_imports = true
127132

128133
[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-
"""
134+
env_list = [
135+
"py39",
136+
"py310",
137+
"py311",
138+
"py312",
139+
"py313"
140+
]
141+
142+
[tool.tox.env_run_base]
143+
description = "Run tests under {base_python}"
144+
dependency_groups = [
145+
"test",
146+
]
147+
commands = [["pytest"]]
148+
149+
[tool.tox.env.type]
150+
description = "Check types with mypy"
151+
skip_install = true
152+
dependency_groups = [
153+
"genproto",
154+
"dev" # without it cannot import yandexcloud dependencies and [import-untyped] is raised
155+
]
156+
commands = [["mypy", "yandexcloud"]] # TODO: add `tests` directory
157+
158+
[tool.tox.env.format]
159+
description = "Format code with black and isort"
160+
skip_install = true
161+
dependency_groups = [
162+
"format",
163+
]
164+
commands = [
165+
["black", "--check", "--diff", "yandexcloud"],
166+
["isort", "--check", "--diff", "yandexcloud"],
167+
]
168+
169+
[tool.tox.env.style]
170+
description = "Check style with flake8 and pylint"
171+
skip_install = true
172+
dependency_groups = [
173+
"style",
174+
"dev" # without it cannot import yandexcloud dependencies and E0401 is raised
175+
]
176+
commands = [
177+
["flake8", "yandexcloud"],
178+
["pylint", "yandexcloud"],
179+
]
180+
181+
[tool.tox.gh.python]
182+
# uncomment when upgrade grpcio-tools, current version does not work with 3.13
183+
# "3.13" = ["3.13", "type", "format", "style"]
184+
"3.12" = ["3.12", "type", "format", "style"]
185+
"3.11" = ["3.11"]
186+
"3.10" = ["3.10"]
187+
"3.9" = ["3.9"]

0 commit comments

Comments
 (0)