diff --git a/.github/workflows/autoformat.yaml b/.github/workflows/autoformat.yaml new file mode 100644 index 0000000..f5ae79e --- /dev/null +++ b/.github/workflows/autoformat.yaml @@ -0,0 +1,48 @@ +name: AutoFormat +on: [push, pull_request] + +jobs: + autotest: + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python version + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install poetry + uses: abatilo/actions-poetry@v2 + + - name: Setup a local virtual environment + run: | + poetry config virtualenvs.create true --local + poetry config virtualenvs.in-project true --local + + - uses: actions/cache@v3 + name: Define a cache for the virtual environment based on the dependencies lock file + with: + path: ./.venv + key: venv-${{ hashFiles('poetry.lock') }} + + - name: Install the project dependencies + run: poetry install + + - name: Auto format + run: bash autoformat.sh + + - name: Run flake8 + run: poetry run flake8 . + + - name: Run mypy + run: poetry run mypy . + + - uses: actions-go/push@master + with: + commit-message: 'style: 自动格式化代码' + remote: origin \ No newline at end of file diff --git a/autoformat.sh b/autoformat.sh index 0353c94..dd807ab 100644 --- a/autoformat.sh +++ b/autoformat.sh @@ -1 +1,3 @@ -autoflake -i --remove-unused-variables --remove-duplicate-keys --remove-all-unused-imports --ignore-init-module-imports --remove-rhs-for-unused-variables **/*.py \ No newline at end of file +poetry run autopep8 -i **/*.py +poetry run autoflake -i --remove-unused-variables --remove-duplicate-keys --remove-all-unused-imports --ignore-init-module-imports --remove-rhs-for-unused-variables **/*.py +poetry run isort . \ No newline at end of file diff --git a/main.py b/main.py index d1d6341..4d9eb80 100644 --- a/main.py +++ b/main.py @@ -11,6 +11,8 @@ dotenv.load_dotenv() + + def telemetering(): if TELEMETERING: requests.post('http://itte.api.xycode.club/', json={ diff --git a/poetry.lock b/poetry.lock index a30e9f6..b8d9390 100644 --- a/poetry.lock +++ b/poetry.lock @@ -822,6 +822,25 @@ type = "legacy" url = "https://pypi.tuna.tsinghua.edu.cn/simple" reference = "mirrors" +[[package]] +name = "isort" +version = "5.13.2" +description = "A Python utility / library to sort Python imports." +optional = false +python-versions = ">=3.8.0" +files = [ + {file = "isort-5.13.2-py3-none-any.whl", hash = "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6"}, + {file = "isort-5.13.2.tar.gz", hash = "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109"}, +] + +[package.extras] +colors = ["colorama (>=0.4.6)"] + +[package.source] +type = "legacy" +url = "https://pypi.tuna.tsinghua.edu.cn/simple" +reference = "mirrors" + [[package]] name = "jinja2" version = "3.1.3" @@ -2427,4 +2446,4 @@ reference = "mirrors" [metadata] lock-version = "2.0" python-versions = ">=3.10,<4.0" -content-hash = "05c65d3caef767f5ab113affd5171d4480b79c799c5183440d562f1b408509ec" +content-hash = "8d2e5210b1ea6116c2b1e8f4a7766e04e5b773277a0d9a272a55c6c6d961b461" diff --git a/pyproject.toml b/pyproject.toml index 4d5e103..fe43dcd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,6 +44,7 @@ types-psutil = "^5.9.5.20240423" types-requests = "^2.31.0.20240406" flake8 = "^7.0.0" autopep8 = "^2.1.0" +isort = "^5.13.2" [build-system] requires = ["poetry-core"]