diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8bf709c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,105 @@ +on: + pull_request: + branches: + - main + + push: + branches: + - main + tags: + - 'v*' + +name: Build renameat2 + +jobs: + manylinux: + runs-on: ubuntu-20.04 + + strategy: + fail-fast: true + matrix: + python: + - cp36-cp36m + - cp37-cp37m + - cp38-cp38 + - cp39-cp39 + arch: + - x86_64 + - i686 + - aarch64 + + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Build manylinux wheel + run: | + set -euo pipefail + + if [ "$ARCH" = "aarch64" ]; then + export BASEPLAT=manylinux2014 + fi + + docker-compose -f builder/docker-compose.yml build --pull + docker-compose -f builder/docker-compose.yml run manylinux build-wheel.sh + env: + WHICH_PYTHON: ${{ matrix.python }} + ARCH: ${{ matrix.arch }} + + - uses: actions/upload-artifact@v2 + if: github.event_name == 'push' + with: + name: ${{ matrix.python }}-${{ matrix.arch }} + path: dist/*.whl + + + sdist: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Build sdist + run: | + set -euo pipefail + + docker-compose -f builder/docker-compose.yml build --pull + docker-compose -f builder/docker-compose.yml run manylinux /opt/python/cp36-cp36m/bin/python3 setup.py sdist + + - uses: actions/upload-artifact@v2 + if: github.event_name == 'push' + with: + name: sdist + path: dist/*.tar.gz + + + testpypi: + runs-on: ubuntu-20.04 + if: github.event_name == 'push' + + needs: + - manylinux + - sdist + + steps: + - uses: actions/download-artifact@v2 + with: + path: ./artifacts + + - name: Rearrange artifacts + run: | + mkdir -p dist + mv ./artifacts/*/* dist/ + + - name: Publish package to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.TEST_PYPI_TOKEN }} + repository_url: https://test.pypi.org/legacy/ diff --git a/builder/docker-compose.yml b/builder/docker-compose.yml index a3f5fdc..68197d5 100644 --- a/builder/docker-compose.yml +++ b/builder/docker-compose.yml @@ -5,7 +5,7 @@ services: args: ARCH: ${ARCH:-x86_64} environment: - PLAT: manylinux1_${ARCH:-x86_64} + PLAT: ${BASEPLAT:-manylinux1}_${ARCH:-x86_64} WHICH_PYTHON: ${WHICH_PYTHON:-cp36-cp36m} volumes: - ..:/mnt diff --git a/builder/manylinux/Dockerfile b/builder/manylinux/Dockerfile index 569cfb2..4eac453 100644 --- a/builder/manylinux/Dockerfile +++ b/builder/manylinux/Dockerfile @@ -3,15 +3,6 @@ ARG BASE_IMAGE=quay.io/pypa/manylinux2014_${ARCH}:latest FROM ${BASE_IMAGE} -# We need newer kernel headers, manylinux comes with 3.10 and we need 3.15 -RUN rpm --import https://repo.ius.io/RPM-GPG-KEY-IUS-7 && \ - yum install -y https://repo.ius.io/ius-release-el7.rpm && \ - yum install -y yum-plugin-replace && \ - rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org && \ - yum install -y https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm && \ - yum --enablerepo=elrepo-kernel replace -y kernel-headers --replace-with=kernel-lt-headers && \ - yum clean all - COPY build-wheel.sh /usr/bin/build-wheel.sh VOLUME [ "/mnt", "/tmp" ] diff --git a/builder/manylinux/build-wheel.sh b/builder/manylinux/build-wheel.sh index f0a391f..bd70a16 100755 --- a/builder/manylinux/build-wheel.sh +++ b/builder/manylinux/build-wheel.sh @@ -31,10 +31,10 @@ fi tar -C /build/source -xvf "$sdist" # Install development requirements -"/opt/python/${WHICH_PYTHON}/bin/pip" install -r /mnt/requirements-dev.txt +"/opt/python/${WHICH_PYTHON}/bin/pip3" install -r /mnt/requirements-dev.txt # Compile wheel -"/opt/python/${WHICH_PYTHON}/bin/pip" wheel /build/source/"$(basename "$sdist" .tar.gz)" --no-deps -w /build/wheel +"/opt/python/${WHICH_PYTHON}/bin/pip3" wheel /build/source/"$(basename "$sdist" .tar.gz)" --no-deps -w /build/wheel # Bundle external shared libraries into the wheels for whl in /build/wheel/*.whl; do @@ -43,7 +43,7 @@ done # Install packages and test cp /mnt/renameat2_test.py /bin/renameat2_test.py -"/opt/python/${WHICH_PYTHON}/bin/pip" install renameat2 --no-index -f /build/fixedwheel +"/opt/python/${WHICH_PYTHON}/bin/pip3" install renameat2 --no-index -f /build/fixedwheel cd / && "/opt/python/${WHICH_PYTHON}/bin/python3" -m pytest /bin/renameat2_test.py mnt_uid=$(stat -c '%u' /mnt) diff --git a/pyproject.toml b/pyproject.toml index 1a9755d..497611f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,3 +3,4 @@ requires = ["setuptools >= 40.6.0", "cffi", "wheel", "setuptools_scm[toml]>=3.4" build-backend = "setuptools.build_meta" [tool.setuptools_scm] +local_scheme = "no-local-version" diff --git a/renameat2.c b/renameat2.c index bcef41d..5e4e5f7 100644 --- a/renameat2.c +++ b/renameat2.c @@ -2,6 +2,25 @@ #include #include +#ifndef SYS_renameat2 +# ifdef __x86_64__ +# define SYS_renameat2 316 +# endif +# ifdef __i386__ +# define SYS_renameat2 353 +# endif +# ifdef __aarch64__ +# define SYS_renameat2 276 +# endif +# ifdef __arm__ +# define SYS_renameat2 382 +# endif +#endif + +#ifndef SYS_renameat2 +# error SYS_renameat2 is not defined +#endif + /* Newer versions of glibc include this, but none new enough for manylinux */ int renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, diff --git a/renameat2/__init__.py b/renameat2/__init__.py index f6eefda..20e5bc1 100644 --- a/renameat2/__init__.py +++ b/renameat2/__init__.py @@ -39,7 +39,7 @@ def _check_kernel_version(): class Flags(IntFlag): - RENAME_EXCHANGE: int = _lib.RENAME_EXCHANGE # type: ignore + RENAME_EXCHANGE = 2 """ Atomically exchange oldpath and newpath. Both pathnames must exist but may be of different types (e.g., one could be a non-empty directory and the other a symbolic @@ -49,7 +49,7 @@ class Flags(IntFlag): RENAME_WHITEOUT. """ - RENAME_NOREPLACE: int = _lib.RENAME_NOREPLACE # type: ignore + RENAME_NOREPLACE = 1 """ Don't overwrite newpath of the rename. Return an error if newpath already exists. @@ -57,7 +57,7 @@ class Flags(IntFlag): renameat(2) manpage for more information. """ - RENAME_WHITEOUT: int = _lib.RENAME_WHITEOUT # type: ignore + RENAME_WHITEOUT = 4 """ Specifying RENAME_WHITEOUT creates a "whiteout" object at the source of the rename at the same time as performing the rename. The whole operation is atomic, so that diff --git a/renameat2_build.py b/renameat2_build.py index 7a28b62..ccd41f5 100644 --- a/renameat2_build.py +++ b/renameat2_build.py @@ -4,10 +4,6 @@ ffibuilder.cdef( # type: ignore """ - #define RENAME_EXCHANGE ... - #define RENAME_NOREPLACE ... - #define RENAME_WHITEOUT ... - int renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags); diff --git a/setup.py b/setup.py index 6fdafd2..757f641 100644 --- a/setup.py +++ b/setup.py @@ -1,17 +1,6 @@ from setuptools import setup -# setup.cfg seems to be working but I'm old and still don't trust it -# setup( -# name="renameat2", -# version="1.0.0", -# author="Jordan Webb", -# author_email="jordan@getseam.com", -# description="A wrapper around Linux's renameat2 system call", -# url="https://github.com/jordemort/python-renameat2", -# packages=["renameat2"], -# setup_requires=["cffi>=1.0.0"], -# cffi_modules=["renameat2_build.py:ffibuilder"], -# python_requires=">=3.6", -# ) - -setup(cffi_modules=["renameat2_build.py:ffibuilder"], use_scm_version=True) +setup( + cffi_modules=["renameat2_build.py:ffibuilder"], + use_scm_version={"local_scheme": "no-local-version"}, +)