Skip to content

Add python binding layout #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

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

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
28 changes: 28 additions & 0 deletions python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "async-tiff"
version = "0.1.0-beta.1"
authors = ["Kyle Barron <kyle@developmentseed.org>"]
edition = "2021"
# description = "Fast, memory-efficient 2D spatial indexes for Python."
readme = "README.md"
repository = "https://github.com/developmentseed/async-tiff"
license = "MIT OR Apache-2.0"
keywords = ["python", "geospatial"]
categories = ["science::geo"]
rust-version = "1.75"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "_async_tiff"
crate-type = ["cdylib"]

[dependencies]
async-tiff = { path = "../" }
bytes = "1.8"
pyo3 = { version = "0.23.0", features = ["macros"] }
pyo3-bytes = "0.1.2"
thiserror = "1"

[profile.release]
lto = true
codegen-units = 1
5 changes: 5 additions & 0 deletions python/DEVELOP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```
uv sync --no-install-package async-tiff
uv run --no-project maturin develop
uv run --no-project mkdocs serve
```
11 changes: 11 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# async-tiff

<!-- [![PyPI][pypi_badge]][pypi_link]

[pypi_badge]: https://badge.fury.io/py/geoindex-rs.svg
[pypi_link]: https://pypi.org/project/geoindex-rs/ -->

Fast, async TIFF and GeoTIFF reader for Python.

<!-- This documentation is for the Python bindings. [Refer here for the Rust crate documentation](https://docs.rs/geo-index). -->

35 changes: 35 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[build-system]
requires = ["maturin>=1.4.0,<2.0"]
build-backend = "maturin"

[project]
name = "async-tiff"
requires-python = ">=3.9"
dependencies = []
dynamic = ["version"]
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]

[tool.maturin]
features = ["pyo3/extension-module"]
module-name = "async_tiff._async_tiff"
python-source = "python"

[tool.uv]
dev-dependencies = [
"griffe-inherited-docstrings>=1.0.1",
"ipykernel>=6.29.5",
"maturin>=1.7.4",
"mike>=2.1.3",
"mkdocs-material[imaging]>=9.5.40",
"mkdocs>=1.6.1",
"mkdocstrings-python>=1.13.0",
"mkdocstrings>=0.27.0",
"numpy>=1",
"pip>=24.2",
"pytest>=8.3.3",
"ruff>=0.8.4",
]
3 changes: 3 additions & 0 deletions python/python/async_tiff/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ._async_tiff import ___version

__version__: str = ___version()
Empty file.
Empty file.
39 changes: 39 additions & 0 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#![deny(clippy::undocumented_unsafe_blocks)]

use pyo3::prelude::*;

const VERSION: &str = env!("CARGO_PKG_VERSION");

#[pyfunction]
fn ___version() -> &'static str {
VERSION
}

/// Raise RuntimeWarning for debug builds
#[pyfunction]
fn check_debug_build(_py: Python) -> PyResult<()> {
#[cfg(debug_assertions)]
{
use pyo3::exceptions::PyRuntimeWarning;
use pyo3::intern;
use pyo3::types::PyTuple;

let warnings_mod = _py.import(intern!(_py, "warnings"))?;
let warning = PyRuntimeWarning::new_err(
"async-tiff has not been compiled in release mode. Performance will be degraded.",
);
let args = PyTuple::new(_py, vec![warning])?;
warnings_mod.call_method1(intern!(_py, "warn"), args)?;
}

Ok(())
}

#[pymodule]
fn _async_tiff(py: Python, m: &Bound<PyModule>) -> PyResult<()> {
check_debug_build(py)?;

m.add_wrapped(wrap_pyfunction!(___version))?;

Ok(())
}
Loading