diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 45e0801..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,200 +0,0 @@ -build-wheel: &build-wheel - working_directory: /work - steps: - - checkout - - run: - name: build wheel - command: bash /work/ci/build-wheels.sh - - run: - name: upload - command: | - if [ $CIRCLE_TAG ]; then source /work/ci/deploy.sh; fi - -test: &test - working_directory: ~/bencoder.pyx - steps: - - checkout - - run: - name: install dependencies - command: | - sudo pip install -r tox-requirements.txt - - restore_cache: - keys: - - tox-env-{{ checksum "test-requirements" }}-{{ checksum "build-requirements.txt" }} - - tox-env- - - run: - name: test - command: | - tox -e ${CIRCLE_JOB} - - save_cache: - key: tox-env-{{ checksum "test-requirements" }}-{{ checksum "build-requirements.txt" }} - paths: - - .tox -test_pypy: &test_pypy - working_directory: ~/bencoder.pyx - steps: - - checkout - - run: - name: install dependencies - command: | - pip install -r tox-requirements.txt - - run: - name: test - command: | - tox -e ${CIRCLE_JOB} - - -version: 2 -jobs: - # - # test - # - py27: - docker: - - image: circleci/python:2.7 - <<: *test - py34: - docker: - - image: circleci/python:3.4 - <<: *test - py35: - docker: - - image: circleci/python:3.5 - <<: *test - py36: - docker: - - image: circleci/python:3.6 - <<: *test - py37: - docker: - - image: circleci/python:3.7 - <<: *test - pypy: - docker: - - image: pypy:2 - <<: *test_pypy - pypy3: - docker: - - image: pypy:3 - <<: *test_pypy - - # - # build manylinux wheel - # - - # - # x64 - # - manylinux-x64_cp27-cp27m: - docker: - - image: quay.io/pypa/manylinux1_x86_64 - <<: *build-wheel - - manylinux-x64_cp27-cp27mu: - docker: - - image: quay.io/pypa/manylinux1_x86_64 - <<: *build-wheel - - manylinux-x64_cp34-cp34m: - docker: - - image: quay.io/pypa/manylinux1_x86_64 - <<: *build-wheel - - manylinux-x64_cp35-cp35m: - docker: - - image: quay.io/pypa/manylinux1_x86_64 - <<: *build-wheel - - manylinux-x64_cp36-cp36m: - docker: - - image: quay.io/pypa/manylinux1_x86_64 - <<: *build-wheel - - manylinux-x64_cp37-cp37m: - docker: - - image: quay.io/pypa/manylinux1_x86_64 - <<: *build-wheel - - # - # x86 - # - manylinux-x86_cp27-cp27m: - docker: - - image: quay.io/pypa/manylinux1_i686 - <<: *build-wheel - - manylinux-x86_cp27-cp27mu: - docker: - - image: quay.io/pypa/manylinux1_i686 - <<: *build-wheel - - manylinux-x86_cp34-cp34m: - docker: - - image: quay.io/pypa/manylinux1_i686 - <<: *build-wheel - - manylinux-x86_cp35-cp35m: - docker: - - image: quay.io/pypa/manylinux1_i686 - <<: *build-wheel - - manylinux-x86_cp36-cp36m: - docker: - - image: quay.io/pypa/manylinux1_i686 - <<: *build-wheel - - manylinux-x86_cp37-cp37m: - docker: - - image: quay.io/pypa/manylinux1_i686 - <<: *build-wheel - - -workflows: - version: 2 - test_and_build: - jobs: - - py27 - - py34 - - py35 - - py36 - - py37 - - pypy - - pypy3 - - - manylinux-x64_cp27-cp27m: - requires: - - py27 - - manylinux-x64_cp27-cp27mu: - requires: - - py27 - - manylinux-x64_cp34-cp34m: - requires: - - py34 - - manylinux-x64_cp35-cp35m: - requires: - - py35 - - manylinux-x64_cp36-cp36m: - requires: - - py36 - - manylinux-x64_cp37-cp37m: - requires: - - py37 - - - manylinux-x86_cp27-cp27m: - requires: - - py27 - - manylinux-x86_cp27-cp27mu: - requires: - - py27 - - manylinux-x86_cp34-cp34m: - requires: - - py34 - - manylinux-x86_cp35-cp35m: - requires: - - py35 - - manylinux-x86_cp36-cp36m: - requires: - - py36 - - manylinux-x86_cp37-cp37m: - requires: - - py37 diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 0000000..669addd --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,3 @@ +{ + "extends": ["@whtsky"] +} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f5fe6e3 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +name: Build + +on: [push, pull_request] + +jobs: + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-20.04, windows-2019, macos-11] + + steps: + - uses: actions/checkout@v4 + + - name: Set up QEMU + if: runner.os == 'Linux' + uses: docker/setup-qemu-action@v3 + with: + platforms: all + + - name: Build wheels + uses: pypa/cibuildwheel@v2.16.2 + env: + CIBW_ARCHS: all + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + + make_sdist: + name: Make SDist + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build SDist + run: pipx run build --sdist + - uses: actions/upload-artifact@v3 + with: + path: dist/*.tar.gz \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c7a9dbb --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +on: + push: + pull_request: +name: Test +jobs: + pytest: + name: pytest + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions/setup-python@v5 + with: + python-version: "3.10" + architecture: "x64" + - run: python -m pip install -U pip wheel setuptools + - run: python -m pip install -r test-requirements.txt + - run: python -m pip install . + env: + CFLAGS: "-DCYTHON_TRACE=1" + BENCODER_LINETRACE: 1 + - run: python -m pytest --cov=bencoder --cov-report=xml . + - uses: codecov/codecov-action@v3.1.4 diff --git a/.gitignore b/.gitignore index f983405..0bb041c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ __pycache__/ *.py[cod] *$py.class +.pytest_cache/ # C extensions *.so diff --git a/.sonarcloud.properties b/.sonarcloud.properties new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.sonarcloud.properties @@ -0,0 +1 @@ + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5fd62b5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -os: osx -language: generic -osx_image: xcode6.4 -env: - global: - - secure: "R5OivfMMAw1BhdwbBjEjfxhkqtj+Ntqf+jh+05Mr3y1aV8tC9J1vsq213Q7J7teweJ7WteHSj8ymJk2DdJ5mOIFEPAWQeuUIzcaplmfmsxYNdUhj19Ok8E8XG+ppBHccDaS3eE6GM6tDB9PouOE0MGA8/j9DLHXDSPTrjO/+G+AQ7V9M2+XqiEHJrPhlzas1h37XKLa5EzMIMK3atoUS1CLg6JOa+Rgz9OfXs+wQyErdQ5BjNfzZH4BKFhHl1zBViPv+j3SHDkyFw92mbXx14qn8xiyY3ZtKisMKT/X5o8DUJbWN3OdFF65NQq5lcnTFjIx06LJmy+zLjnZ83qggRuRPxAV2D9ODRBjDY3bdBMVSeaP/0yKldZyd14UXU3Ahwymi9lHC+MRgzRx5VyovptgOq3RfZ97peRT0NRDuotcxG1oFcAOIutH7oQZiAWZV7LLSSc3JdNCbwjRDm0MqzoD4TcMa8vCJMEZWSzLLygJYiZC0OklTnOYko5wdYms8aJw1FPjXbc2UNo6bVXXnbdoxEfadxtWKskNKF6tSdl766CMh/jM3gMv2bZkY2mYSnNp1RL1sslE33BZPgzW5fyFnUBskwQZEOidWx+uQ1eiPsnvb5FBC8on59fTVKkHh6Xiffqltq8Yvy33P12qoV+S9GHMT4DOm9bQf/qob2fQ=" - matrix: - - VERSION=2.7 - - VERSION=3.4 - - VERSION=3.5 - - VERSION=3.6 - - VERSION=3.7 - -install: - - if [ "$TRAVIS_OS_NAME" == "osx" ]; then source ci/travis_osx_install.sh; fi - -script: - - if [ "$TRAVIS_OS_NAME" == "osx" ]; then source ci/travis_osx_script.sh; fi - -after_success: - - ls wheelhouse/ - - if [ $TRAVIS_TAG ]; then source ci/deploy.sh; fi diff --git a/README.rst b/README.rst index 2413a3d..9917642 100644 --- a/README.rst +++ b/README.rst @@ -3,24 +3,12 @@ Bencoder.pyx A fast bencode implementation in Cython supports both Python2 & Python3 . -.. image:: https://img.shields.io/travis/whtsky/bencoder.pyx/master.svg?maxAge=3600&label=macOS - :alt: macOS Test Status - :target: https://travis-ci.org/whtsky/bencoder.pyx -.. image:: https://img.shields.io/appveyor/ci/whtsky/bencoder-pyx/master.svg?maxAge=3600&label=Windows - :alt: Windows Test Status - :target: https://ci.appveyor.com/project/whtsky/bencoder-pyx -.. image:: https://img.shields.io/circleci/ci/whtsky/bencoder-pyx/master.svg?maxAge=3600&label=Linux - :alt: Linux Test Status - :target: https://circleci.com/gh/whtsky/bencoder.pyx .. image:: https://img.shields.io/pypi/l/bencoder.pyx.svg :alt: PyPI License :target: https://pypi.org/project/bencoder.pyx/ .. image:: https://codecov.io/gh/whtsky/bencoder.pyx/branch/master/graph/badge.svg :alt: Codecov Coverage :target: https://codecov.io/gh/whtsky/bencoder.pyx -.. image:: https://pypistats.com/badge/bencoder-pyx.svg - :alt: bencoder-pyx PyPI Downloads - :target: https://pypistats.com/package/bencoder-pyx Install ------- @@ -53,6 +41,23 @@ Usage ChangeLog ---------- +Version 3.0.1 +~~~~~~~~~~~~~~~ ++ Add support for Python 3.11 + +Versoin 3.0.0 +~~~~~~~~~~~~~~~ + ++ Add support for Python 3.9 & 3.10 ++ Drop support for Python 2 ++ Build wheels for musl & aarch64 + +Version 2.0.1 +~~~~~~~~~~~~~~~ + ++ Add support for Python 3.8 ++ Drop support for Python 3.4 + Version 2.0.0 ~~~~~~~~~~~~~~~ diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100755 index f47a41b..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,51 +0,0 @@ -version: '{branch}-{build}' -cache: - - '%LOCALAPPDATA%\pip\Cache' -environment: - PYPI_PASSWD: - secure: pp1j5lAB9NN8ZDasgY+oxoGrNw0+4gGzbNZmHVwJkCzUyrNBP5ZIuCrwjmx4q6ifg7RMiE3bVt9MljFCJh3XpsvVOAcx+AGKsHSjtXd40HM= - - matrix: - - PYTHON: "C:\\Python27" - - PYTHON: "C:\\Python27-x64" - - PYTHON: "C:\\Python34" - - PYTHON: "C:\\Python34-x64" - - PYTHON: "C:\\Python35" - - PYTHON: "C:\\Python35-x64" - - PYTHON: "C:\\Python36" - - PYTHON: "C:\\Python36-x64" - - PYTHON: "C:\\Python37" - - PYTHON: "C:\\Python37-x64" - -init: - - ps: "ls C:/Python*" - -install: - - SET PATH=%PYTHON%;%PYTHON%\scripts;%PATH% - - echo "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 > "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\vcvars64.bat" - - pip install -r dev-requirements.txt - -build: off - -test_script: - - python -m pip install -U pip setuptools - - pip install codecov - - python setup.py test - - codecov --required - -after_test: - - del bencoder.c - - pip install wheel - - pip wheel . -w wheelhouse/ - - ps: "ls wheelhouse/*" - -deploy_script: - - ps: >- - if($env:appveyor_repo_tag -eq 'True') { - $env:Path += ";C:\Python35;C:\Python35\scripts" - pip install twine - twine upload --username whtsky --password $env:PYPI_PASSWD wheelhouse/bencoder*.whl - } - -artifacts: - - path: wheelhouse/bencoder*.whl diff --git a/bencoder.pyx b/bencoder.pyx index b193b1f..6bd214d 100644 --- a/bencoder.pyx +++ b/bencoder.pyx @@ -12,18 +12,11 @@ # Based on https://github.com/karamanolev/bencode3/blob/master/bencode.py -__version__ = '2.0.0' - from cpython.version cimport PY_MAJOR_VERSION, PY_MINOR_VERSION -IS_PY2 = PY_MAJOR_VERSION == 2 -if IS_PY2: - END_CHAR = 'e' - ARRAY_TYPECODE = b'b' -else: - END_CHAR = ord('e') - ARRAY_TYPECODE = 'b' +END_CHAR = ord('e') +ARRAY_TYPECODE = 'b' if PY_MAJOR_VERSION >= 3 and PY_MINOR_VERSION >=7: OrderedDict = dict @@ -81,10 +74,7 @@ for func, keys in [ (decode_string, [str(x) for x in range(10)]) ]: for key in keys: - if IS_PY2: - decode_func[key] = func - else: - decode_func[ord(key)] = func + decode_func[ord(key)] = func def bdecode2(bytes x): diff --git a/build-requirements.txt b/build-requirements.txt deleted file mode 100644 index 64c06c6..0000000 --- a/build-requirements.txt +++ /dev/null @@ -1 +0,0 @@ -cython==0.28.5 diff --git a/ci/build-wheels.sh b/ci/build-wheels.sh deleted file mode 100755 index 41c684a..0000000 --- a/ci/build-wheels.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -set -e -x - -cd /work - -MANYLINUX_PYTHON=$(echo ${CIRCLE_JOB} | cut -d"_" -f2) -ARCHITECTURE=$(echo ${CIRCLE_JOB} | cut -d"_" -f1 | cut -d"-" -f2) -PYBIN=/opt/python/${MANYLINUX_PYTHON}/bin -echo "MANYLINUX_PYTHON [${MANYLINUX_PYTHON}] ${ARCHITECTURE}" -if [ "$ARCHITECTURE" == "x86" ] -then - echo "x86 architect, use linux32" - PRE_CMD=linux32 -fi -${PRE_CMD} ${PYBIN}/pip install -r /work/dev-requirements.txt -${PRE_CMD} ${PYBIN}/pip wheel /work/ -w /tmp/wheelhouse/ - -for whl in /tmp/wheelhouse/bencoder*.whl; do - auditwheel repair $whl -w /work/wheelhouse/ -done - -# Install packages and test again -${PRE_CMD} ${PYBIN}/pip install bencoder.pyx --no-index -f /work/wheelhouse -(cd /work; ${PRE_CMD} ${PYBIN}/py.test) \ No newline at end of file diff --git a/ci/deploy.sh b/ci/deploy.sh deleted file mode 100755 index 52362fd..0000000 --- a/ci/deploy.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -pip install twine -twine upload --username whtsky --password $PYPI_PASSWORD wheelhouse/bencoder*.whl \ No newline at end of file diff --git a/ci/travis_osx_install.sh b/ci/travis_osx_install.sh deleted file mode 100644 index 0898d54..0000000 --- a/ci/travis_osx_install.sh +++ /dev/null @@ -1,5 +0,0 @@ -git clone https://github.com/matthew-brett/multibuild.git -source multibuild/osx_utils.sh -get_macpython_environment $VERSION venv -pip install --upgrade pip wheel -pip install -r test-requirements.txt \ No newline at end of file diff --git a/ci/travis_osx_script.sh b/ci/travis_osx_script.sh deleted file mode 100644 index 0ac430a..0000000 --- a/ci/travis_osx_script.sh +++ /dev/null @@ -1,4 +0,0 @@ -python setup.py test -bash <(curl -s https://codecov.io/bash) -rm bencoder.c -pip wheel . -w wheelhouse/ \ No newline at end of file diff --git a/dev-requirements.txt b/dev-requirements.txt deleted file mode 100644 index fdb9b6a..0000000 --- a/dev-requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ --r test-requirements.txt --r tox-requirements.txt \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f890cb0 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = ["cython>=0.29.32", "setuptools>=58.0", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.cibuildwheel] +test-requires = "pytest" +test-command = "pytest {project}/tests" diff --git a/release.sh b/release.sh deleted file mode 100755 index b13ac2e..0000000 --- a/release.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -rm -rf wheelhouse/ -rm -rf dist/ -cython bencoder.pyx -python setup.py sdist --formats=zip,gztar -tox -c tox-wheels.ini -twine upload dist/* -twine upload wheelhouse/* \ No newline at end of file diff --git a/renovate.json b/renovate.json deleted file mode 100644 index f45d8f1..0000000 --- a/renovate.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": [ - "config:base" - ] -} diff --git a/setup.py b/setup.py index 23ed072..32744ca 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ import os.path import sys -import platform +import os from setuptools import setup from setuptools.extension import Extension @@ -9,39 +9,23 @@ pyx_path = 'bencoder.pyx' c_path = 'bencoder.c' -try: - import Cython - HAVE_CYTHON = True -except ImportError: - HAVE_CYTHON = False - -if HAVE_CYTHON: - if os.path.exists(c_path): - # Remove C file to force Cython recompile. - os.remove(c_path) - if 'test' in sys.argv and platform.python_implementation() == 'CPython': - from Cython.Build import cythonize - ext_modules = cythonize(Extension( - "bencoder", - [pyx_path], - define_macros=[('CYTHON_TRACE', '1')] - ), compiler_directives={ - 'linetrace': True, - 'binding': True - }) - else: - from Cython.Build import cythonize - ext_modules = cythonize(Extension( - "bencoder", - [pyx_path], - extra_compile_args=['-O3'] - )) -else: - ext_modules = [Extension( - 'bencoder', - [c_path], - extra_compile_args=['-O3'] - )] +if os.path.exists(c_path): + # Remove C file to force Cython recompile. + os.remove(c_path) + +if os.environ.get("BENCODER_LINETRACE", "") == "1": + from Cython.Compiler.Options import get_directive_defaults + directive_defaults = get_directive_defaults() + + directive_defaults['linetrace'] = True + directive_defaults['binding'] = True + +from Cython.Build import cythonize +ext_modules = cythonize(Extension( + "bencoder", + [pyx_path], + extra_compile_args=['-O3'] +)) class PyTest(TestCommand): @@ -68,33 +52,10 @@ def run_tests(self): cmdclass = {'test': PyTest} -# patch bdist_wheel -try: - from wheel.bdist_wheel import bdist_wheel - - REPLACE = '.'.join([ - 'macosx_10_6_intel', - 'macosx_10_9_intel', - 'macosx_10_9_x86_64', - 'macosx_10_10_intel', - 'macosx_10_10_x86_64', - ]) - - class _bdist_wheel(bdist_wheel): - def get_tag(self): - tag = bdist_wheel.get_tag(self) - if tag[2] == 'macosx_10_6_intel': - tag = (tag[0], tag[1], REPLACE) - return tag - - cmdclass['bdist_wheel'] = _bdist_wheel -except ImportError: - pass - setup( name='bencoder.pyx', - version='2.0.0', + version='3.0.1', description='Yet another bencode implementation in Cython', long_description=open('README.rst', 'r').read(), author='whtsky', @@ -114,13 +75,13 @@ def get_tag(self): 'Operating System :: OS Independent', 'Programming Language :: Cython', 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Intended Audience :: Developers', diff --git a/test-requirements.txt b/test-requirements.txt index 1ff817a..0db84cc 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,3 +1,3 @@ --r build-requirements.txt -pytest==3.7.3 -coverage==4.5.2 +Cython==0.29.32 +pytest==7.2.0 +pytest-cov==4.0.0 diff --git a/tox-requirements.txt b/tox-requirements.txt deleted file mode 100644 index 0c5e6bc..0000000 --- a/tox-requirements.txt +++ /dev/null @@ -1 +0,0 @@ -tox==3.2.0 diff --git a/tox-wheels.ini b/tox-wheels.ini deleted file mode 100644 index e6c6eaa..0000000 --- a/tox-wheels.ini +++ /dev/null @@ -1,8 +0,0 @@ -[tox] -envlist = py27, py34, py35, py36, py37 - -[testenv] -commands = pip wheel {toxinidir} -w {toxinidir}/wheelhouse/ -skip_install = True -deps = - -rbuild-requirements.txt diff --git a/tox.ini b/tox.ini deleted file mode 100644 index f1c84bb..0000000 --- a/tox.ini +++ /dev/null @@ -1,23 +0,0 @@ -[tox] -envlist = py27, py34, py35, py36, py37, pypy, pypy3 - -[testenv] -commands = - python setup.py test - codecov -e TOXENV -skip_install = True -passenv = - CI - BRANCH_NAME - REVISION - CODECOV_TOKEN - TOXENV - SEMAPHORE - SEMAPHORE_* - TRAVIS - CIRCLECI - CIRCLE_* - -deps = - -rtest-requirements.txt - codecov>=1.4.0