diff --git a/.github/workflows/Pages.yml b/.github/workflows/Pages.yml index dd66784e..cc482129 100644 --- a/.github/workflows/Pages.yml +++ b/.github/workflows/Pages.yml @@ -20,26 +20,18 @@ jobs: build: runs-on: ubuntu-latest - env: - PYTHON_VER: "3.11" - steps: - name: Checkout uses: actions/checkout@v3 - - name: Setup Python ${{ env.PYTHON_VER }} - uses: actions/setup-python@v4 - with: - python-version: ${{ env.PYTHON_VER }} - - name: Install dependencies run: | - pip install -U pip -qq - pip install mkdocs-material mkdocstrings[python] -qq + pipx install pdm + pdm install -G doc --no-default --no-self - name: Build run: | - mkdocs build -d site -s + pdm run mkdocs build -d site -s - name: Upload Artifact uses: actions/upload-pages-artifact@v2 diff --git a/.github/workflows/Publish.yml b/.github/workflows/Publish.yml index 88f9afce..4d3b79d9 100644 --- a/.github/workflows/Publish.yml +++ b/.github/workflows/Publish.yml @@ -17,56 +17,53 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.x" - - - name: Install cibuildwheel - run: pip install cibuildwheel -qq - - name: Build wheels - run: python -m cibuildwheel --output-dir wheelhouse + uses: pypa/cibuildwheel@v2.15.0 env: - CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-* pp38-* pp39-*" + CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-* pp38-* pp39-* pp310-*" CIBW_SKIP: "*-win32 *_i686 *_s390x *_ppc64le" - uses: actions/upload-artifact@v3 with: - name: dist path: ./wheelhouse/*.whl + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Build sdist + run: pipx run build --sdist + + - uses: actions/upload-artifact@v3 + with: + path: dist/*.tar.gz + publish: name: Publish - needs: build_wheels + needs: [build_wheels, build_sdist] runs-on: ubuntu-latest environment: - name: publish + name: pypi - env: - PYTHON_VER: "3.11" + permissions: + id-token: write steps: - - name: Set up Python ${{ env.PYTHON_VER }} - uses: actions/setup-python@v4 - with: - python-version: ${{ env.PYTHON_VER }} - - - name: Install dependencies - run: | - python -m pip install -U pip -qq - pip install -U twine -qq - - name: Download distributions uses: actions/download-artifact@v3 with: - name: dist + name: artifact path: dist - name: Publish to PyPI if: ${{ github.event_name == 'push' }} - run: twine upload dist/* -u __token__ -p ${{ secrets.PYPI_TOKEN }} --disable-progress-bar + uses: pypa/gh-action-pypi-publish@release/v1 - name: Publish to TestPyPI if: ${{ github.event_name == 'workflow_dispatch' }} - run: twine upload -r testpypi dist/* -u __token__ -p ${{ secrets.TESTPYPI_TOKEN }} --disable-progress-bar + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ diff --git a/.gitignore b/.gitignore index 17aaed5e..4730e97f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ !docs/** !tests !tests/** +!scripts +!scripts/** *.py[cd] __pycache__ diff --git a/README.md b/README.md index 86ee1647..b22db3a0 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,10 @@ PyPI - Python Version + + + pdm-managed +

