From 6eb71429e7675c255a0a6c0ee6447bf73bf46da6 Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 3 Aug 2020 13:48:18 +0800 Subject: [PATCH] Upgrade pyo3 to 0.11 --- .cargo/config | 5 ++ .travis.yml | 7 ++- Cargo.lock | 89 +++++++++--------------------- Cargo.toml | 24 +++++++- Dockerfile | 8 ++- celery_exporter/monitor.py | 2 +- ci/build-wheels.sh | 6 +- pyproject.toml | 3 + requirements/requirements_test.txt | 2 +- setup.py | 34 ------------ src/lib.rs | 2 +- tox.ini | 5 +- 12 files changed, 73 insertions(+), 114 deletions(-) create mode 100644 .cargo/config create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..15d5d32 --- /dev/null +++ b/.cargo/config @@ -0,0 +1,5 @@ +[target.x86_64-apple-darwin] +rustflags = [ + "-C", "link-arg=-undefined", + "-C", "link-arg=dynamic_lookup", +] diff --git a/.travis.yml b/.travis.yml index d2a8449..0e54a6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ python: - "3.5" - "3.6" - "3.7" + - "3.8" env: - RUSTUP_HOME=~/rustup CARGO_HOME=~/cargo PATH=~/cargo/bin:$PATH @@ -14,7 +15,7 @@ install: - chmod +x rustup-init - ./rustup-init -y --no-modify-path --default-toolchain stable - chmod -R a+w $RUSTUP_HOME $CARGO_HOME - - pip install tox-travis tox pyo3-pack==0.6.1 setuptools-rust==0.11.6 + - pip install tox-travis tox maturin script: tox jobs: @@ -27,8 +28,8 @@ jobs: env: TWINE_USERNAME=$PYPI_USER TWINE_PASSWORD=$PYPI_PASSWORD before_script: - - pip install setuptools-rust==0.11.6 twine + - pip install twine maturin script: - - python setup.py sdist + - maturin sdist - docker run --rm -v `pwd`:/io quay.io/pypa/manylinux1_x86_64 /io/ci/build-wheels.sh - twine upload --skip-existing dist/* diff --git a/Cargo.lock b/Cargo.lock index 325772d..e5fb759 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,8 +13,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] -name = "celery_state" -version = "0.1.0" +name = "celery_exporter" +version = "1.4.0" dependencies = [ "lru", "pyo3", @@ -28,12 +28,12 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "ctor" -version = "0.1.9" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b4c17619643c1252b5f690084b82639dd7fac141c57c8e77a00e0148132092c" +checksum = "5e98e2ad1a782e33928b96fc3948e7c355e5af34ba4de7670fe8bac2a3b2006d" dependencies = [ - "quote 0.6.12", - "syn 0.15.39", + "quote", + "syn", ] [[package]] @@ -42,9 +42,9 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a5bcf1bbeab73aa4cf2fde60a846858dc036163c7c33bec309f8d17de785479" dependencies = [ - "proc-macro2 1.0.26", - "quote 1.0.9", - "syn 1.0.68", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -73,9 +73,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce046d161f000fffde5f432a0d034d0341dc152643b2598ed5bfce44c4f3a8f0" dependencies = [ "proc-macro-hack", - "proc-macro2 1.0.26", - "quote 1.0.9", - "syn 1.0.68", + "proc-macro2", + "quote", + "syn", "unindent", ] @@ -105,9 +105,9 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75c094e94816723ab936484666968f5b58060492e880f3c8d00489a1e244fa51" dependencies = [ - "proc-macro2 1.0.26", - "quote 1.0.9", - "syn 1.0.68", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -184,22 +184,13 @@ version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" -[[package]] -name = "proc-macro2" -version = "0.4.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -dependencies = [ - "unicode-xid 0.1.0", -] - [[package]] name = "proc-macro2" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" dependencies = [ - "unicode-xid 0.2.1", + "unicode-xid", ] [[package]] @@ -224,9 +215,9 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10ecd0eb6ed7b3d9965b4f4370b5b9e99e3e5e8742000e1c452c018f8c2a322f" dependencies = [ - "proc-macro2 1.0.26", - "quote 1.0.9", - "syn 1.0.68", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -236,17 +227,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d344fdaa6a834a06dd1720ff104ea12fe101dad2e8db89345af9db74c0bb11a0" dependencies = [ "pyo3-derive-backend", - "quote 1.0.9", - "syn 1.0.68", -] - -[[package]] -name = "quote" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" -dependencies = [ - "proc-macro2 0.4.30", + "quote", + "syn", ] [[package]] @@ -255,7 +237,7 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ - "proc-macro2 1.0.26", + "proc-macro2", ] [[package]] @@ -281,32 +263,15 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "syn" -version = "0.15.39" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4d960b829a55e56db167e861ddb43602c003c7be0bee1d345021703fac2fb7c" +checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.12", - "unicode-xid 0.1.0", + "proc-macro2", + "quote", + "unicode-xid", ] -[[package]] -name = "syn" -version = "1.0.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ce15dd3ed8aa2f8eeac4716d6ef5ab58b6b9256db41d7e1a0224c2788e8fd87" -dependencies = [ - "proc-macro2 1.0.26", - "quote 1.0.9", - "unicode-xid 0.2.1", -] - -[[package]] -name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" - [[package]] name = "unicode-xid" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 90182cc..d684721 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,16 @@ [package] -name = "celery_state" -version = "0.1.0" +name = "celery_exporter" +version = "1.4.0" authors = ["Nicola Martino "] +description = "Prometheus metrics exporter for Celery" edition = "2018" +homepage = "https://github.com/OvalMoney/celery-exporter" +license = "MIT" +readme = "README.md" +repository = "https://github.com/OvalMoney/celery-exporter.git" [lib] -name = "celery_state" +name = "celery_exporter" crate-type = ["cdylib"] [dependencies.pyo3] @@ -16,3 +21,16 @@ features = ["extension-module"] [dependencies] lru = "0.6.5" + +[package.metadata.maturin] +classifier = [ + "Development Status :: 3 - Alpha", + "Environment :: Console", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3 :: Only", + "Operating System :: OS Independent" +] + +[package.metadata.maturin.scripts] +celery-exporter = "celery_exporter.__main__:main" diff --git a/Dockerfile b/Dockerfile index 8fe98f2..d53b2cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,13 +39,15 @@ RUN apk add --no-cache alpine-sdk bash && \ chmod +x ./rustup-init && \ ./rustup-init -y --no-modify-path --default-toolchain stable --default-host x86_64-unknown-linux-gnu && \ rm -rf rustup-init && \ - pip install setuptools-rust wheel + wget "https://github.com/PyO3/maturin/releases/download/v0.8.2/maturin-v0.8.2-i686-unknown-linux-musl.tar.gz" -O maturin.tar.gz && \ + tar -C /usr/local/cargo/bin -zxf maturin.tar.gz && \ + rm -rf maturin.tar.gz -COPY Cargo.toml Cargo.lock setup.py README.md ./ +COPY Cargo.toml Cargo.lock README.md ./ COPY src/ ./src COPY celery_exporter/ ./celery_exporter/ -RUN pip wheel . -w /src/wheelhouse +RUN maturin build --release -o /src/wheelhouse FROM base-image as app LABEL maintainer="Fabio Todaro " diff --git a/celery_exporter/monitor.py b/celery_exporter/monitor.py index 6495287..a195538 100644 --- a/celery_exporter/monitor.py +++ b/celery_exporter/monitor.py @@ -8,7 +8,7 @@ import celery.states from .metrics import TASKS, TASKS_RUNTIME, LATENCY, WORKERS -from celery_state import CeleryState +from .celery_exporter import CeleryState from .utils import get_config diff --git a/ci/build-wheels.sh b/ci/build-wheels.sh index 8d9a0c4..e2e08a7 100755 --- a/ci/build-wheels.sh +++ b/ci/build-wheels.sh @@ -8,11 +8,11 @@ export PATH="$HOME/.cargo/bin:$PATH" cd /io -for PYBIN in /opt/python/{cp35-cp35m,cp36-cp36m,cp37-cp37m}/bin; do +for PYBIN in /opt/python/{cp35-cp35m,cp36-cp36m,cp37-cp37m,cp38-cp38}/bin; do export PYTHON_SYS_EXECUTABLE="$PYBIN/python" - "${PYBIN}/pip" install -U setuptools wheel setuptools-rust - "${PYBIN}/python" setup.py bdist_wheel + "${PYBIN}/pip" install -U maturin + "${PYBIN}/maturin" build --release -i "${PYBIN}/python" -o dist/ done PYBIN=/opt/python/cp37-cp37m/bin diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..90cb176 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["maturin"] +build-backend = "maturin" diff --git a/requirements/requirements_test.txt b/requirements/requirements_test.txt index 83505b4..92f32d0 100644 --- a/requirements/requirements_test.txt +++ b/requirements/requirements_test.txt @@ -12,5 +12,5 @@ py==1.8.0 pylint==2.3.1 pytest==4.3.1 six==1.12.0 -typed-ast==1.3.2 +typed-ast==1.4.1 wrapt==1.11.1 diff --git a/setup.py b/setup.py deleted file mode 100644 index c2bbb89..0000000 --- a/setup.py +++ /dev/null @@ -1,34 +0,0 @@ -import io - -from setuptools import setup -from setuptools_rust import Binding, RustExtension - -long_description = "See https://github.com/OvalMoney/celery-exporter" -with io.open("README.md", encoding="utf-8") as fp: - long_description = fp.read() - -setup( - name="celery-exporter", - description="Prometheus metrics exporter for Celery", - long_description=long_description, - long_description_content_type="text/markdown", - version="1.4.0", - author="Fabio Todaro, Nicola Martino", - license="MIT", - author_email="fbregist@gmail.com, mroci@bruttocarattere.org", - url="https://github.com/OvalMoney/celery-exporter", - classifiers=[ - "Development Status :: 3 - Alpha", - "Environment :: Console", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3 :: Only", - "Operating System :: OS Independent", - ], - rust_extensions=[RustExtension("celery_state", binding=Binding.PyO3, debug=False)], - packages=["celery_exporter"], - install_requires=["click>=7", "celery>=4", "prometheus_client>=0.0.20"], - entry_points={ - "console_scripts": ["celery-exporter = celery_exporter.__main__:main"] - }, -) diff --git a/src/lib.rs b/src/lib.rs index 49df3df..6136cf5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -233,7 +233,7 @@ impl CeleryState { } #[pymodule] -fn celery_state(_py: Python, m: &PyModule) -> PyResult<()> { +fn celery_exporter(_py: Python, m: &PyModule) -> PyResult<()> { m.add_class::()?; Ok(()) } diff --git a/tox.ini b/tox.ini index becd40d..f716d2c 100644 --- a/tox.ini +++ b/tox.ini @@ -8,11 +8,10 @@ deps = py36: black==19.3b0 -rrequirements/requirements_test.txt -rrequirements/requirements.txt - pyo3-pack==0.6.1 - setuptools-rust==0.11.6 + maturin==0.8.2 commands = py36: black . --check - pyo3-pack develop + maturin develop coverage run -m py.test {toxinidir}/test/ coverage report