Skip to content

Commit

Permalink
Merge pull request #43 from simobasso/feature/add_maturin
Browse files Browse the repository at this point in the history
Feature/add maturin
  • Loading branch information
Fabio Todaro authored Apr 14, 2021
2 parents 5801a8c + faedbe4 commit ddd9626
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 138 deletions.
5 changes: 5 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ python:
- "3.5"
- "3.6"
- "3.7"
- "3.8"

env:
- RUSTUP_HOME=~/rustup CARGO_HOME=~/cargo PATH=~/cargo/bin:$PATH
Expand All @@ -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:
Expand All @@ -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
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/*
89 changes: 27 additions & 62 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
[package]
name = "celery_state"
version = "0.1.0"
name = "celery_exporter"
version = "1.4.0"
authors = ["Nicola Martino <mroci@bruttocarattere.org>"]
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]
Expand All @@ -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"
34 changes: 7 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,7 @@ FROM python:3.6-alpine as base-image

ENV LANG=C.UTF-8

RUN ALPINE_GLIBC_BASE_URL="https://github.com/sgerrand/alpine-pkg-glibc/releases/download" && \
ALPINE_GLIBC_PACKAGE_VERSION="2.29-r0" && \
ALPINE_GLIBC_BASE_PACKAGE_FILENAME="glibc-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \
ALPINE_GLIBC_BIN_PACKAGE_FILENAME="glibc-bin-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \
ALPINE_GLIBC_I18N_PACKAGE_FILENAME="glibc-i18n-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \
apk add --no-cache wget ca-certificates && \
wget "https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub" -O /etc/apk/keys/sgerrand.rsa.pub && \
wget "$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" && \
wget "$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" && \
wget "$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_I18N_PACKAGE_FILENAME" && \
apk add --no-cache \
"$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_I18N_PACKAGE_FILENAME" && \
rm "/etc/apk/keys/sgerrand.rsa.pub" && \
/usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 "$LANG" || true && \
echo "export LANG=$LANG" > /etc/profile.d/locale.sh && \
apk del glibc-i18n && \
rm \
"/root/.wget-hsts" \
"$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_I18N_PACKAGE_FILENAME"
RUN apk add libgcc

FROM base-image as build-rs

Expand All @@ -37,15 +15,17 @@ WORKDIR /src
RUN apk add --no-cache alpine-sdk bash && \
wget "https://sh.rustup.rs" -O rustup-init && \
chmod +x ./rustup-init && \
./rustup-init -y --no-modify-path --default-toolchain stable --default-host x86_64-unknown-linux-gnu && \
./rustup-init -y --no-modify-path --default-toolchain stable --default-host x86_64-unknown-linux-musl && \
rm -rf rustup-init && \
pip install setuptools-rust wheel
wget "https://github.com/PyO3/maturin/releases/download/v0.8.3/maturin-v0.8.3-x86_64-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 RUSTFLAGS="-C target-feature=-crt-static" maturin build --target x86_64-unknown-linux-musl --release --manylinux off -o /src/wheelhouse

FROM base-image as app
LABEL maintainer="Fabio Todaro <ft@ovalmoney.com>"
Expand Down
2 changes: 1 addition & 1 deletion celery_exporter/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions ci/build-wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["maturin"]
build-backend = "maturin"
2 changes: 1 addition & 1 deletion requirements/requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 0 additions & 34 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<CeleryState>()?;
Ok(())
}
5 changes: 2 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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.3
commands =
py36: black . --check
pyo3-pack develop
maturin develop
coverage run -m py.test {toxinidir}/test/
coverage report

Expand Down

0 comments on commit ddd9626

Please sign in to comment.