diff --git a/aiotieba/__version__.py b/aiotieba/__version__.py index 975f6914..3bdbbae2 100644 --- a/aiotieba/__version__.py +++ b/aiotieba/__version__.py @@ -1 +1 @@ -__version__ = "3.7.1" +__version__ = "3.7.2" diff --git a/aiotieba/api/get_bawu_postlogs/_classdef.py b/aiotieba/api/get_bawu_postlogs/_classdef.py index 81bf8125..d03093a6 100644 --- a/aiotieba/api/get_bawu_postlogs/_classdef.py +++ b/aiotieba/api/get_bawu_postlogs/_classdef.py @@ -119,7 +119,7 @@ def __init__(self, data_tag: bs4.element.Tag) -> None: text_item = post_content_item.div self._text = text_item.string[12:] - self._medias = [Media_postlog(tag) for tag in text_item.next_sibling('a')] + self._medias = [Media_postlog(tag) for tag in text_item.next_sibling('a', class_=None)] op_type_item = left_cell_item.next_sibling self._op_type = op_type_item.string diff --git a/aiotieba/api/get_forum_detail/_classdef.py b/aiotieba/api/get_forum_detail/_classdef.py index 8e07a186..b3e89cd7 100644 --- a/aiotieba/api/get_forum_detail/_classdef.py +++ b/aiotieba/api/get_forum_detail/_classdef.py @@ -41,7 +41,7 @@ def __init__(self, data_proto: Optional[TypeMessage] = None) -> None: self._slogan = forum_proto.slogan self._member_num = forum_proto.member_count self._post_num = forum_proto.thread_count - self._has_bawu = bool(data_proto.election_tab.new_manager_status) + self._has_bawu = data_proto.election_tab.new_manager_status == 5 else: self._fid = 0 self._fname = '' diff --git a/aiotieba/const.py b/aiotieba/const.py index 18328a66..9b8ad1d7 100644 --- a/aiotieba/const.py +++ b/aiotieba/const.py @@ -1,4 +1,4 @@ -MAIN_VERSION = "12.45.7.0" +MAIN_VERSION = "12.46.3.0" POST_VERSION = "12.35.1.0" APP_SECURE_SCHEME = "https" diff --git a/aiotieba/helper/crypto/include/tbcrypto/_python.h b/aiotieba/helper/crypto/include/tbcrypto/pywrap.h similarity index 90% rename from aiotieba/helper/crypto/include/tbcrypto/_python.h rename to aiotieba/helper/crypto/include/tbcrypto/pywrap.h index 1640135a..7518799c 100644 --- a/aiotieba/helper/crypto/include/tbcrypto/_python.h +++ b/aiotieba/helper/crypto/include/tbcrypto/pywrap.h @@ -2,7 +2,9 @@ #define PY_SSIZE_T_CLEAN // use Py_ssize_t instead of int -#ifdef TBC_FORCE_PYTHON_NODEBUG +#ifdef TBC_PYTHON_DEBUG +#include +#else #ifdef _DEBUG #undef _DEBUG // use these steps to avoid linking with python_d.lib #define __TBC_RESTORE_DEBUG @@ -12,6 +14,4 @@ #define _DEBUG #undef __TBC_RESTORE_DEBUG #endif -#else -#include #endif diff --git a/aiotieba/helper/crypto/include/tbcrypto/zid.h b/aiotieba/helper/crypto/include/tbcrypto/rc442.h similarity index 100% rename from aiotieba/helper/crypto/include/tbcrypto/zid.h rename to aiotieba/helper/crypto/include/tbcrypto/rc442.h diff --git a/aiotieba/helper/crypto/include/tbcrypto/sign.h b/aiotieba/helper/crypto/include/tbcrypto/sign.h index 75690485..9688e6c1 100644 --- a/aiotieba/helper/crypto/include/tbcrypto/sign.h +++ b/aiotieba/helper/crypto/include/tbcrypto/sign.h @@ -1,5 +1,5 @@ #pragma once -#include "tbcrypto/_python.h" +#include "tbcrypto/pywrap.h" PyObject* sign(PyObject* Py_UNUSED(self), PyObject* args); diff --git a/aiotieba/helper/crypto/src/tbcrypto/lib.c b/aiotieba/helper/crypto/src/tbcrypto/lib.c index 8e4f0399..81b37341 100644 --- a/aiotieba/helper/crypto/src/tbcrypto/lib.c +++ b/aiotieba/helper/crypto/src/tbcrypto/lib.c @@ -1,10 +1,10 @@ -#include "tbcrypto/_python.h" +#include "tbcrypto/pywrap.h" #include "tbcrypto/const.h" #include "tbcrypto/cuid.h" #include "tbcrypto/error.h" +#include "tbcrypto/rc442.h" #include "tbcrypto/sign.h" -#include "tbcrypto/zid.h" PyObject* cuid_galaxy2(PyObject* Py_UNUSED(self), PyObject* args) { diff --git a/aiotieba/helper/crypto/src/tbcrypto/zid.c b/aiotieba/helper/crypto/src/tbcrypto/rc442.c similarity index 98% rename from aiotieba/helper/crypto/src/tbcrypto/zid.c rename to aiotieba/helper/crypto/src/tbcrypto/rc442.c index 42a5db2c..cd515d01 100644 --- a/aiotieba/helper/crypto/src/tbcrypto/zid.c +++ b/aiotieba/helper/crypto/src/tbcrypto/rc442.c @@ -3,7 +3,7 @@ #include "tbcrypto/const.h" #include "tbcrypto/error.h" -#include "tbcrypto/zid.h" +#include "tbcrypto/rc442.h" typedef struct rc4_42_context { int x; diff --git a/docs/index.md b/docs/index.md index 1f1d3fcb..f07bd572 100644 --- a/docs/index.md +++ b/docs/index.md @@ -18,6 +18,10 @@ PyPI - Python Version + + + pdm-managed +

