diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index e687c0f..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,105 +0,0 @@ -test: &test - working_directory: ~/bencoder.pyx - steps: - - checkout - - run: - name: install dependencies - command: | - pip install -U pip setuptools wheel - pip install -r dev-requirements.txt - - run: - name: test - command: | - python setup.py test - - run: - name: upload coverage - command: | - pip install codecov - codecov --required -version: 2 -jobs: - # - # test - # - py27: - docker: - - image: python:2.7 - <<: *test - py35: - docker: - - image: python:3.5 - <<: *test - py36: - docker: - - image: python:3.6 - <<: *test - py37: - docker: - - image: python:3.7 - <<: *test - py38: - docker: - - image: python:3.8 - <<: *test - twine_check: - docker: - - image: python:3.8 - working_directory: ~/bencoder.pyx - steps: - - checkout - - run: - name: install dependencies - command: | - pip install -U pip setuptools wheel twine - pip install -r dev-requirements.txt - - run: - name: build wheel - command: | - python setup.py bdist_wheel - - run: - name: twine check - command: | - twine check dist/*.whl - pypy: - docker: - - image: pypy:2 - working_directory: ~/bencoder.pyx - steps: - - checkout - - run: - name: install dependencies - command: | - pip install -U pip setuptools wheel - pip install -r dev-requirements.txt - - run: - name: test - command: | - pypy setup.py test - pypy3: - docker: - - image: pypy:3 - working_directory: ~/bencoder.pyx - steps: - - checkout - - run: - name: install dependencies - command: | - pip install -U pip setuptools wheel - pip install -r dev-requirements.txt - - run: - name: test - command: | - pypy3 setup.py test - -workflows: - version: 2 - test_and_build: - jobs: - - py27 - - py35 - - py36 - - py37 - - py38 - - pypy - - pypy3 - - twine_check diff --git a/renovate.json b/.github/renovate.json similarity index 100% rename from renovate.json rename to .github/renovate.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5d01d5c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,41 @@ +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-10.15] + + steps: + - uses: actions/checkout@v2 + + - name: Set up QEMU + if: runner.os == 'Linux' + uses: docker/setup-qemu-action@v1 + with: + platforms: all + + - name: Build wheels + uses: pypa/cibuildwheel@v2.3.1 + env: + # configure cibuildwheel to build native archs ('auto'), and some + # emulated ones + CIBW_ARCHS_LINUX: auto aarch64 + - uses: actions/upload-artifact@v2 + with: + path: ./wheelhouse/*.whl + + make_sdist: + name: Make SDist + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build SDist + run: pipx run build --sdist + - uses: actions/upload-artifact@v2 + 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..941777a --- /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@v2 + with: + python-version: "3.8" + 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@v2.1.0 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/.travis.yml b/.travis.yml deleted file mode 100644 index ca07253..0000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -language: python -env: - global: - - CIBW_BEFORE_BUILD="pip install -r build-requirements.txt" - - CIBW_TEST_REQUIRES=pytest - - CIBW_TEST_COMMAND="pytest {project}/tests" - - secure: "R5OivfMMAw1BhdwbBjEjfxhkqtj+Ntqf+jh+05Mr3y1aV8tC9J1vsq213Q7J7teweJ7WteHSj8ymJk2DdJ5mOIFEPAWQeuUIzcaplmfmsxYNdUhj19Ok8E8XG+ppBHccDaS3eE6GM6tDB9PouOE0MGA8/j9DLHXDSPTrjO/+G+AQ7V9M2+XqiEHJrPhlzas1h37XKLa5EzMIMK3atoUS1CLg6JOa+Rgz9OfXs+wQyErdQ5BjNfzZH4BKFhHl1zBViPv+j3SHDkyFw92mbXx14qn8xiyY3ZtKisMKT/X5o8DUJbWN3OdFF65NQq5lcnTFjIx06LJmy+zLjnZ83qggRuRPxAV2D9ODRBjDY3bdBMVSeaP/0yKldZyd14UXU3Ahwymi9lHC+MRgzRx5VyovptgOq3RfZ97peRT0NRDuotcxG1oFcAOIutH7oQZiAWZV7LLSSc3JdNCbwjRDm0MqzoD4TcMa8vCJMEZWSzLLygJYiZC0OklTnOYko5wdYms8aJw1FPjXbc2UNo6bVXXnbdoxEfadxtWKskNKF6tSdl766CMh/jM3gMv2bZkY2mYSnNp1RL1sslE33BZPgzW5fyFnUBskwQZEOidWx+uQ1eiPsnvb5FBC8on59fTVKkHh6Xiffqltq8Yvy33P12qoV+S9GHMT4DOm9bQf/qob2fQ=" - -matrix: - include: - - sudo: required - services: - - docker - - os: osx - language: generic - -script: - - python -m pip install cibuildwheel==1.0.0 twine - - cibuildwheel --output-dir wheelhouse - -after_success: - - ls wheelhouse/ - - if [ $TRAVIS_TAG ]; then twine upload --username whtsky --password $PYPI_PASSWORD wheelhouse/bencoder*.whl; fi diff --git a/README.rst b/README.rst index 22ab144..33b1aac 100644 --- a/README.rst +++ b/README.rst @@ -3,9 +3,6 @@ Bencoder.pyx A fast bencode implementation in Cython supports both Python2 & Python3 . -.. image:: https://img.shields.io/circleci/build/github/whtsky/bencoder.pyx/master - :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/ @@ -44,6 +41,10 @@ Usage ChangeLog ---------- +Versoin 3.0.0 + ++ Drop support for Python 2 + Version 2.0.1 ~~~~~~~~~~~~~~~ diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100755 index 73894a7..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,40 +0,0 @@ -version: "{branch}-{build}" -cache: - - '%LOCALAPPDATA%\pip\Cache' -environment: - CIBW_BEFORE_BUILD: "pip install -r build-requirements.txt" - CIBW_TEST_REQUIRES: pytest - CIBW_TEST_COMMAND: "pytest {project}/tests" - PYPI_PASSWD: - secure: pp1j5lAB9NN8ZDasgY+oxoGrNw0+4gGzbNZmHVwJkCzUyrNBP5ZIuCrwjmx4q6ifg7RMiE3bVt9MljFCJh3XpsvVOAcx+AGKsHSjtXd40HM= - -init: - - ps: "ls C:/Python*" - -install: - - 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_script: - - python -m pip install -U pip setuptools - - python setup.py sdist - - pip install cibuildwheel==1.0.0 - - cibuildwheel --output-dir wheelhouse - -test_script: - - pip install codecov - - python setup.py test - - codecov --required - -deploy_script: - - ps: >- - if($env:appveyor_repo_tag -eq 'True') { - $env:Path += ";C:\Python37;C:\Python37\scripts" - pip install twine - twine upload --username whtsky --password $env:PYPI_PASSWD wheelhouse/bencoder*.whl - twine upload --username whtsky --password $env:PYPI_PASSWD dist/bencoder* - } - -artifacts: - - path: wheelhouse/bencoder*.whl - - path: dist/bencoder* diff --git a/bencoder.pyx b/bencoder.pyx index f22546a..9b7d02c 100644 --- a/bencoder.pyx +++ b/bencoder.pyx @@ -12,18 +12,13 @@ # Based on https://github.com/karamanolev/bencode3/blob/master/bencode.py -__version__ = '2.0.1' +__version__ = '3.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 +76,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 4ed2dc0..0000000 --- a/build-requirements.txt +++ /dev/null @@ -1 +0,0 @@ -cython==0.29.21 diff --git a/dev-requirements.txt b/dev-requirements.txt deleted file mode 100644 index dc906c0..0000000 --- a/dev-requirements.txt +++ /dev/null @@ -1 +0,0 @@ --r test-requirements.txt \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b948a37 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = ["cython==0.29.21", "setuptools>=58.0", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.cibuildwheel] +test-requires = "pytest" +test-command = "pytest {project}/tests" \ No newline at end of file diff --git a/setup.py b/setup.py index c356ffe..e3fc99d 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.1', + version='3.0.0', description='Yet another bencode implementation in Cython', long_description=open('README.rst', 'r').read(), author='whtsky', @@ -114,13 +75,12 @@ 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.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 :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Intended Audience :: Developers', diff --git a/test-requirements.txt b/test-requirements.txt index c923e18..f5b79c9 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,3 +1,3 @@ --r build-requirements.txt -pytest==4.6.2 -coverage==4.5.4 +Cython==0.29.21 +pytest==6.2.5 +pytest-cov==3.0.0