Skip to content

Commit

Permalink
setup new workflow for checks using tox and uv
Browse files Browse the repository at this point in the history
  • Loading branch information
Islam Alibekov committed Dec 13, 2024
1 parent 07ce4b2 commit 663c72b
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 174 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Checks

on: [pull_request]

jobs:
test:
name: test with ${{ matrix.env }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 10

strategy:
fail-fast: false
matrix:
env:
- "3.13"
- "3.12"
# - "3.11"
# - "3.10"
# - "3.9"
os:
- ubuntu-latest
# - macos-latest

steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
# Install a specific version of uv.
version: "0.5.8"
enable-cache: true

# - name: Install dependencies
# run: make deps

# - name: Install tox
# run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv --with tox-gh

- name: Install Python
# Python 3.13 was installed above already
# if: matrix.env != '3.13'
run: uv python install --python-preference only-managed ${{ matrix.env }}

- name: Install dependencies
run: make deps

- name: Run test suite
run: tox run
env:
TOX_GH_MAJOR_MINOR: ${{ matrix.env }}
53 changes: 32 additions & 21 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
name: Tests
# name: Tests

on: [pull_request]
# on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
# jobs:
# build:
# runs-on: ubuntu-latest
# timeout-minutes: 10

strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
# strategy:
# fail-fast: false
# matrix:
# python-version:
# - "3.9"
# - "3.10"
# - "3.11"
# - "3.12"
# - "3.13"

steps:
- name: Checkout sources
uses: actions/checkout@v4
# steps:
# - name: Checkout sources
# uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# - name: Install uv
# uses: astral-sh/setup-uv@v4
# with:
# # Install a specific version of uv.
# version: "0.5.8"

- name: Install dependencies
run: make deps
# - name: Set up Python
# uses: actions/setup-python@v5
# with:
# python-version: ${{ matrix.python-version }}

- name: Run checks
run: make tox
# - name: Install dependencies
# run: make deps

# - name: Run checks
# run: make tox
22 changes: 8 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,25 @@
REPO_ROOT:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

deps: ## install deps (library & development)
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements-dev.txt
python3 -m pip install setuptools wheel

deps-genproto: ## install deps (library & development)
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements-genproto.txt
uv sync --all-extras

tox: ## run ALL checks for ALL available python versions
python3 -m tox
uv run tox

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

test: ## run tests ONLY for current python version
python3 -m pytest
uv run pytest

lint: ## run linters, formatters for current python versions
python3 -m flake8 yandexcloud
python3 -m pylint yandexcloud
python3 -m mypy yandexcloud
uv run flake8 yandexcloud
uv run pylint yandexcloud
uv run mypy yandexcloud

format:
python3 -m isort yandexcloud tests examples
python3 -m black yandexcloud tests examples
uv run isort yandexcloud tests examples
uv run black yandexcloud tests examples

test-all-versions: ## run test for multiple python versions using docker
# python 3.12 and 3.13 are not provided in image so we skip them
Expand Down
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[license-image]: https://img.shields.io/github/license/yandex-cloud/python-sdk.svg
[license-url]: https://github.com/yandex-cloud/python-sdk/blob/master/LICENSE

# Yandex.Cloud SDK (Python)
# Yandex.Cloud SDK (Python)

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

Expand Down Expand Up @@ -42,7 +42,7 @@ sdk = yandexcloud.SDK()
### Service Account Keys

```python
# you can store and read it from JSON file
# you can store and read it from JSON file
sa_key = {
"id": "...",
"service_account_id": "...",
Expand Down Expand Up @@ -150,18 +150,33 @@ Notice: if both overrides are used for same endpoint, override by client has pri
```python
from yandexcloud import SDK, set_up_yc_api_endpoint
kz_region_endpoint = "api.yandexcloud.kz"
# this will make SDK list endpoints from KZ yc installation
# this will make SDK list endpoints from KZ yc installation
sdk = SDK(iam_token="t1.9eu...", endpoint="api.yandexcloud.kz")
# or you can use global function
set_up_yc_api_endpoint(kz_region_endpoint)
```

## Contributing
### Dependencies
We use [uv](https://docs.astral.sh/uv) to manage dependencies.
Install it with official standalone installer:
`curl -LsSf https://astral.sh/uv/install.sh | sh`

#### Installing dependencies
Use `make deps` command to install library, its production and development dependencies.

#### Adding new project dependency with uv
`uv add cryptography`

#### Adding new optional dependency with uv
add to `dev` extras section
`uv add pre-commit --optional dev`

add to `genproto` extras section
`uv add grpcio-tools --optional genproto`

### Formatting
Use `make format` to autoformat code with black tool.
Use `make format` to autoformat code with black tool.

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


### Maintaining
If pull request consists of several meaningful commits, that should be preserved,
then use "Rebase and merge" option. Otherwise use "Squash and merge".
If pull request consists of several meaningful commits, that should be preserved,
then use "Rebase and merge" option. Otherwise use "Squash and merge".

New release (changelog, tag and pypi upload) will be automatically created
New release (changelog, tag and pypi upload) will be automatically created
on each push to master via Github Actions workflow.
74 changes: 47 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,23 @@ Homepage = "https://github.com/yandex-cloud/python-sdk"

[project.optional-dependencies]
dev = [
"pre-commit>=4.0.1",
"python-semantic-release>=v9.8.8",
"tox-gh-actions>=3.2.0",
"tox-gh>=1.3.1",
"tox>=4.14.2",
"yandexcloud[format,genproto,lint,test]",
"pre-commit>=4.0.1",
]
format = [
"black>=24.4.2",
"isort>=5.13.2",
]
genproto = [
"grpcio-tools>=1.59.3",
"mypy-protobuf>=3.6.0",
"mypy-protobuf==3.6.0",
]
lint = [
"flake8>=7.0.0",
"flake8-pyproject>=1.2.3",
"mypy>=1.10",
"pylint>=3.1.0",
]
Expand Down Expand Up @@ -126,27 +127,46 @@ module = [
ignore_missing_imports = true

[tool.tox]
legacy_tox_ini = """
[gh-actions]
python =
3.9: py39
3.10: py310
3.11: py311
3.12: py312
3.13: py313
[tox]
envlist = py{39,310,311,312,313}
[testenv]
deps = -rrequirements-dev.txt
commands =
pytest tests
flake8 yandexcloud
pylint yandexcloud
mypy yandexcloud
isort --diff yandexcloud setup.py
isort --check yandexcloud setup.py
black --diff yandexcloud setup.py
black --check yandexcloud setup.py
"""
env_list = [
"py39",
"py310",
"py311",
"py312",
"py313"
]

[tool.tox.env_run_base]
description = "Run tests under {base_python}"
commands = [["pytest"]]

[tool.tox.env.type]
skip_install = true
# deps = ["mypy"]
commands = [["mypy", "yandexcloud"]] # TODO: add `tests` directory

[tool.tox.env.sort]
skip_install = true
# deps = ["isort"]
commands = [["isort", "--check", "--diff", "yandexcloud"]]

[tool.tox.env.format]
skip_install = true
deps = ["black"]
commands = [["black", "--check", "--diff", "yandexcloud"]]

[tool.tox.env.style]
skip_install = true
deps = ["flake8", "flake8-pyproject"]
commands = [["flake8", "yandexcloud"]]

[tool.tox.env.lint]
skip_install = true
deps = ["pylint"]
commands = [["pylint", "yandexcloud"]]

[tool.tox.gh.python]
"3.13" = ["3.13", "type", "sort", "format", "style", "lint"]
"3.12" = ["3.12"]
"3.11" = ["3.11"]
"3.10" = ["3.10"]
"3.9" = ["3.9"]
Loading

0 comments on commit 663c72b

Please sign in to comment.