--- diff --git a/pyproject.toml b/pyproject.toml index c77f743d..64821b95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,10 +69,15 @@ version = { attr = "aiotieba.__version__.__version__" } [tool.setuptools.package-data] "*" = ["*.pyi"] +[tool.pdm.dev-dependencies] +lint = ["ruff", "black"] +test = ["aiotieba[speedup]", "pytest", "pytest-asyncio", "pytest-rerunfailures"] +doc = ["mkdocs-material", "mkdocstrings[python]"] + [tool.black] line-length = 120 skip-string-normalization = true -target-version = ["py38"] +target-version = ["py38", "py39", "py310", "py311"] [tool.ruff] line-length = 120 @@ -86,7 +91,6 @@ target-version = "py38" "*_pb2.py" = ["F401"] [tool.pytest.ini_options] -minversion = "6.0" addopts = "-q" testpaths = ["tests"] required_plugins = "pytest-asyncio pytest-rerunfailures" diff --git a/scripts/proto_compile.py b/scripts/proto_compile.py new file mode 100644 index 00000000..c00b4040 --- /dev/null +++ b/scripts/proto_compile.py @@ -0,0 +1,48 @@ +import subprocess +from pathlib import Path + +commom_proto_pth = Path("aiotieba/api/_protobuf") + +for fpth in commom_proto_pth.glob('*_pb2.py'): + fpth.unlink() + +subprocess.run("protoc --python_out=. *.proto", cwd=str(commom_proto_pth), check=True, timeout=60.0) + +for fpth in commom_proto_pth.glob('*_pb2.py'): + bak_fpth = fpth.with_suffix('.bak') + with ( + fpth.open('r') as f, + bak_fpth.open('w') as bak_f, + ): + for row in f.readlines(): + if row.startswith('#'): + continue + if row.startswith('import'): + row = "from . " + row + bak_f.write(row) + fpth.unlink() + bak_fpth.rename(fpth) + +for mod_pth in Path("aiotieba/api").glob('*/protobuf'): + for fpth in mod_pth.glob('*_pb2.py'): + fpth.unlink() + + subprocess.run("protoc -I../../_protobuf -I. --python_out=. *.proto", cwd=str(mod_pth), check=True, timeout=10.0) + + for fpth in mod_pth.glob('*_pb2.py'): + bak_fpth = fpth.with_suffix('.bak') + with ( + fpth.open('r') as f, + bak_fpth.open('w') as bak_f, + ): + for row in f.readlines(): + if row.startswith('#'): + continue + if row.startswith('import'): + row = "from ..._protobuf " + row + bak_f.write(row) + fpth.unlink() + bak_fpth.rename(fpth) + +subprocess.run("ruff . --fix", cwd='.', check=False, timeout=10.0) +subprocess.run("black .", cwd='.', check=False, timeout=30.0)