diff --git a/.github/workflows/build.sh b/.github/workflows/build.sh index 002d12a..34ed29b 100644 --- a/.github/workflows/build.sh +++ b/.github/workflows/build.sh @@ -17,10 +17,10 @@ make make install cd .. for PYBIN in /opt/python/*/bin; do - if [[ $PYBIN = *"cp27"* ]]; then + if [[ $PYBIN = *"cp27"* ]] || [[ $PYBIN = *"cp36"* ]] || [[ $PYBIN = *"cp37"* ]]; then continue fi - "${PYBIN}/python" setup.py bdist_wheel -b build/build_tmp -d build --libdir=build/lib --incdir=build/include/lame + "${PYBIN}/python" -m build -w -o build -C="--build-option=--libdir=build/lib" -C="--build-option=--incdir=build/include/lame" done for whl in build/*.whl; do auditwheel repair "$whl" -w build/ diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 249f858..0b9c469 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -15,14 +15,17 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: Execute the build uses: docker://quay.io/pypa/manylinux_2_24_x86_64 with: entrypoint: bash args: /github/workspace/.github/workflows/build.sh - name: Archive built wheels - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: manylinux2_24_64 path: build/*.whl @@ -33,7 +36,7 @@ jobs: needs: [ build_linux2_24_64 ] runs-on: ubuntu-latest steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 id: download with: name: manylinux2_24_64 @@ -49,14 +52,17 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: Execute the build uses: docker://quay.io/pypa/manylinux_2_24_i686 with: entrypoint: linux32 args: bash /github/workspace/.github/workflows/build.sh - name: Archive built wheels - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: manylinux2_24_32 path: build/*.whl @@ -67,7 +73,7 @@ jobs: needs: [ build_linux2_24_32 ] runs-on: ubuntu-latest steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 id: download with: name: manylinux2_24_32 @@ -83,7 +89,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: Set up emulation uses: docker/setup-qemu-action@v2 @@ -96,7 +105,7 @@ jobs: entrypoint: bash args: /github/workspace/.github/workflows/build.sh - name: Archive built wheels - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: manylinux2_24_aarch64 path: build/*.whl @@ -107,7 +116,7 @@ jobs: needs: [ build_linux2_24_aarch64 ] runs-on: ubuntu-latest steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 id: download with: name: manylinux2_24_aarch64 @@ -123,14 +132,17 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: Execute the build uses: docker://quay.io/pypa/manylinux_2_28_x86_64 with: entrypoint: bash args: /github/workspace/.github/workflows/build.sh - name: Archive built wheels - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: manylinux2_28_64 path: build/*.whl @@ -141,7 +153,7 @@ jobs: needs: [ build_linux2_28_64 ] runs-on: ubuntu-latest steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 id: download with: name: manylinux2_28_64 @@ -157,10 +169,13 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: Set up emulation - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 with: platforms: aarch64 @@ -170,7 +185,7 @@ jobs: entrypoint: bash args: /github/workspace/.github/workflows/build.sh - name: Archive built wheels - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: manylinux2_28_aarch64 path: build/*.whl @@ -181,7 +196,7 @@ jobs: needs: [ build_linux2_28_aarch64 ] runs-on: ubuntu-latest steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 id: download with: name: manylinux2_28_aarch64 @@ -203,12 +218,15 @@ jobs: steps: - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install Python dependencies - run: python -m pip install --user setuptools wheel - - uses: actions/checkout@v2 + run: python -m pip install --user build + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: Build the wheel run: | mkdir build @@ -216,9 +234,9 @@ jobs: cmake -DCMAKE_OSX_ARCHITECTURES="${{ matrix.arch }}" -DPYTHON_VERSIONS=${{ matrix.python-version }} .. make - name: Archive built wheel - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: mac + name: mac_${{ matrix.arch }}_${{ matrix.python-version }} path: build/*.whl if-no-files-found: error @@ -226,11 +244,15 @@ jobs: if: github.event_name == 'release' && github.event.action == 'created' needs: [ build_mac ] runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] + arch: ['arm64', 'x86_64'] steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 id: download with: - name: mac + name: mac_${{ matrix.arch }}_${{ matrix.python-version }} - name: Publish package to PyPI uses: pypa/gh-action-pypi-publish@release/v1 @@ -255,13 +277,16 @@ jobs: steps: - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} architecture: ${{ matrix.python-arch }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - name: Install dependencies - run: python -m pip install --upgrade setuptools wheel + run: python -m pip install --upgrade build - name: Build the wheel run: | mkdir build @@ -269,9 +294,9 @@ jobs: cmake -DPYTHON_VERSIONS=${{ matrix.python-version }} .. -G "Visual Studio 16 2019" ${{ matrix.arch }} cmake --build . --config Release - name: Archive built wheels - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: windows + name: windows_${{ matrix.python-arch }}_${{ matrix.python-version }} path: build/*.whl if-no-files-found: error @@ -279,11 +304,15 @@ jobs: if: github.event_name == 'release' && github.event.action == 'created' needs: [ build_windows ] runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] + python-arch: ['x86', 'x64'] steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 id: download with: - name: windows + name: windows_${{ matrix.python-arch }}_${{ matrix.python-version }} - name: Publish package to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b2648c..b3374c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ if (APPLE) set(HOST "") if ("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64" OR "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "") set(ARCH_FLAGS "-arch x86_64") + set(HOST "--host=x86_64") endif () if ("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64") set(ARCH_FLAGS "${ARCH_FLAGS} -arch arm64") @@ -109,15 +110,14 @@ foreach (Version IN LISTS PYTHON_VERSIONS) COMMAND ${CMAKE_COMMAND} ARGS -E env "ARCHFLAGS=${ARCH_FLAGS}" "${HOST_PLATFORM}" - ${PYTHON${Version}_EXECUTABLE} - "${CMAKE_CURRENT_SOURCE_DIR}/setup.py" bdist_wheel - -b "${CMAKE_CURRENT_BINARY_DIR}/build_tmp" - -d "${CMAKE_CURRENT_BINARY_DIR}" - "--libdir=${BINARY_DIR}/lib" - "--incdir=${SOURCE_DIR}/include" + ${PYTHON${Version}_EXECUTABLE} -m build -w + -o "${CMAKE_CURRENT_BINARY_DIR}" + "-C=--build-option=--libdir=${BINARY_DIR}/lib" + "-C=--build-option=--incdir=${SOURCE_DIR}/include" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" DEPENDS lame + "${CMAKE_CURRENT_SOURCE_DIR}/pyproject.toml" "${CMAKE_CURRENT_SOURCE_DIR}/setup.py" "${CMAKE_CURRENT_SOURCE_DIR}/lameenc.c" ) diff --git a/DESCRIPTION.md b/DESCRIPTION.md new file mode 100644 index 0000000..f59d0cd --- /dev/null +++ b/DESCRIPTION.md @@ -0,0 +1,5 @@ +Python 3 bindings for the LAME encoding library. +This library makes it simple to encode PCM data into MP3 without having +to compile any binaries. + +Provides binaries in PyPi for Python 3.8+ for Windows, macOS and Linux. \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5f0c29e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,26 @@ +[build-system] +requires = ["setuptools","wheel", "setuptools-scm"] +build-backend = "setuptools.build_meta" + +[project] +name = "lameenc" +description = "LAME encoding bindings" +readme = "DESCRIPTION.md" +authors = [ + {name = "Chris Staite", email = "chris@yourdreamnet.co.uk"}, +] +license = {file = "LICENSE"} +classifiers = [ + "Topic :: Multimedia :: Sound/Audio :: Conversion", + "Programming Language :: Python :: 3 :: Only", + "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", + "Operating System :: MacOS :: MacOS X", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX :: Linux" +] +dynamic = ["version"] + +[project.urls] +Repository = "https://github.com/chrisstaite/lameenc" + +[tool.setuptools_scm] diff --git a/setup.py b/setup.py index 86c4a2b..63b9f2f 100644 --- a/setup.py +++ b/setup.py @@ -4,16 +4,19 @@ import os.path +print(sys.argv) # Grab the library location from the command line libdir = None for argument in sys.argv: if argument.startswith('--libdir='): libdir = argument if libdir is None: - print('Need to specify location of liblame') - sys.exit(1) -sys.argv.remove(libdir) -libdir = libdir[len('--libdir='):] + if 'bdist_wheel' in sys.argv: + print('Need to specify location of liblame') + sys.exit(1) +else: + sys.argv.remove(libdir) + libdir = libdir[len('--libdir='):] # Grab the include location from the command line incdir = None @@ -21,19 +24,21 @@ if argument.startswith('--incdir='): incdir = argument if incdir is None: - print('Need to specify location of liblame source') - sys.exit(1) -sys.argv.remove(incdir) -incdir = incdir[len('--incdir='):] + if 'bdist_wheel' in sys.argv: + print('Need to specify location of liblame source') + sys.exit(1) +else: + sys.argv.remove(incdir) + incdir = incdir[len('--incdir='):] # Create the extension lameenc = distutils.core.Extension( 'lameenc', - include_dirs=[incdir], + include_dirs=[incdir] if incdir else [], libraries=['libmp3lame'] if sys.platform == 'win32' else [], extra_objects= - [] if sys.platform == 'win32' else [os.path.join(libdir, 'libmp3lame.a')], - library_dirs=[libdir] if sys.platform == 'win32' else [], + [] if sys.platform == 'win32' or not libdir else [os.path.join(libdir, 'libmp3lame.a')], + library_dirs=[libdir] if sys.platform == 'win32' and libdir else [], sources=['lameenc.c'] ) @@ -62,14 +67,5 @@ ] ) -if os.path.exists(os.path.join(os.path.abspath(os.path.dirname(__file__)), '.git')): - configuration['setup_requires'] = ['setuptools-git-versioning'] - configuration['setuptools_git_versioning'] = { - 'enabled': True, - 'starting_version': '1.7.0' - } -else: - configuration['version'] = '1.7.0' - # Create the package setuptools.setup(**configuration)