Skip to content

Commit

Permalink
feat(wip): python package
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Oct 12, 2023
1 parent 5d98af5 commit dd6b646
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 0 deletions.
158 changes: 158 additions & 0 deletions .github/workflows/maturin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# This file is autogenerated by maturin v1.3.0
# To update, run
#
# maturin generate-ci github -m pystac/Cargo.toml --pytest
#
name: CI

on:
push:
branches:
- main
tags:
- '*'
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
linux:
runs-on: ubuntu-latest
strategy:
matrix:
target: [x86_64, x86, aarch64, armv7, s390x, ppc64le]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter --manifest-path pystac/Cargo.toml
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist
- name: pytest
if: ${{ startsWith(matrix.target, 'x86_64') }}
shell: bash
run: |
set -e
pip install pystac-rs --find-links dist --force-reinstall
pip install pytest
cd pystac && pytest
- name: pytest
if: ${{ !startsWith(matrix.target, 'x86') && matrix.target != 'ppc64' }}
uses: uraimo/run-on-arch-action@v2.5.0
with:
arch: ${{ matrix.target }}
distro: ubuntu22.04
githubToken: ${{ github.token }}
install: |
apt-get update
apt-get install -y --no-install-recommends python3 python3-pip
pip3 install -U pip pytest
run: |
set -e
pip3 install pystac-rs --find-links dist --force-reinstall
cd pystac && pytest
windows:
runs-on: windows-latest
strategy:
matrix:
target: [x64, x86]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
architecture: ${{ matrix.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter --manifest-path pystac/Cargo.toml
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist
- name: pytest
if: ${{ !startsWith(matrix.target, 'aarch64') }}
shell: bash
run: |
set -e
pip install pystac-rs --find-links dist --force-reinstall
pip install pytest
cd pystac && pytest
macos:
runs-on: macos-latest
strategy:
matrix:
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter --manifest-path pystac/Cargo.toml
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist
- name: pytest
if: ${{ !startsWith(matrix.target, 'aarch64') }}
shell: bash
run: |
set -e
pip install pystac-rs --find-links dist --force-reinstall
pip install pytest
cd pystac && pytest
sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist --manifest-path pystac/Cargo.toml
- name: Upload sdist
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

release:
name: Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: [linux, windows, macos, sdist]
steps:
- uses: actions/download-artifact@v3
with:
name: wheels
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing *
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
resolver = "2"
members = [
"pystac",
"stac",
"stac-api",
"stac-async",
Expand Down
72 changes: 72 additions & 0 deletions pystac/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/target

# Byte-compiled / optimized / DLL files
__pycache__/
.pytest_cache/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
.venv/
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
include/
man/
venv/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
pip-selfcheck.json

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

.DS_Store

# Sphinx documentation
docs/_build/

# PyCharm
.idea/

# VSCode
.vscode/

# Pyenv
.python-version
12 changes: 12 additions & 0 deletions pystac/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "pystac"
version = "0.0.1"
edition = "2021"

[lib]
name = "pystac_rs"
crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.20.0"
stac = { version = "0.5", path = "../stac" }
19 changes: 19 additions & 0 deletions pystac/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[project]
name = "pystac-rs"
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]

[project.optional-dependencies]
dev = ["pytest~=7.4"]

[tool.maturin]
features = ["pyo3/extension-module"]

[build-system]
requires = ["maturin>=1.3,<2.0"]
build-backend = "maturin"
2 changes: 2 additions & 0 deletions pystac/pystac_rs.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Item:
id: str
22 changes: 22 additions & 0 deletions pystac/src/item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use pyo3::prelude::*;

#[pyclass]
pub struct Item(stac::Item);

#[pymethods]
impl Item {
#[new]
fn new(id: String) -> Item {
Item(stac::Item::new(id))
}

#[getter]
fn id(&self) -> &str {
&self.0.id
}

#[setter]
fn set_id(&mut self, id: String) {
self.0.id = id;
}
}
4 changes: 4 additions & 0 deletions pystac/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod item;
mod module;

pub use item::Item;
10 changes: 10 additions & 0 deletions pystac/src/module.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::Item;
use pyo3::prelude::*;

/// pystac-rs is a library for working with the SpatioTemporal Asset Catalog
/// (STAC) specification, written in Rust.
#[pymodule]
fn pystac_rs(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<Item>()?;
Ok(())
}
8 changes: 8 additions & 0 deletions pystac/tests/test_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pystac_rs import Item


def test_init():
item = Item("an-id")
assert item.id == "an-id"
item.id = "new-id"
assert item.id == "new-id"

0 comments on commit dd6b646

Please sign in to comment.