From bed8225a289cf3089fa83d1fcdd4dbccac9a3993 Mon Sep 17 00:00:00 2001 From: ovizro Date: Wed, 15 Nov 2023 12:41:35 +0000 Subject: [PATCH] Update workflows --- .github/workflows/build_test.yml | 42 +++++++ .github/workflows/lint.yml | 21 ++++ .github/workflows/python-publish.yml | 161 ++++++++++++++++++++------- README.md | 8 +- README_cn.md | 95 ++++++++++++++++ docs/cn/README.md | 41 ------- setup.py | 4 +- 7 files changed, 288 insertions(+), 84 deletions(-) create mode 100644 .github/workflows/build_test.yml create mode 100644 .github/workflows/lint.yml create mode 100644 README_cn.md delete mode 100644 docs/cn/README.md diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml new file mode 100644 index 0000000..09896a5 --- /dev/null +++ b/.github/workflows/build_test.yml @@ -0,0 +1,42 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: build + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + strategy: + matrix: + python-version: [3.8, 3.9, "3.10", "3.11"] + os: [windows-latest, ubuntu-20.04, macos-latest] + # exclude: + # # package dependencies error on macos 3.9+ for unkwown reason + # - os: macos-latest + # python-version: 3.9 + # - os: macos-latest + # python-version: "3.10" + runs-on: ${{ matrix.os }} + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Upgrade pip + run: | + python -m pip install --upgrade pip + pip install setuptools wheel + - name: Install typing-extensions + if: ${{ matrix.python-version == 3.6 }} + run: | + pip install typing-extensions==4.1.1 + - name: Build dist and test with unittest + run: | + make build install test build_dist diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..bde15ca --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,21 @@ +name: lint + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + flake8-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install flake8 + run: pip install flake8 + - name: Run flake8 + run: make lint diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index fca78d7..f52ae0b 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -1,39 +1,122 @@ -# This workflow will upload a Python Package using Twine when a release is created -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Upload Python Package - -on: - release: - types: [published] - -permissions: - contents: read - -jobs: - deploy: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v3 - with: - python-version: '3.8' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build - - name: Build package - run: python -m build - - name: Publish package - uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Upload Python Package + +on: + create: + workflow_dispatch: + +permissions: + contents: read + +jobs: + deploy-wheels: + name: Deploy wheels on ${{ matrix.os }} for ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + python-version: [36, 37, 38, 39, 310] + manylinux-image: [manylinux2010, manylinux2014, manylinux_2_24] + arch: [auto] + include: + - os: ubuntu-latest + manylinux-image: manylinux2014 + arch: aarch64 + python-version: 36 + - os: ubuntu-latest + manylinux-image: manylinux2014 + arch: aarch64 + python-version: 37 + - os: ubuntu-latest + manylinux-image: manylinux2014 + arch: aarch64 + python-version: 38 + - os: ubuntu-latest + manylinux-image: manylinux2014 + arch: aarch64 + python-version: 39 + - os: ubuntu-latest + manylinux-image: manylinux2014 + arch: aarch64 + python-version: 310 + exclude: + # manyliunx image is not a valid variation on MacOS and Windows + - os: macos-latest + manylinux-image: manylinux2010 + - os: windows-latest + manylinux-image: manylinux2010 + - os: macos-latest + manylinux-image: manylinux2014 + - os: windows-latest + manylinux-image: manylinux2014 + + steps: + - uses: actions/checkout@v2 + - name: Set up QEMU + if: ${{ matrix.arch == 'aarch64' }} + uses: docker/setup-qemu-action@v1 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install twine setuptools wheel + - name: Install cibuildwheel + run: python -m pip install cibuildwheel -U + + - name: Build wheels + run: python -m cibuildwheel --output-dir wheelhouse + env: + CIBW_BUILD: 'cp${{ matrix.python-version }}-*' + CIBW_SKIP: '*musllinux*' + CIBW_ARCHS: ${{matrix.arch}} + CIBW_MANYLINUX_*_IMAGE: ${{ matrix.manylinux-image }} + CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux-image }} + + - name: Publish wheels to PyPI Unix + if: matrix.os != 'windows-latest' + continue-on-error: true + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: | + twine upload wheelhouse/*.whl + - name: Publish wheels to PyPI Windows + if: matrix.os == 'windows-latest' + continue-on-error: true + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: | + twine upload (Get-ChildItem wheelhouse/*.whl) + deploy-tar: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install twine setuptools wheel + - name: Build source tar + run: | + python setup.py sdist + - name: Publish wheels to PyPI + continue-on-error: true + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: | + twine upload dist/*tar* diff --git a/README.md b/README.md index 9ccf895..01ba9a4 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,14 @@ From pip: From source code: - python setup.py install + git clone https://github.com/Ovizro/Karuha.git + cd Karuha + make install ## Quick Start +> Before starting, you need to make sure you have the Tinode service running locally with its gRPC port set to the default value of 16060. If your service is not local or the default port has been changed, you need to add additional server configuration items in the following code. + Create a new file `config.json` and write the following content: ```json @@ -60,7 +64,7 @@ Well, you can actually go a step further and send messages to users. Currently, if you want to reply to a message, you currently need to add a handler for the event yourself. This is not a simple process. Fortunately, we are about to introduce a command module to improve this. -Because this is a relatively low-level function, I will only give an example to show how karuha is currently used in python: +Because this is a relatively low-level API, I will only give an example to show how karuha is currently used in python: ```python import karuha diff --git a/README_cn.md b/README_cn.md new file mode 100644 index 0000000..2cfe99a --- /dev/null +++ b/README_cn.md @@ -0,0 +1,95 @@ +# Karuha + +[![License](https://img.shields.io/github/license/Ovizro/Karuha.svg)](/LICENSE) +[![PyPI](https://img.shields.io/pypi/v/KaruhaBot.svg)](https://pypi.python.org/pypi/KaruhaBot) +![Python Version](https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10%20|%203.11-blue.svg) + +一个简单的Tinode聊天机器人框架 + +> 目前项目仍处于开发期,部分次要接口可能会频繁变化,造成的不便敬请谅解 + +库的名称`Karuha`来自游戏星空列车与白的旅行中的角色 狩叶·朗姆柯妮(カルハ・ラムコネ) + +
+ +![Karuha](/docs/img/tw_icon-karuha2.png) + +
+ +> カルハ・ラムコネと申します。カルハちゃんって呼んでいいわよ + +# 安装 + +从Pypi安装: + + pip install KaruhaBot + +或从源码安装: + + git clone https://github.com/Ovizro/Karuha.git + cd Karuha + make install + +# 快速开始 + +在开始前,你需要确保在本地有运行的Tinode服务,其gRPC端口为默认值16060。如果你的服务不在本地,在接下来的代码中,你需要额外添加服务器的配置项。 + +创建一个新的文件`config.json`并写入以下内容作为配置文件: + +```json +{ + "server": { + "host": "localhost:16060", + "listen": "0.0.0.0:40051" + }, + "bots": [ + { + "name": "chatbot", + "schema": "basic", + "secret": "{chatbot_login_name}:{chatebot_login_passwd}" + } + ] +} +``` + +> 将 `{chatbot_login_name}` 和 `{chatebot_login_passwd}` 替换为聊天机器人在 Tinode 服务器中的登录帐户名和密码。 + +使用以下的命令启动聊天机器人: + + python -m Karuha ./config.json + +现在您可以在命令行上查看其他人发送到聊天机器人的消息。是的,这就是我们目前能做到的大部分内容。 + +## 更进一步? + +好吧,其实我们的确可以再进一步,让我们试着回复一些消息吧。 + +至于为什么我并不在上面一段提及这个,因为就目前来说,回复消息的确不是几件简单的事情。这需要我们手动对事件进行绑定。但不要担心,我们很快就会有一套命令模块来简化这一流程。 + +由于这涉及到低层级API,故此处仅提供一个例子,以展示其目前在Python中的使用方法: + +```python +import karuha +from karuha import Bot, DataEvent + + +bot = Bot( + "basic", + "chatbot:123456" +) + + +@karuha.on(DataEvent) +async def reply(event: DataEvent) -> None: + if event.server_message.content.decode() == "\"Hello chatbot!\"": # message.content is a json string + await event.bot.publish( + event.server_message.topic, + "Hello world!" + ) + + +if __name__ = "__main__": + karuha.load_config() + karuha.add_bot(bot) + karuha.run() +``` diff --git a/docs/cn/README.md b/docs/cn/README.md deleted file mode 100644 index de7aa52..0000000 --- a/docs/cn/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# Karuha - -[![License](https://img.shields.io/github/license/Ovizro/Karuha.svg)](/LICENSE) -[![PyPI](https://img.shields.io/pypi/v/KaruhaBot.svg)](https://pypi.python.org/pypi/KaruhaBot) -![Python Version](https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10%20|%203.11-blue.svg) - -一个简单的Tinode聊天机器人框架 - -> 目前项目仍处于开发期,部分次要接口可能会频繁变化,造成的不便敬请谅解 - -库的名称`Karuha`来自游戏星空列车与白的旅行中的角色 狩叶·朗姆柯妮(カルハ・ラムコネ) - -
- -![Karuha](/docs/img/tw_icon-karuha2.png) - -
- -> カルハ・ラムコネと申します。カルハちゃんって呼んでいいわよ - -# 安装 - -从Pypi安装: - - pip install KaruhaBot - -或从源码安装: - - git clone https://github.com/Ovizro/Karuha.git - cd Karuha - make install - -# 快速开始 - -在开始前,你需要确保: - -1. 已经安装了Karuha框架即其所需要的包 -2. 在本地有运行的Tinode服务,其gRPC端口为默认值16060。如果你的服务不在本地,在接下来的代码中,你需要额外添加服务器的配置项 -3. 最好具有一定的Python异步编程基础 - -Karuha框架基于异步的事件处理机制 diff --git a/setup.py b/setup.py index 00e00f8..fd35729 100644 --- a/setup.py +++ b/setup.py @@ -43,9 +43,9 @@ long_description_content_type='text/markdown', author="Ovizro", - author_email="Ovizro@visecy.top", + author_email="Ovizro@visecy.org", maintainer="Ovizro", - maintainer_email="Ovizro@visecy.top", + maintainer_email="Ovizro@visecy.org", license="Apache 2.0", url="https://github.com/Ovizro/Karuha",