Skip to content

Commit

Permalink
feat: use pyproject.toml and uv publish pkg (#6)
Browse files Browse the repository at this point in the history
* feat: use pyproject.toml and uv publish pkg

* feat: use pyproject.toml and uv publish pkg

* feat: use pyproject.toml and uv publish pkg

* feat: use pyproject.toml and uv publish pkg
  • Loading branch information
ifooth authored Nov 7, 2024
1 parent 26a8f7f commit 10784bf
Show file tree
Hide file tree
Showing 12 changed files with 429 additions and 449 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: lint
on: [push, pull_request]
jobs:
lint:
name: lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Lint
if: matrix.python-version != '3.13'
# 3.13 以下锁定版本
run: |
uv sync --frozen
uv run ruff check
- name: Lint 3.13
if: matrix.python-version == '3.13'
# 3.13 以上安装最新版本
run: |
uv sync -U
uv run ruff check
- name: Test
run: |
uv run pytest -s tests/
- name: Build
run: |
uv build
31 changes: 15 additions & 16 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@ jobs:
name: publish package to pypI
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3 # 拉取最新代码
- name: Checkout
uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v3
- name: Set up python
uses: actions/setup-python@v5
with:
python-version: '3.10.12' # 选择您的 Python 版本
python-version: "3.8"

- name: install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel setuptools
- name: build and publish
- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
python setup.py sdist bdist_wheel
python -m pip install twine
python -m twine upload --skip-existing dist/*
uv sync --frozen
uv run ruff check
uv run pytest -s tests/
uv build
uv publish
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.vscode
.vscode
.ruff_cache
366 changes: 0 additions & 366 deletions poetry.lock

This file was deleted.

49 changes: 26 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
[tool.poetry]
[project]
name = "bk-bscp"
version = "0.1.0"
version = "0.2.0"
description = "The Python SDK for blueking bscp project."
include = ["bk-bscp/py.typed"]
readme = "readme.md"
authors = ["blueking <[email protected]>"]
license = "MIT"
license = { file = "LICENSE.txt" }
authors = [{ name = "blueking", email = "[email protected]" }]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3 :: Only",
]

[tool.poetry.dependencies]
python = "^3.8"
grpcio = "^1.60.0"
typing-extensions = "^4.9.0"
protobuf = "^4.25.2"

requires-python = ">=3.8"
dependencies = [
"grpcio>=1.60.0",
"protobuf>=4.25.2",
"typing-extensions>=4.9.0",
]
[project.urls]
Home = "https://github.com/TencentBlueKing/bscp-python-sdk"

[tool.poetry.group.dev.dependencies]
grpcio-tools = "^1.60.0"
ruff = "^0.1.13"
pytest = "^7.4.4"
mypy = "^1.9.0"
[dependency-groups]
dev = ["grpcio-tools>=1.60.0", "mypy>=1.9.0", "pytest>=7.4.4", "ruff>=0.7.2"]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
requires = ["setuptools>=61.0.0"]
build-backend = "setuptools.build_meta"

[tool.ruff]
line-length = 119
Expand All @@ -53,7 +58,7 @@ select = [
# 理论上来说,ignore 规则列表中的条目越少越好。但在实际项目中,选择性地忽略某些规则常常是必须的。
# 下面收集了常见的待忽略规则集,并将其分为两类:“推荐忽略”和“谨慎忽略”。“推荐忽略”类中所包含的规
# 则,所有项目建议默认启用。“谨慎忽略”类中的规则,项目可酌情添加。
#
#
# 除此处列出的规则以外,不建议随意扩充忽略规则列表。
ignore = [
# === 推荐忽略 ===
Expand Down Expand Up @@ -86,14 +91,12 @@ ignore = [
"N817",
# pep8-naming: 忽略后,不强制要求异常类的名字必须以 Error 结尾
"N818",
# perflint: 忽略后,不强制要求一定用推导式替代 for 循环,因为有时循环的可读性更好
# perflint: 忽略后,不强制要求一定用推导式替代 for 循环,因为有时循环的可读性更好
"PERF401",
# perflint: 忽略后,允许在循环中使用 try except 代码块,因为这对性能影响微乎其微,有时可读性更好
"PERF203",
# tryceratops: 忽略后,允许抛出异常时,使用较长的字符串作为异常信息,可能会降低异常的可使用性
"TRY003",
# tryceratops: 忽略后,允许在 except 语句块中使用裸的 raise 语句,不要求必须使用 raise ... from
"TRY200",
# flake8-simplify: 忽略后,允许使用 exception: pass 语句,不要求必须用 contextlib.suppress 替换
"SIM105",
# flake8-simplify: 忽略后,不强制要求用三元表达式替换普通的短 if-else 语句
Expand Down
10 changes: 6 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## BSCP-PYTHON-SDK

[![license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)]()

[EnglishDocs](./readme_en.md)
Expand Down Expand Up @@ -43,7 +44,6 @@ with BscpClient(server_addrs, token, biz_id) as client:

- 在这种风格下,client 的连接会自动关闭,适合短连接,操作次数不多时的场景


### 示例文件

更多示例代码请参考 examples/ 目录。
Expand All @@ -52,11 +52,13 @@ with BscpClient(server_addrs, token, biz_id) as client:

执行单元测试:

poetry run pytest -s tests/
```bash
uv run pytest -s tests/
```

一些相关的环境变量配置项:

```
```bash
# 设置日志打印级别,默认为 INFO
BSCP_LOG_LEVEL=DEBUG
```
Expand Down Expand Up @@ -112,4 +114,4 @@ bash sync_grpc_generated.sh {bscp_project_path}

## License

bscp-python-sdk 是基于MIT协议, 详细请参考[LICENSE](./LICENSE.txt)
bscp-python-sdk 是基于MIT协议, 详细请参考[LICENSE](./LICENSE.txt)
10 changes: 6 additions & 4 deletions readme_en.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## BSCP-PYTHON-SDK

[![license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)]()

[中文文档](./readme.md)
Expand Down Expand Up @@ -43,7 +44,6 @@ with BscpClient(server_addrs, token, biz_id) as client:

- In this style, the client's connection will be automatically closed, which is suitable for scenarios where the connection is short and the number of operations is small.


### Sample files

For more sample code, please refer to the examples/ directory.
Expand All @@ -52,11 +52,13 @@ For more sample code, please refer to the examples/ directory.

Execute unit tests:

poetry run pytest -s tests/
```bash
uv run pytest -s tests/
```

Some related environment variable configuration items:

```
```bash
# Set the log printing level, the default is INFO
BSCP_LOG_LEVEL=DEBUG
```
Expand Down Expand Up @@ -113,4 +115,4 @@ If you have good ideas or suggestions, please let us know by Issues or Pull Requ

## License

bscp-go is based on the MIT protocol. Please refer to [LICENSE](./LICENSE.txt) for details.
bscp-go is based on the MIT protocol. Please refer to [LICENSE](./LICENSE.txt) for details.
9 changes: 0 additions & 9 deletions setup.cfg

This file was deleted.

21 changes: 0 additions & 21 deletions setup.py

This file was deleted.

5 changes: 3 additions & 2 deletions tests/test_client_integrated.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""The integrated tests for bk_bscp module, **a real server is required for running
these tests.**
"""

import os
from dataclasses import dataclass
from typing import List
Expand All @@ -35,7 +36,7 @@ class ClientConfig:
biz_id: int


@pytest.fixture()
@pytest.fixture
def config() -> ClientConfig:
"""Read client configs from environment variables."""
_server_addrs = os.getenv("BSCP_SERVER_ADDRS")
Expand All @@ -48,7 +49,7 @@ def config() -> ClientConfig:
return ClientConfig(server_addrs=server_addrs, token=token, biz_id=biz_id)


@pytest.fixture()
@pytest.fixture
def existent_app_key() -> List[str]:
"""An real app and key that exists in the server."""
app_key = os.getenv("BSCP_EXISTENT_APP_KEY")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class Foo:

class Test__dict_to_dataclass:
@pytest.mark.parametrize(
("data",),
"data",
[
({"name": "foo", "value": 1},),
{"name": "foo", "value": 1},
# data has extra keys
({"name": "foo", "value": 1, "bar": "foobar"},),
{"name": "foo", "value": 1, "bar": "foobar"},
],
)
def test_normal_cases(self, data):
Expand Down
Loading

0 comments on commit 10784bf

Please sign in to comment.