Skip to content

Commit

Permalink
Add wheels for MacOS and Windows platforms (#7)
Browse files Browse the repository at this point in the history
Refactor the code
  • Loading branch information
Andrii Sokyrko authored Jun 1, 2022
1 parent 392b6bb commit 143b1a2
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 142 deletions.
11 changes: 11 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]

[target.aarch64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
42 changes: 32 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,47 @@ name: Publish

on:
release:
types: [created]
types: [ created ]

jobs:
publish:
runs-on: ubuntu-latest
build:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ "windows-2019", "macOS-12", "ubuntu-latest" ]

steps:
- uses: actions/checkout@v2

- name: Set up Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install twine
- name: Build and publish

- if: "${{ matrix.os != 'ubuntu-latest' }}"
name: Build
uses: messense/maturin-action@v1
with:
maturin-version: 0.12.18
command: build
args: --release --strip

- if: "${{ matrix.os == 'ubuntu-latest' }}"
name: Build
run: docker run --rm -v ${PWD}:/io konstin2/maturin build --release --strip

- name: Publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
make build
make publish
pip install twine
twine check target/wheels/*.whl
twine upload target/wheels/*.whl
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
pip install -r requirements-dev.txt
- name: Install the package
run: |
python setup.py install --user
make install
- name: Test
run: |
make test
Expand Down
85 changes: 30 additions & 55 deletions Cargo.lock

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

13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "fast_mail_parser"
version = "0.2.2"
version = "0.2.3"
authors = ["Andrii Sokyrko <[email protected]>"]
license = "Apache-2.0"

Expand All @@ -24,9 +24,9 @@ classifier = [
"Topic :: Communications :: Email",
"Topic :: Software Development :: Libraries",
]
requires-python = ">=3.6.0"
maintainer-email = "andrey.sokirko@namecheap.com"
maintainer = "Andrey Sokirko"
requires-python = ">=3.7.0"
maintainer-email = "wartwvister@gmail.com"
maintainer = "Andrii Sokyrko"

[profile.dev]
opt-level = 0
Expand All @@ -35,6 +35,9 @@ debug = true
[profile.release]
opt-level = 3
debug = false
strip = "debuginfo"
lto = true
codegen-units = 1

[lib]
name = "fast_mail_parser"
Expand All @@ -43,7 +46,7 @@ crate-type = ["cdylib"]

[dependencies]
mailparse = "0.13.8"
pyo3 = "0.15.1"
pyo3 = "0.16.5"

[features]
default = ["pyo3/extension-module"]
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
.PHONY: build
.PHONY: install

test:
pytest -v --ignore tests/benchmark tests

benchmark:
pytest -v tests/benchmark

build:
docker run --rm -v $(CURDIR):/io konstin2/maturin build --release --strip

publish:
twine check target/wheels/*
twine upload target/wheels/*
install:
python3 setup.py install --force
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.61
31 changes: 18 additions & 13 deletions src/fast_mail_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct PyAttachment {
}

impl PyAttachment {
pub fn from_attachment(py: Python, attachment: mail_parser::Attachment) -> Self {
pub(crate) fn from_attachment(py: Python, attachment: mail_parser::Attachment) -> Self {
PyAttachment {
mimetype: attachment.mimetype,
content: Py::from(PyBytes::new(py, attachment.content.as_slice())),
Expand All @@ -44,6 +44,22 @@ pub struct PyMail {
pub headers: HashMap<String, String>,
}

impl PyMail {
pub(crate) fn from_mail(py: Python, mail: mail_parser::Mail) -> Self {
Self {
subject: mail.subject,
text_plain: mail.text_plain,
text_html: mail.text_html,
date: mail.date,
attachments: mail.attachments
.into_iter()
.map(|a| PyAttachment::from_attachment(py, a))
.collect(),
headers: mail.headers,
}
}
}

trait PyToBytes {
fn to_bytes(&self, py: Python) -> PyResult<Vec<u8>>;
}
Expand Down Expand Up @@ -75,18 +91,7 @@ pub fn parse_email(py: Python, payload: PyObject) -> PyResult<PyMail> {

mail_parser::parse_email(message.as_slice())
.map_err(|e| ParseError::new_err(format!("Message parsing error: {}", e)))
.map(|m| PyMail {
subject: m.get_subject(),
text_plain: m.get_text_plain(),
text_html: m.get_text_html(),
date: m.get_date(),
attachments: m
.get_attachments()
.into_iter()
.map(|a| PyAttachment::from_attachment(py, a))
.collect(),
headers: m.get_headers(),
})
.map(|mail| PyMail::from_mail(py, mail))
}

#[pymodule]
Expand Down
Loading

0 comments on commit 143b1a2

Please sign in to comment.