diff --git a/.github/workflows/sdist.yml b/.github/workflows/sdist.yml deleted file mode 100644 index 8523d92..0000000 --- a/.github/workflows/sdist.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Source Distribution - -on: [push] - -jobs: - build: - runs-on: ubuntu-latest - - name: Python 3.9 - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: 3.9 - architecture: x64 - - - name: Install test dependencies - run: pip install wheel flake8 pytest twine - - - name: Flake8 - # stop the build if there are Python syntax errors or undefined names - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - run: | - flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - - name: Install libsnappy-dev - run: sudo apt-get install libsnappy-dev - - - name: Generate source distribution - run: python setup.py sdist - - - name: Clean up sources - # this cleans up the sources to make sure `import snappy` uses the sdist - # an alternative would be to run pytest in a different working directory - run: rm -rf setup.py ./snappy - - - name: Install python-snappy sdist - run: pip install dist/python-snappy*.tar.gz - - - name: Pytest - run: pytest --verbose test_snappy.py - - - name: Archive sdist - if: startsWith(github.ref, 'refs/tags/0.') - uses: actions/upload-artifact@v2 - with: - name: python-snappy-sdist - path: dist/python-snappy*.tar.gz - - - name: Publish sdist to PyPI - if: startsWith(github.ref, 'refs/tags/0.') - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - twine upload dist/python-snappy*.tar.gz diff --git a/.github/workflows/wheel.yml b/.github/workflows/wheel.yml index a23d8c3..b22f6b1 100644 --- a/.github/workflows/wheel.yml +++ b/.github/workflows/wheel.yml @@ -1,34 +1,12 @@ -name: Wheel +name: PyPi wheel and sdist -on: [push] +on: [push, pull_request] jobs: - build: + sdist: runs-on: ubuntu-latest - strategy: - matrix: - include: - - python-version: 2.7 - pep-425-tag: cp27-cp27mu - # we build for "wide-unicode" CPython 2.7, which is prevalent among - # most Linux distributions. See https://github.com/pypa/manylinux - - - python-version: 3.5 - pep-425-tag: cp35-cp35m - - - python-version: 3.6 - pep-425-tag: cp36-cp36m - - - python-version: 3.7 - pep-425-tag: cp37-cp37m - - - python-version: 3.8 - pep-425-tag: cp38-cp38 - - - python-version: 3.9 - pep-425-tag: cp39-cp39 - name: Python ${{ matrix.python-version }} + name: Python 3.9 steps: - uses: actions/checkout@v2 @@ -36,44 +14,122 @@ jobs: - name: Setup Python uses: actions/setup-python@v2 with: - python-version: ${{ matrix.python-version }} + python-version: 3.9 architecture: x64 - name: Install test dependencies - run: pip install pytest twine + run: pip install wheel flake8 pytest - # Flake8 is already run in Source Distribution (sdist) workflow, so we don't run it here. + - name: Flake8 + # stop the build if there are Python syntax errors or undefined names + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + run: | + flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Build python-snappy manylinux wheels - uses: RalfG/python-wheels-manylinux-build@v0.3.3-manylinux2010_x86_64 - with: - python-versions: ${{ matrix.pep-425-tag }} - system-packages: "snappy-devel" + - name: Install libsnappy-dev + run: sudo apt-get install libsnappy-dev - - name: Install python-snappy wheel - # manylinux1 offers broader compatibility than manylinux2010 or manylinux2014 - run: | - pip install dist/python_snappy*-manylinux1*.whl + - name: Generate source distribution + run: python setup.py sdist - - name: Clean up sources - # this cleans up the sources to make sure `import snappy` uses the wheel - # an alternative would be to run pytest in a different working directory - run: rm -rf setup.py ./snappy + - name: Install python-snappy sdist + run: pip install dist/python-snappy*.tar.gz - name: Pytest run: pytest --verbose test_snappy.py - - name: Archive wheels - if: startsWith(github.ref, 'refs/tags/0.') + - name: Archive sdist uses: actions/upload-artifact@v2 with: - name: python_snappy-${{ matrix.pep-425-tag }}-manylinux - path: dist/python_snappy*-manylinux1*.whl + name: wheels + path: dist/python-snappy*.tar.gz + + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-20.04, macos-10.15, windows-2019] + architecture: ['x64'] + linux_archs: ["auto s390x"] + include: + - os: windows-2019 + architecture: 'x86' + skip: "*2*win* *win_amd64" + environment_windows: INCLUDE="C:/Program Files (x86)/Snappy/include" LIB="C:/Program Files (x86)/Snappy/lib" + - os: windows-2019 + architecture: 'x64' + skip: "*2*win* *win32" + environment_windows: INCLUDE="C:/Program Files/Snappy/include" LIB="C:/Program Files/Snappy/lib" + - os: ubuntu-20.04 + architecture: 'x64' + linux_archs: aarch64 ppc64le + + name: Python ${{ matrix.os }} + env: + CIBW_TEST_REQUIRES: pytest + CIBW_TEST_COMMAND: "python -m pytest --verbose {project}/test_snappy.py" + CIBW_BEFORE_ALL_LINUX: yum install -y snappy-devel + MACOSX_DEPLOYMENT_TARGET: "10.9" + CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel}" + CIBW_BEFORE_ALL: "bash {project}/build_snappy.sh" + CIBW_SKIP: ${{ matrix.skip }} + CIBW_ENVIRONMENT_WINDOWS: ${{ matrix.environment_windows }} + CIBW_ARCHS_LINUX: ${{ matrix.linux_archs }} + CIBW_ARCHS_MACOS: x86_64 universal2 + CIBW_TEST_SKIP: "*_arm64 *_universal2:arm64" + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.8" + architecture: ${{ matrix.architecture }} + +# - name: Install Visual C++ for Python 2.7 +# if: runner.os == 'Windows' +# run: | +# choco install vcpython27 -f -y + + - name: Set up QEMU + if: runner.os == 'Linux' + uses: docker/setup-qemu-action@v1 + with: + platforms: all + + - name: Add msbuild to PATH + if: runner.os == 'Windows' + uses: microsoft/setup-msbuild@v1.0.2 + + - name: delvewheel install + if: runner.os == 'Windows' + run: | + python -m pip install delvewheel==0.0.9 + + - name: Build wheels + uses: joerick/cibuildwheel@v1.9.0 + + - uses: actions/upload-artifact@v2 + with: + path: ./wheelhouse/*.whl + name: wheels + + upload: + runs-on: ubuntu-latest + name: upload wheels + needs: ['sdist', 'build'] + if: startsWith(github.ref, 'refs/tags/0.') + steps: + - name: Download test data + uses: actions/download-artifact@v1 + with: + name: wheels - name: Publish wheels to PyPI - if: startsWith(github.ref, 'refs/tags/0.') env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - twine upload dist/python_snappy*-manylinux1*.whl + twine upload dist/*.whl diff --git a/MANIFEST.in b/MANIFEST.in index 364e64a..2c0b6f2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -include *.py AUTHORS README.rst snappy/*.h MANIFEST.in LICENSE +include *.py AUTHORS README.rst src/snappy/*.h MANIFEST.in LICENSE diff --git a/build_snappy.sh b/build_snappy.sh new file mode 100644 index 0000000..a2e0bc5 --- /dev/null +++ b/build_snappy.sh @@ -0,0 +1,25 @@ +git clone --depth 1 --branch 1.1.8 https://github.com/google/snappy snappy-src +cd snappy-src +git submodule update --init + + +case "$(uname -s)" in + CYGWIN*|MINGW32*|MSYS*|MINGW*) + cmake -G "Visual Studio 16 2019" -A Win32 -S . -B "build32" + cmake -G "Visual Studio 16 2019" -A x64 -S . -B "build64" + cmake --build build32 --config Release --target install + cmake --build build64 --config Release --target install + ;; + + # Add here more strings to compare + # See correspondence table at the bottom of this answer + + *) + cmake -S . -B "build" -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" + cmake --build build --config Release --target install + ;; +esac + + + + diff --git a/setup.py b/setup.py index 6f782e5..68a1cd1 100644 --- a/setup.py +++ b/setup.py @@ -29,6 +29,8 @@ except ImportError: from distutils.core import setup, Extension +import os + version = '0.6.0' long_description = """ Python bindings for the snappy compression library from Google. @@ -36,10 +38,17 @@ More details about Snappy library: http://google.github.io/snappy """ +library_dirs, include_dirs = [], [] +if os.environ.get("CIBUILDWHEEL", False) and sys.version_info[:2] == (3, 9) and sys.platform =="darwin": + library_dirs = ["/usr/local/lib/"] + include_dirs = ["/usr/local/include/"] + snappymodule = Extension('snappy._snappy', libraries=['snappy'], - sources=['snappy/snappymodule.cc', 'snappy/crc32c.c']) + sources=['src/snappy/snappymodule.cc', 'src/snappy/crc32c.c'], + library_dirs=library_dirs, + include_dirs=include_dirs) ext_modules = [snappymodule] packages = ['snappy'] @@ -52,7 +61,7 @@ ext_modules = [] install_requires = ['cffi>=1.0.0'] setup_requires = ['cffi>=1.0.0'] - cffi_modules = ['./snappy/snappy_cffi_builder.py:ffi'] + cffi_modules = ['./src/snappy/snappy_cffi_builder.py:ffi'] setup( name='python-snappy', @@ -80,10 +89,13 @@ '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,' ], ext_modules=ext_modules, packages=packages, install_requires=install_requires, setup_requires=setup_requires, - cffi_modules=cffi_modules + cffi_modules=cffi_modules, + package_dir={'': 'src'}, ) diff --git a/snappy/__init__.py b/src/snappy/__init__.py similarity index 100% rename from snappy/__init__.py rename to src/snappy/__init__.py diff --git a/snappy/__main__.py b/src/snappy/__main__.py similarity index 100% rename from snappy/__main__.py rename to src/snappy/__main__.py diff --git a/snappy/crc32c.c b/src/snappy/crc32c.c similarity index 100% rename from snappy/crc32c.c rename to src/snappy/crc32c.c diff --git a/snappy/crc32c.h b/src/snappy/crc32c.h similarity index 100% rename from snappy/crc32c.h rename to src/snappy/crc32c.h diff --git a/snappy/hadoop_snappy.py b/src/snappy/hadoop_snappy.py similarity index 100% rename from snappy/hadoop_snappy.py rename to src/snappy/hadoop_snappy.py diff --git a/snappy/snappy.py b/src/snappy/snappy.py similarity index 100% rename from snappy/snappy.py rename to src/snappy/snappy.py diff --git a/snappy/snappy_cffi.py b/src/snappy/snappy_cffi.py similarity index 100% rename from snappy/snappy_cffi.py rename to src/snappy/snappy_cffi.py diff --git a/snappy/snappy_cffi_builder.py b/src/snappy/snappy_cffi_builder.py similarity index 100% rename from snappy/snappy_cffi_builder.py rename to src/snappy/snappy_cffi_builder.py diff --git a/snappy/snappy_formats.py b/src/snappy/snappy_formats.py similarity index 100% rename from snappy/snappy_formats.py rename to src/snappy/snappy_formats.py diff --git a/snappy/snappymodule.cc b/src/snappy/snappymodule.cc similarity index 100% rename from snappy/snappymodule.cc rename to src/snappy/snappymodule.cc