mirror of
https://github.com/dathere/ckan_geoconnex_bulk_runner.git
synced 2026-07-05 15:12:20 +00:00
feat: add initial Python package
This commit is contained in:
parent
e6b29be459
commit
71b08a53f0
8 changed files with 290 additions and 7 deletions
79
Cargo.lock
generated
79
Cargo.lock
generated
|
|
@ -176,6 +176,15 @@ dependencies = [
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ckan_geoconnex_bulk_runner_py"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"ckan_geoconnex_bulk_runner",
|
||||||
|
"pyo3",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ckanaction"
|
name = "ckanaction"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
|
@ -1198,6 +1207,12 @@ version = "0.3.33"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e"
|
checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "portable-atomic"
|
||||||
|
version = "1.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "potential_utf"
|
name = "potential_utf"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
|
|
@ -1226,6 +1241,64 @@ dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pyo3"
|
||||||
|
version = "0.28.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "91fd8e38a3b50ed1167fb981cd6fd60147e091784c427b8f7183a7ee32c31c12"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
"portable-atomic",
|
||||||
|
"pyo3-build-config",
|
||||||
|
"pyo3-ffi",
|
||||||
|
"pyo3-macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pyo3-build-config"
|
||||||
|
version = "0.28.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e368e7ddfdeb98c9bca7f8383be1648fd84ab466bf2bc015e94008db6d35611e"
|
||||||
|
dependencies = [
|
||||||
|
"target-lexicon",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pyo3-ffi"
|
||||||
|
version = "0.28.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f29e10af80b1f7ccaf7f69eace800a03ecd13e883acfacc1e5d0988605f651e"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"pyo3-build-config",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pyo3-macros"
|
||||||
|
version = "0.28.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "df6e520eff47c45997d2fc7dd8214b25dd1310918bbb2642156ef66a67f29813"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"pyo3-macros-backend",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pyo3-macros-backend"
|
||||||
|
version = "0.28.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c4cdc218d835738f81c2338f822078af45b4afdf8b2e33cbb5916f108b813acb"
|
||||||
|
dependencies = [
|
||||||
|
"heck",
|
||||||
|
"proc-macro2",
|
||||||
|
"pyo3-build-config",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.45"
|
version = "1.0.45"
|
||||||
|
|
@ -1759,6 +1832,12 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "target-lexicon"
|
||||||
|
version = "0.13.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tempfile"
|
name = "tempfile"
|
||||||
version = "3.27.0"
|
version = "3.27.0"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
|
resolver = "3"
|
||||||
members = [
|
members = [
|
||||||
"ckan_geoconnex_bulk_runner",
|
"ckan_geoconnex_bulk_runner",
|
||||||
|
"ckan_geoconnex_bulk_runner_py",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
10
README.md
10
README.md
|
|
@ -13,29 +13,29 @@ This runner is expected to be implemented for a water data hub with the relevant
|
||||||
## Installation and setup
|
## Installation and setup
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo run --release
|
cargo run -p ckan_geoconnex_bulk_runner --release
|
||||||
```
|
```
|
||||||
|
|
||||||
To ignore standard error output and only show valid output:
|
To ignore standard error output and only show valid output:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo run --release 2>/dev/null
|
cargo run -p ckan_geoconnex_bulk_runner --release 2>/dev/null
|
||||||
```
|
```
|
||||||
|
|
||||||
## Run tests
|
## Run tests
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo test
|
cargo test -p ckan_geoconnex_bulk_runner
|
||||||
```
|
```
|
||||||
|
|
||||||
To include print statements in test output, run:
|
To include print statements in test output, run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo test -- --nocapture
|
cargo test -p ckan_geoconnex_bulk_runner -- --nocapture
|
||||||
```
|
```
|
||||||
|
|
||||||
If you have the local dump files setup available you can run those tests with:
|
If you have the local dump files setup available you can run those tests with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo test -F local -- --nocapture
|
cargo test -p ckan_geoconnex_bulk_runner -F local -- --nocapture
|
||||||
```
|
```
|
||||||
|
|
|
||||||
73
ckan_geoconnex_bulk_runner_py/.github/workflows/CI.yml
vendored
Normal file
73
ckan_geoconnex_bulk_runner_py/.github/workflows/CI.yml
vendored
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
# This file is autogenerated by maturin v1.13.3
|
||||||
|
# To update, run
|
||||||
|
#
|
||||||
|
# maturin generate-ci github
|
||||||
|
#
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
# TODO: Enable when implementation is ready
|
||||||
|
# push:
|
||||||
|
# branches:
|
||||||
|
# - main
|
||||||
|
# - master
|
||||||
|
# tags:
|
||||||
|
# - '*'
|
||||||
|
# pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
linux:
|
||||||
|
runs-on: ${{ matrix.platform.runner }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
platform:
|
||||||
|
- runner: ubuntu-latest
|
||||||
|
target: x86_64
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions/setup-python@v6
|
||||||
|
with:
|
||||||
|
python-version: "3.x"
|
||||||
|
- name: Build wheels
|
||||||
|
uses: PyO3/maturin-action@v1
|
||||||
|
with:
|
||||||
|
target: ${{ matrix.platform.target }}
|
||||||
|
args: --release --out dist --find-interpreter
|
||||||
|
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
||||||
|
manylinux: auto
|
||||||
|
- name: Upload wheels
|
||||||
|
uses: actions/upload-artifact@v6
|
||||||
|
with:
|
||||||
|
name: wheels-linux-${{ matrix.platform.target }}
|
||||||
|
path: dist
|
||||||
|
|
||||||
|
release:
|
||||||
|
name: Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
|
||||||
|
needs: [linux]
|
||||||
|
permissions:
|
||||||
|
# Use to sign the release artifacts
|
||||||
|
id-token: write
|
||||||
|
# Used to upload release artifacts
|
||||||
|
contents: write
|
||||||
|
# Used to generate artifact attestation
|
||||||
|
attestations: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/download-artifact@v7
|
||||||
|
- name: Generate artifact attestation
|
||||||
|
uses: actions/attest@v4
|
||||||
|
with:
|
||||||
|
subject-path: 'wheels-*/*'
|
||||||
|
- name: Install uv
|
||||||
|
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
||||||
|
uses: astral-sh/setup-uv@v7
|
||||||
|
- name: Publish to PyPI
|
||||||
|
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
||||||
|
run: uv publish 'wheels-*/*'
|
||||||
|
env:
|
||||||
|
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
|
||||||
72
ckan_geoconnex_bulk_runner_py/.gitignore
vendored
Normal file
72
ckan_geoconnex_bulk_runner_py/.gitignore
vendored
Normal file
|
|
@ -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
|
||||||
14
ckan_geoconnex_bulk_runner_py/Cargo.toml
Normal file
14
ckan_geoconnex_bulk_runner_py/Cargo.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
[package]
|
||||||
|
name = "ckan_geoconnex_bulk_runner_py"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
name = "ckan_geoconnex_bulk_runner_py"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
ckan_geoconnex_bulk_runner = { path = "../ckan_geoconnex_bulk_runner" }
|
||||||
|
pyo3 = "0.28.3"
|
||||||
|
serde_json = "1.0.149"
|
||||||
13
ckan_geoconnex_bulk_runner_py/pyproject.toml
Normal file
13
ckan_geoconnex_bulk_runner_py/pyproject.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
[build-system]
|
||||||
|
requires = ["maturin>=1.13,<2.0"]
|
||||||
|
build-backend = "maturin"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "ckan_geoconnex_bulk_runner_py"
|
||||||
|
requires-python = ">=3.8"
|
||||||
|
classifiers = [
|
||||||
|
"Programming Language :: Rust",
|
||||||
|
"Programming Language :: Python :: Implementation :: CPython",
|
||||||
|
"Programming Language :: Python :: Implementation :: PyPy",
|
||||||
|
]
|
||||||
|
dynamic = ["version"]
|
||||||
31
ckan_geoconnex_bulk_runner_py/src/lib.rs
Normal file
31
ckan_geoconnex_bulk_runner_py/src/lib.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
use pyo3::prelude::*;
|
||||||
|
|
||||||
|
/// Python functions for Geoconnex integration that can be used in CKAN extensions.
|
||||||
|
/// Based on <https://github.com/dathere/ckan_geoconnex_bulk_runner>.
|
||||||
|
#[pymodule]
|
||||||
|
mod ckan_geoconnex_bulk_runner_py {
|
||||||
|
use pyo3::{exceptions::PyException, prelude::*};
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
|
/// Construct Geoconnex-compatible JSON-LD as a string from dataset metadata.
|
||||||
|
///
|
||||||
|
/// Input: Dataset metadata (output of /package_show for a CKAN dataset) as a string.
|
||||||
|
/// Output: Constructed Geoconnex-compatible JSON-LD as a string.
|
||||||
|
fn construct_dataset_jsonld_from_metadata(dataset_metadata: String) -> PyResult<String> {
|
||||||
|
match serde_json::to_value(dataset_metadata) {
|
||||||
|
Ok(dataset_json) => {
|
||||||
|
match ckan_geoconnex_bulk_runner::jsonld::construct_dataset_jsonld_from_metadata(
|
||||||
|
dataset_json,
|
||||||
|
) {
|
||||||
|
Ok(jsonld) => serde_json::to_string(&jsonld).map_err(|e| {
|
||||||
|
PyException::new_err(format!(
|
||||||
|
"Error when converting JSON-LD to string: {e}"
|
||||||
|
))
|
||||||
|
}),
|
||||||
|
Err(e) => Err(PyException::new_err(e.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => Err(PyException::new_err(e.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue